Changeset 3082 for pjproject/trunk
- Timestamp:
- Jan 29, 2010 11:20:43 AM (15 years ago)
- Location:
- pjproject/trunk/pjlib/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjlib/src/pj/pool.c
r3081 r3082 32 32 #endif 33 33 34 #define LOG(expr) PJ_LOG(6,expr) 34 #define LOG(expr) PJ_LOG(6,expr) 35 #define ALIGN_PTR(PTR,ALIGNMENT) (PTR + (-(long)(PTR) & (ALIGNMENT-1))) 35 36 36 37 PJ_DEF_DATA(int) PJ_NO_MEMORY_EXCEPTION; … … 72 73 73 74 /* Set the start pointer, aligning it as needed */ 74 block->cur = (unsigned char*) 75 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & 76 ~(PJ_POOL_ALIGNMENT - 1)); 75 block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT); 77 76 78 77 /* Insert in the front of the list. */ … … 217 216 218 217 /* Set the start pointer, aligning it as needed */ 219 block->cur = (unsigned char*) 220 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & 221 ~(PJ_POOL_ALIGNMENT - 1)); 218 block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT); 222 219 223 220 pj_list_insert_after(&pool->block_list, block); … … 263 260 264 261 /* Set the start pointer, aligning it as needed */ 265 block->cur = (unsigned char*) 266 (((unsigned long)block->buf + PJ_POOL_ALIGNMENT - 1) & 267 ~(PJ_POOL_ALIGNMENT - 1)); 262 block->cur = ALIGN_PTR(block->buf, PJ_POOL_ALIGNMENT); 268 263 269 264 pool->capacity = block->end - (unsigned char*)pool; -
pjproject/trunk/pjlib/src/pjlib-test/pool.c
r3081 r3082 85 85 pj_pool_t *pool; 86 86 void *ptr; 87 enum { MEMSIZE = 64, LOOP = 100 }; 88 unsigned i; 87 89 88 90 PJ_LOG(3,("test", "...alignment test")); 89 91 90 pool = pj_pool_create(mem, NULL, PJ_POOL_SIZE+ 64, 64, NULL);92 pool = pj_pool_create(mem, NULL, PJ_POOL_SIZE+MEMSIZE, MEMSIZE, NULL); 91 93 if (!pool) 92 94 return -300; … … 94 96 #define IS_ALIGNED(p) ((((unsigned long)p) & (PJ_POOL_ALIGNMENT-1)) == 0) 95 97 96 /* Test first allocation */ 97 ptr = pj_pool_alloc(pool, 1); 98 if (!IS_ALIGNED(ptr)) { 99 pj_pool_release(pool); 100 return -310; 101 } 102 103 /* Test subsequent allocation */ 104 ptr = pj_pool_alloc(pool, 1); 105 if (!IS_ALIGNED(ptr)) { 106 pj_pool_release(pool); 107 return -320; 108 } 109 110 /* Test allocation after new block is created */ 111 ptr = pj_pool_alloc(pool, 127); 112 if (!IS_ALIGNED(ptr)) { 113 pj_pool_release(pool); 114 return -330; 115 } 116 117 /* Reset the pool */ 118 pj_pool_reset(pool); 119 120 /* Retest first allocation */ 121 ptr = pj_pool_alloc(pool, 1); 122 if (!IS_ALIGNED(ptr)) { 123 pj_pool_release(pool); 124 return -340; 125 } 126 127 /* Retest subsequent allocation */ 128 ptr = pj_pool_alloc(pool, 1); 129 if (!IS_ALIGNED(ptr)) { 130 pj_pool_release(pool); 131 return -350; 98 for (i=0; i<LOOP; ++i) { 99 /* Test first allocation */ 100 ptr = pj_pool_alloc(pool, 1); 101 if (!IS_ALIGNED(ptr)) { 102 pj_pool_release(pool); 103 return -310; 104 } 105 106 /* Test subsequent allocation */ 107 ptr = pj_pool_alloc(pool, 1); 108 if (!IS_ALIGNED(ptr)) { 109 pj_pool_release(pool); 110 return -320; 111 } 112 113 /* Test allocation after new block is created */ 114 ptr = pj_pool_alloc(pool, MEMSIZE*2+1); 115 if (!IS_ALIGNED(ptr)) { 116 pj_pool_release(pool); 117 return -330; 118 } 119 120 /* Reset the pool */ 121 pj_pool_reset(pool); 132 122 } 133 123 … … 142 132 { 143 133 pj_pool_t *pool; 144 char buf[ 256];134 char buf[512]; 145 135 void *ptr; 136 enum { LOOP = 100 }; 137 unsigned i; 146 138 147 139 PJ_LOG(3,("test", "...pool_buf alignment test")); … … 151 143 return -400; 152 144 153 /* Test first allocation */ 154 ptr = pj_pool_alloc(pool, 1); 155 if (!IS_ALIGNED(ptr)) { 156 pj_pool_release(pool); 157 return -410; 158 } 159 160 /* Test subsequent allocation */ 161 ptr = pj_pool_alloc(pool, 1); 162 if (!IS_ALIGNED(ptr)) { 163 pj_pool_release(pool); 164 return -420; 165 } 166 167 /* Reset the pool */ 168 pj_pool_reset(pool); 169 170 /* Retest first allocation */ 171 ptr = pj_pool_alloc(pool, 1); 172 if (!IS_ALIGNED(ptr)) { 173 pj_pool_release(pool); 174 return -430; 175 } 176 177 /* Retest subsequent allocation */ 178 ptr = pj_pool_alloc(pool, 1); 179 if (!IS_ALIGNED(ptr)) { 180 pj_pool_release(pool); 181 return -440; 145 for (i=0; i<LOOP; ++i) { 146 /* Test first allocation */ 147 ptr = pj_pool_alloc(pool, 1); 148 if (!IS_ALIGNED(ptr)) { 149 pj_pool_release(pool); 150 return -410; 151 } 152 153 /* Test subsequent allocation */ 154 ptr = pj_pool_alloc(pool, 1); 155 if (!IS_ALIGNED(ptr)) { 156 pj_pool_release(pool); 157 return -420; 158 } 159 160 /* Reset the pool */ 161 pj_pool_reset(pool); 182 162 } 183 163
Note: See TracChangeset
for help on using the changeset viewer.