Changeset 4421 for trunk/module-datastruct-llist.c
- Timestamp:
- 01/12/11 08:36:08 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-datastruct-llist.c
r4404 r4421 19 19 { 20 20 LLIST *l = calloc(1, sizeof(LLIST)); 21 21 22 22 pthread_mutex_init(&l->lock, NULL); 23 23 … … 43 43 void ll_clear(LLIST *l) 44 44 { 45 if (!l) return; 45 46 void *obj; 46 47 … … 48 49 while ((obj = ll_iter_next(it))) 49 50 ll_iter_remove(it); 51 l->count = 0; 50 52 ll_iter_release(it); 51 53 } … … 58 60 while ((obj = ll_iter_next(it))) 59 61 ll_iter_remove_data(it); 62 l->count = 0; 60 63 ll_iter_release(it); 61 64 } 62 65 63 void ll_append (LLIST *l, void *obj)64 { 65 if ( obj) {66 void ll_append_nolock(LLIST *l, void *obj) 67 { 68 if (l && obj) { 66 69 LL_NODE *new = calloc(1, sizeof(LL_NODE)); 67 70 LL_NODE *n = l->initial; … … 75 78 } else 76 79 l->initial = new; 80 l->count++; 81 } 82 } 83 84 void ll_append(LLIST *l, void *obj) 85 { 86 if (l && obj) { 87 pthread_mutex_lock(&l->lock); 88 ll_append_nolock(l, obj); 89 pthread_mutex_unlock(&l->lock); 77 90 } 78 91 } … … 84 97 it->l = l; 85 98 if (l) { 99 pthread_mutex_lock(&l->lock); 86 100 it->cur = l->initial; 87 pthread_mutex_lock(&l->lock);88 101 } 89 102 else 90 103 it->cur = NULL; 91 92 104 93 105 return it; … … 144 156 if(it && obj) { 145 157 if (!it->cur) 146 ll_append (it->l, obj);158 ll_append_nolock(it->l, obj); 147 159 else { 148 160 LL_NODE *n = calloc(1, sizeof(LL_NODE)); … … 153 165 it->cur->prv->nxt = n; 154 166 it->cur->prv = n; 167 it->l->count++; 155 168 } 156 169 } … … 175 188 else it->l->initial = n->nxt; 176 189 190 it->l->count--; 177 191 NULLFREE(n); 178 192 return obj; … … 194 208 return 0; 195 209 196 void *obj; 197 int c = 0; 198 199 LL_ITER *it = ll_iter_create(l);; 200 while ((obj = ll_iter_next(it))) c++; 201 ll_iter_release(it); 202 203 return c; 204 } 205 206 void ll_insert_at(LLIST *l, void *obj, int pos) 207 { 210 return l->count; 211 } 212 213 void ll_insert_at_nolock(LLIST *l, void *obj, int pos) 214 { 215 if (!l || !obj) 216 return; 217 208 218 LL_NODE *new = calloc(1, sizeof(LL_NODE)); 209 219 LL_NODE *n = l->initial; … … 221 231 if (n && n->prv) n->prv->nxt = new; 222 232 else l->initial = new; 233 l->count++; 223 234 224 235 if (n) n->prv = new; 236 } 237 238 void ll_insert_at(LLIST *l, void *obj, int pos) 239 { 240 if (!l || !obj) 241 return; 242 243 pthread_mutex_lock(&l->lock); 244 ll_insert_at_nolock(l, obj, pos); 245 pthread_mutex_unlock(&l->lock); 225 246 } 226 247
Note:
See TracChangeset
for help on using the changeset viewer.