comparison PrivateQueue.c @ 48:1ea30ca7093c

changed headers
author Sean Halle <seanhalle@yahoo.com>
date Tue, 23 Jul 2013 07:28:22 -0700
parents 67c7f5a0308b
children 083298a6f7b6
comparison
equal deleted inserted replaced
27:e07794f7bc4c 29:9a20e1493f5e
12 #include <string.h> 12 #include <string.h>
13 #include <errno.h> 13 #include <errno.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 15
16 #include "PrivateQueue.h" 16 #include "PrivateQueue.h"
17 #include "PR__common_includes/Services_offered_by_PR/Memory_Handling/vmalloc__wrapper_library.h"
17 18
18 19
19 20
20 //=========================================================================== 21 //===========================================================================
21 22
25 26
26 PrivQueueStruc* makePrivQ() 27 PrivQueueStruc* makePrivQ()
27 { 28 {
28 PrivQueueStruc* retQ; 29 PrivQueueStruc* retQ;
29 //This malloc is not safe to use in wrapper lib nor app code! 30 //This malloc is not safe to use in wrapper lib nor app code!
30 retQ = (PrivQueueStruc *) PR_int__malloc( sizeof( PrivQueueStruc ) ); 31 retQ = (PrivQueueStruc *) PR__malloc( sizeof( PrivQueueStruc ) );
31 32
32 //This malloc is not safe to use in wrapper lib nor app code! 33 //This malloc is not safe to use in wrapper lib nor app code!
33 retQ->startOfData = PR_int__malloc( 1024 * sizeof(void *) ); 34 retQ->startOfData = PR__malloc( 1024 * sizeof(void *) );
34 memset( retQ->startOfData, 0, 1024 * sizeof(void *) ); 35 memset( retQ->startOfData, 0, 1024 * sizeof(void *) );
35 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty 36 retQ->extractPos = &(retQ->startOfData[0]); //side by side == empty
36 retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be 37 retQ->insertPos = &(retQ->startOfData[1]); // so start pos's have to be
37 retQ->endOfData = &(retQ->startOfData[1023]); 38 retQ->endOfData = &(retQ->startOfData[1023]);
38 39
62 63
63 oldSize = oldEndOfData - oldStartOfData + 1; //in bytes 64 oldSize = oldEndOfData - oldStartOfData + 1; //in bytes
64 newSize = 2 * oldSize; 65 newSize = 2 * oldSize;
65 66
66 //This malloc is not safe to use in wrapper lib nor app code! 67 //This malloc is not safe to use in wrapper lib nor app code!
67 Q->startOfData = (void **)PR_int__malloc( newSize ); 68 Q->startOfData = (void **)PR__malloc( newSize );
68 newStartOfData = (int8 *)Q->startOfData; 69 newStartOfData = (int8 *)Q->startOfData;
69 newEndOfData = newStartOfData + newSize; //all calcs in Bytes 70 newEndOfData = newStartOfData + newSize; //all calcs in Bytes
70 Q->endOfData = (void **)newEndOfData; 71 Q->endOfData = (void **)newEndOfData;
71 72
72 //TODO: test all of this, for both cases 73 //TODO: test all of this, for both cases
100 bottPartSize = oldSize - topPartSize - 1; //-1 for empty insertPos 101 bottPartSize = oldSize - topPartSize - 1; //-1 for empty insertPos
101 memcpy( newStartOfData, oldStartOfData, bottPartSize ); 102 memcpy( newStartOfData, oldStartOfData, bottPartSize );
102 Q->insertPos = (void **)(newStartOfData + bottPartSize); 103 Q->insertPos = (void **)(newStartOfData + bottPartSize);
103 } 104 }
104 //This free is not safe to use in wrapper lib nor app code! 105 //This free is not safe to use in wrapper lib nor app code!
105 PR_int__free(oldStartOfData); 106 PR__free(oldStartOfData);
106 } 107 }
107 108
108 109
109 /*Returns TRUE when queue is empty 110 /*Returns TRUE when queue is empty
110 */ 111 */
290 */ 291 */
291 void 292 void
292 freePrivQ( PrivQueueStruc *Q ) 293 freePrivQ( PrivQueueStruc *Q )
293 { 294 {
294 //This free is not safe to use in wrapper lib nor app code! 295 //This free is not safe to use in wrapper lib nor app code!
295 PR_int__free( Q->startOfData ); 296 PR__free( Q->startOfData );
296 PR_int__free( Q ); 297 PR__free( Q );
297 } 298 }