Changeset 1705

Show
Ignore:
Timestamp:
03/06/07 00:05:42
Author:
pvanhoof
Message:

Some locking problems

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/libtinymailui-gtk/tny-gtk-header-list-iterator.c

    r941 r1705  
    4343 
    4444        if (lock) 
    45                 g_mutex_lock (self->model->iterator_lock); 
     45                g_static_rec_mutex_lock (self->model->iterator_lock); 
    4646 
    4747        self->current = model->first; 
    4848 
    4949        if (lock) 
    50                 g_mutex_unlock (self->model->iterator_lock); 
     50                g_static_rec_mutex_unlock (self->model->iterator_lock); 
    5151 
    5252        return; 
     
    103103        /* Move the iterator to the next node */ 
    104104 
    105         g_mutex_lock (me->model->iterator_lock); 
     105        g_static_rec_mutex_lock (me->model->iterator_lock); 
    106106        me->current = g_list_next (me->current); 
    107         g_mutex_unlock (me->model->iterator_lock); 
     107        g_static_rec_mutex_unlock (me->model->iterator_lock); 
    108108 
    109109        return; 
     
    128128        /* Move the iterator to the previous node */ 
    129129 
    130         g_mutex_lock (me->model->iterator_lock); 
     130        g_static_rec_mutex_lock (me->model->iterator_lock); 
    131131        me->current = g_list_previous (me->current); 
    132         g_mutex_unlock (me->model->iterator_lock); 
     132        g_static_rec_mutex_unlock (me->model->iterator_lock); 
    133133 
    134134        return; 
     
    149149        TnyGtkHeaderListIterator *me = (TnyGtkHeaderListIterator*) self; 
    150150        gboolean retval = FALSE; 
    151          
    152         g_mutex_lock (me->model->iterator_lock); 
    153          
    154         if (G_UNLIKELY (!me  || !me->model)) 
     151 
     152        g_static_rec_mutex_lock (me->model->iterator_lock); 
     153 
     154        if (G_UNLIKELY (!me  || !me->model)) { 
     155                g_static_rec_mutex_unlock (me->model->iterator_lock); 
    155156                return TRUE; 
     157        } 
    156158 
    157159        retval = (me->current == NULL); 
    158         g_mutex_unlock (me->model->iterator_lock); 
    159          
     160        g_static_rec_mutex_unlock (me->model->iterator_lock); 
     161 
    160162        return retval; 
    161163} 
     
    182184           using that one. */ 
    183185 
    184         g_mutex_lock (me->model->iterator_lock); 
     186        g_static_rec_mutex_lock (me->model->iterator_lock); 
    185187        me->current = me->model->first; 
    186         g_mutex_unlock (me->model->iterator_lock); 
     188        g_static_rec_mutex_unlock (me->model->iterator_lock); 
    187189 
    188190        return; 
     
    210212           stored a reference. */ 
    211213 
    212         g_mutex_lock (me->model->iterator_lock); 
     214        g_static_rec_mutex_lock (me->model->iterator_lock); 
    213215        me->current = g_list_nth (me->model->first, nth); 
    214         g_mutex_unlock (me->model->iterator_lock); 
     216        g_static_rec_mutex_unlock (me->model->iterator_lock); 
    215217 
    216218        return; 
     
    235237        /* Give the data of the current node */ 
    236238 
    237         g_mutex_lock (me->model->iterator_lock); 
     239        g_static_rec_mutex_lock (me->model->iterator_lock); 
    238240        retval = (G_UNLIKELY (me->current)) ? me->current->data : NULL; 
    239         g_mutex_unlock (me->model->iterator_lock); 
     241        g_static_rec_mutex_unlock (me->model->iterator_lock); 
    240242 
    241243        if (retval) 
    242                 g_object_ref (G_OBJECT(retval));         
     244                g_object_ref (G_OBJECT(retval)); 
     245 
    243246        return (GObject*)retval; 
    244247} 
     
    255258                return NULL; 
    256259 
    257               g_object_ref (G_OBJECT (me->model)); 
     260      g_object_ref (G_OBJECT (me->model)); 
    258261 
    259262        return TNY_LIST (me->model); 
     
    270273        klass->get_list_func = tny_gtk_header_list_iterator_get_list; 
    271274        klass->is_done = tny_gtk_header_list_iterator_is_done; 
    272          
     275 
    273276        return; 
    274277} 
  • trunk/libtinymailui-gtk/tny-gtk-header-list-model.c

    r1704 r1705  
    186186        /* Fill an GtkTreeIter (this is not a TnyIterator!) using a path */ 
    187187 
    188         g_mutex_lock (list_model->iterator_lock); 
     188        g_static_rec_mutex_lock (list_model->iterator_lock); 
    189189 
    190190        i = gtk_tree_path_get_indices (path)[0]; 
     
    192192        if (G_UNLIKELY (i >= list_model->length)) 
    193193        { 
    194                 g_mutex_unlock (list_model->iterator_lock); 
     194                g_static_rec_mutex_unlock (list_model->iterator_lock); 
    195195                g_mutex_unlock (list_model->folder_lock); 
    196196                return FALSE; 
     
    209209        iter->user_data = ptr; 
    210210        retval = (iter->user_data != NULL); 
    211          
    212         g_mutex_unlock (list_model->iterator_lock); 
    213  
    214          
     211 
     212        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    215213        g_mutex_unlock (list_model->folder_lock); 
    216214 
     
    231229 
    232230        g_mutex_lock (list_model->folder_lock); 
    233         g_mutex_lock (list_model->iterator_lock); 
     231        g_static_rec_mutex_lock (list_model->iterator_lock); 
    234232 
    235233        while (!_tny_gtk_header_list_iterator_is_done_nl ((TnyGtkHeaderListIterator*)list_model->iterator)) 
     
    251249        gtk_tree_path_append_index (tree_path, i); 
    252250 
    253         g_mutex_unlock (list_model->iterator_lock); 
     251        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    254252 
    255253        g_mutex_unlock (list_model->folder_lock); 
     
    341339 
    342340        g_mutex_lock (list_model->folder_lock); 
    343         g_mutex_lock (list_model->iterator_lock); 
     341        g_static_rec_mutex_lock (list_model->iterator_lock); 
    344342 
    345343        /* Remember the ptr we've set above? Get the header instance out of the 
     
    350348        if (((GObject*)header)->ref_count <= 0) 
    351349        { 
    352                 g_mutex_unlock (list_model->iterator_lock); 
     350                g_static_rec_mutex_unlock (list_model->iterator_lock); 
    353351                g_mutex_unlock (list_model->folder_lock); 
    354352                return; 
     
    424422        } 
    425423 
    426         g_mutex_unlock (list_model->iterator_lock); 
     424        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    427425        g_mutex_unlock (list_model->folder_lock); 
    428426 
     
    443441 
    444442        g_mutex_lock (list_model->folder_lock); 
    445         g_mutex_lock (list_model->iterator_lock); 
     443        g_static_rec_mutex_lock (list_model->iterator_lock); 
    446444 
    447445        /* We simply move the iterator and get the value */ 
     
    453451        retval = (iter->user_data != NULL); 
    454452 
    455         g_mutex_unlock (list_model->iterator_lock); 
     453        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    456454        g_mutex_unlock (list_model->folder_lock); 
    457455 
     
    476474 
    477475        g_mutex_lock (list_model->folder_lock); 
    478         g_mutex_lock (list_model->iterator_lock); 
     476        g_static_rec_mutex_lock (list_model->iterator_lock); 
    479477 
    480478        if (G_LIKELY (!iter)) 
    481479                retval = list_model->length; 
    482480 
    483         g_mutex_unlock (list_model->iterator_lock); 
     481        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    484482        g_mutex_unlock (list_model->folder_lock); 
    485483 
     
    498496 
    499497        g_mutex_lock (list_model->folder_lock); 
    500         g_mutex_lock (list_model->iterator_lock); 
     498        g_static_rec_mutex_lock (list_model->iterator_lock); 
    501499 
    502500        restore = ((TnyGtkHeaderListIterator*)list_model->iterator)->current; 
     
    512510                iter->user_data = child; 
    513511 
    514                 g_mutex_unlock (list_model->iterator_lock); 
     512                g_static_rec_mutex_unlock (list_model->iterator_lock); 
    515513                g_mutex_unlock (list_model->folder_lock); 
    516514 
     
    520518        ((TnyGtkHeaderListIterator*)list_model->iterator)->current = restore; 
    521519 
    522         g_mutex_unlock (list_model->iterator_lock); 
     520        g_static_rec_mutex_unlock (list_model->iterator_lock); 
    523521        g_mutex_unlock (list_model->folder_lock); 
    524522 
     
    552550        GtkTreeIter iter; 
    553551 
     552        g_static_rec_mutex_lock (me->iterator_lock); 
     553 
    554554        path = gtk_tree_path_new (); 
    555555        gtk_tree_path_append_index (path, 0); 
     
    559559        /* Prepend something to the list */ 
    560560 
    561         g_mutex_lock (me->iterator_lock); 
    562561        g_object_ref (G_OBJECT (item)); 
    563562        me->first = g_list_prepend (me->first, item); 
     
    573572        ((TnyGtkHeaderListIterator*)me->iterator)->current = me->first; 
    574573        me->last_nth = 0; 
    575         g_mutex_unlock (me->iterator_lock); 
    576574 
    577575        /* Letting the observers know about this (the GtkTreeView) */ 
    578576        gtk_tree_model_row_inserted (GTK_TREE_MODEL (me), path, &iter); 
    579577        gtk_tree_path_free (path); 
     578 
     579        g_static_rec_mutex_unlock (me->iterator_lock); 
     580 
    580581} 
    581582 
     
    587588        GtkTreeIter iter; 
    588589 
     590        g_static_rec_mutex_lock (me->iterator_lock); 
     591 
    589592        path = gtk_tree_path_new (); 
    590593        iter.stamp = me->stamp; 
     
    593596        /* Append something to the list */ 
    594597 
    595         g_mutex_lock (me->iterator_lock); 
    596598        g_object_ref (G_OBJECT (item)); 
    597599        me->first = g_list_append (me->first, item); 
     
    606608        ((TnyGtkHeaderListIterator*)me->iterator)->current = me->first; 
    607609        me->last_nth = 0; 
    608         g_mutex_unlock (me->iterator_lock); 
    609610 
    610611        /* Letting the observers know about this (the GtkTreeView) */ 
     
    613614        gtk_tree_path_free (path); 
    614615 
     616        g_static_rec_mutex_unlock (me->iterator_lock); 
     617 
    615618} 
    616619 
     
    621624        guint retval = 0; 
    622625 
    623         g_mutex_lock (me->iterator_lock); 
     626        g_static_rec_mutex_lock (me->iterator_lock); 
    624627        retval = me->first?g_list_length (me->first):0; 
    625         g_mutex_unlock (me->iterator_lock); 
     628        g_static_rec_mutex_unlock (me->iterator_lock); 
    626629 
    627630        return retval; 
     
    638641        g_return_if_fail (G_IS_OBJECT (me)); 
    639642 
     643        g_static_rec_mutex_lock (me->iterator_lock); 
     644 
    640645        iter.stamp = me->stamp; 
    641646        iter.user_data = item; 
     
    644649        /* Remove something from the list */ 
    645650 
    646         g_mutex_lock (me->iterator_lock); 
    647651        me->first = g_list_remove (me->first, (gconstpointer)item); 
    648652        me->length--; 
     
    651655                g_list_free (me->index); 
    652656        me->index = NULL; 
    653         g_object_unref (G_OBJECT (item)); 
    654657 
    655658        /* Reset the internal iterator */ 
    656659        ((TnyGtkHeaderListIterator*)me->iterator)->current = me->first; 
    657660        me->last_nth = 0; 
    658         g_mutex_unlock (me->iterator_lock); 
    659661 
    660662        /* Letting the observers know about this (the GtkTreeView) */ 
    661663        gtk_tree_model_row_deleted (GTK_TREE_MODEL (me), path); 
    662664        gtk_tree_path_free (path); 
     665 
     666        g_object_unref (G_OBJECT (item)); 
     667 
     668        g_static_rec_mutex_unlock (me->iterator_lock); 
    663669 
    664670} 
     
    688694           only a copy of the list-nodes of course. */ 
    689695 
    690         g_mutex_lock (me->iterator_lock); 
     696        g_static_rec_mutex_lock (me->iterator_lock); 
     697 
    691698        GList *list_copy = g_list_copy (me->first); 
    692699        g_list_foreach (list_copy, (GFunc)g_object_ref, NULL); 
    693700        copy->first = list_copy; 
    694701        copy->usable_index = FALSE; 
    695         g_mutex_unlock (me->iterator_lock); 
     702 
     703        g_static_rec_mutex_unlock (me->iterator_lock); 
    696704 
    697705        return TNY_LIST (copy); 
     
    705713        /* Foreach item in the list (without using a slower iterator) */ 
    706714 
    707         g_mutex_lock (me->iterator_lock); 
     715        g_static_rec_mutex_lock (me->iterator_lock); 
     716 
    708717        g_list_foreach (me->first, func, user_data); 
    709         g_mutex_unlock (me->iterator_lock); 
     718 
     719        g_static_rec_mutex_unlock (me->iterator_lock); 
    710720 
    711721        return; 
     
    857867 
    858868        g_mutex_lock (self->folder_lock); 
    859         g_mutex_lock (self->iterator_lock); 
     869        g_static_rec_mutex_lock (self->iterator_lock); 
    860870 
    861871        if (self->folder) 
     
    899909 
    900910 
    901  
    902         g_mutex_unlock (self->iterator_lock); 
     911        g_static_rec_mutex_unlock (self->iterator_lock); 
    903912        g_mutex_unlock (self->folder_lock); 
    904913 
    905914        g_mutex_free (self->folder_lock); 
    906915        self->folder_lock = NULL; 
    907         g_mutex_free (self->iterator_lock); 
     916 
     917        g_static_rec_mutex_free (self->iterator_lock); 
    908918        self->iterator_lock = NULL; 
    909919 
     
    932942        self->folder = NULL; 
    933943        self->folder_lock = g_mutex_new (); 
    934         self->iterator_lock = g_mutex_new (); 
     944        self->iterator_lock = g_new0 (GStaticRecMutex, 1); 
     945        g_static_rec_mutex_init (self->iterator_lock); 
    935946        self->first = NULL; 
    936947        self->length = 0; 
     
    964975 
    965976        g_mutex_lock (self->folder_lock); 
    966         g_mutex_lock (self->iterator_lock); 
    967  
     977        g_static_rec_mutex_lock (self->iterator_lock); 
    968978 
    969979        /* Unreference the previous headers */ 
     
    989999        self->last_nth = 0; 
    9901000 
    991         g_mutex_unlock (self->iterator_lock); 
     1001        g_static_rec_mutex_unlock (self->iterator_lock); 
    9921002        g_mutex_unlock (self->folder_lock); 
    9931003 
     
    9971007 
    9981008        g_mutex_lock (self->folder_lock); 
    999         g_mutex_lock (self->iterator_lock); 
     1009        g_static_rec_mutex_lock (self->iterator_lock); 
    10001010 
    10011011        /* Reset the internal iterator */ 
     
    10191029        self->folder = folder; 
    10201030 
    1021         g_mutex_unlock (self->iterator_lock); 
    1022         g_mutex_unlock (self->folder_lock);      
    1023  
    10241031        /* Notify the observers (the GtkTreeView) */ 
    10251032        gtk_tree_path_append_index (path, 0); 
    10261033        gtk_tree_model_row_inserted (GTK_TREE_MODEL (self), path, &iter); 
    10271034        gtk_tree_path_free (path); 
     1035 
     1036        g_static_rec_mutex_unlock (self->iterator_lock); 
     1037        g_mutex_unlock (self->folder_lock); 
    10281038 
    10291039        return; 
  • trunk/libtinymailui-gtk/tny-gtk-header-list-model.h

    r1419 r1705  
    6464        GObject parent; 
    6565 
    66         GMutex *folder_lock, *iterator_lock; 
     66        GMutex *folder_lock; 
     67        GStaticRecMutex *iterator_lock; 
    6768        TnyFolder *folder; 
    6869        gint length;