7 // -------------------------
8 List* createEmptyList (void) {
13 l=malloc(sizeof(List));
17 pthread_cond_init(&l->cond, NULL);
18 pthread_mutex_init(&l->mutex, NULL);
27 // ------------------------------------------------
28 void destroyList (List *l, void (*freefunc)(void*)) {
39 pthread_mutex_destroy(&l->mutex);
40 pthread_cond_destroy(&l->cond);
42 for (ln=l->first; ln!=NULL; ) {
46 if ( freefunc!=NULL ) {
62 // -------------------------------------
63 void pushFrontList (List *l, void* data) {
73 pthread_mutex_lock(&l->mutex);
75 ln=malloc(sizeof(ListNode));
80 if ( l->first==NULL ) {
89 pthread_mutex_unlock(&l->mutex);
90 pthread_cond_broadcast(&l->cond);
96 // ------------------------------------
97 void pushBackList (List *l, void* data) {
107 pthread_mutex_lock(&l->mutex);
109 ln=malloc(sizeof(ListNode));
114 if ( l->last==NULL ) {
123 pthread_mutex_unlock(&l->mutex);
124 pthread_cond_broadcast(&l->cond);
130 // -------------------------
131 void* popFrontList (List *l) {
142 pthread_mutex_lock(&l->mutex);
144 if ( (ln=l->first)==NULL ) {
145 pthread_mutex_unlock(&l->mutex);
152 if ( ln->next==NULL ) {
161 pthread_mutex_unlock(&l->mutex);
162 pthread_cond_broadcast(&l->cond);
171 // ------------------------
172 void* popBackList (List *l) {
184 pthread_mutex_lock(&l->mutex);
186 if ( (ln=l->last)==NULL ) {
187 pthread_mutex_unlock(&l->mutex);
194 if ( ln->prev==NULL ) {
203 pthread_mutex_unlock(&l->mutex);
204 pthread_cond_broadcast(&l->cond);
214 // ----------------------------------------------
215 void clearList (List *l, void (*freefunc)(void*)) {
225 pthread_mutex_lock(&l->mutex);
227 for (ln=l->first; ln!=NULL; ) {
231 if ( freefunc!=NULL ) {
244 pthread_mutex_unlock(&l->mutex);
245 pthread_cond_broadcast(&l->cond);
252 // ---------------------------------------------------------------
253 bool findAndDestroy (List *l, void* data, void (*freefunc)(void*)) {
264 pthread_mutex_lock(&l->mutex);
266 for (ln=l->first; ln!=NULL && ln->data!=data; ln=ln->next);
270 pthread_mutex_unlock(&l->mutex);
274 if ( ln->prev==NULL ) {
277 ln->prev->next=ln->next;
280 if ( ln->next==NULL ) {
283 ln->next->prev=ln->prev;
287 if ( freefunc!=NULL ) {
293 pthread_mutex_unlock(&l->mutex);
294 pthread_cond_broadcast(&l->cond);
306 // -------------------------------------------------
307 void browseList (List *l, void (*browsefunc)(void*)) {
313 if ( l==NULL || browsefunc==NULL ) {
318 pthread_mutex_lock(&l->mutex);
320 for (ln=l->first; ln!=NULL; ln=ln->next) {
321 browsefunc(ln->data);
324 pthread_mutex_unlock(&l->mutex);