gwlib List Locking issue

Andreas Fink <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hi folks,

I was optimizing my code which uses gwlib and have hit a big problem  
when I was converting things like


mutex_lock(my_list_mutex);
do_someting_with(my_list);
mutex_unlock(my_list_mutex);


to:

gwlist_lock(my_list);
do_someting_with(my_list);
gwlist_unlock(my_list);

to get rid of an additional mutex we dont really need as we have a  
built in one in List.


While doing that I was hitting a deadlock issue.
It turned out that in my do_something part I called gwlist_sort and  
that looks like this:

void gwlist_sort(List *list, int(*cmp)(const void *, const void *))
{
     gw_assert(list != NULL && cmp != NULL);

     gwlist_lock(list);
     if (list->len == 0) {
         /* nothing to sort */
         gwlist_unlock(list);
         return;
     }
     qsort(&GET(list, 0), list->len, sizeof(void*), cmp);
     gwlist_unlock(list);
}


In my eyes, this function should call lock()/unlock(). not gwlist_lock 
()/gwlist_unlock();

It is the only place where gwlist_lock is used in list.c.

Is this simply a bug I have spotted or was there anywhere a specific  
reason why a sort uses the permanent lock instead of the  
single_operation_lock?







Andreas Fink
Fink Consulting GmbH
---------------------------------------------------------------
Tel: +41-61-6666332 Fax: +41-61-6666331  Mobile: +41-79-2457333
Address: Clarastrasse 3, 4058 Basel, Switzerland
E-Mail:  [email protected]
Homepage: http://www.finkconsulting.com
---------------------------------------------------------------
ICQ: 8239353
MSN: [email protected] AIM: smsrelay Skype: andreasfink
Yahoo: finkconsulting SMS: +41792457333
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.