X-Git-Url: https://git.sur5r.net/?p=ngadmin;a=blobdiff_plain;f=raw%2Fsrc%2Flist.c;h=52b6d451b06bc807f48ff09c37ab588936014246;hp=88a222bb13782537300556ab2286b1c91ee826ad;hb=83114dbb67bdf35b81f2404e061b681c3627b564;hpb=1eae7cf16756c085cdf51e6b0513937e6ccb51df diff --git a/raw/src/list.c b/raw/src/list.c index 88a222b..52b6d45 100644 --- a/raw/src/list.c +++ b/raw/src/list.c @@ -276,6 +276,59 @@ void clearList (List *l, void (*freefunc)(void*)) { +static void __destroyElement (List *l, ListNode *ln, void (*freefunc)(void*)) { + + + if ( ln->prev==NULL ) { + l->first=ln->next; + } else { + ln->prev->next=ln->next; + } + + if ( ln->next==NULL ) { + l->last=ln->prev; + } else { + ln->next->prev=ln->prev; + } + + + if ( freefunc!=NULL ) { + freefunc(ln->data); + } + + l->count--; + free(ln); + +} + + + +// ----------------------------------------------------------------- +bool destroyElement (List *l, ListNode *ln, void (*freefunc)(void*)) { + + + if ( l==NULL || ln==NULL ) { + return false; + } + + + #ifdef MT_SAFE_LIST + pthread_mutex_lock(&l->mutex); + #endif + + __destroyElement(l, ln, freefunc); + + #ifdef MT_SAFE_LIST + pthread_mutex_unlock(&l->mutex); + #endif + + + return true; + +} + + + // --------------------------------------------------------------- bool findAndDestroy (List *l, void* data, void (*freefunc)(void*)) { @@ -302,24 +355,7 @@ bool findAndDestroy (List *l, void* data, void (*freefunc)(void*)) { } else { - if ( ln->prev==NULL ) { - l->first=ln->next; - } else { - ln->prev->next=ln->next; - } - - if ( ln->next==NULL ) { - l->last=ln->prev; - } else { - ln->next->prev=ln->prev; - } - - - if ( freefunc!=NULL ) { - freefunc(data); - } - - l->count--; + __destroyElement(l, ln, freefunc); #ifdef MT_SAFE_LIST pthread_mutex_unlock(&l->mutex);