Changeset 2521

Show
Ignore:
Timestamp:
07/27/07 18:44:34
Author:
pvanhoof
Message:

Cond locks in the callbacks

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • devel/pvanhoof/sessionwork/ChangeLog

    r2513 r2521  
    1111        a callback rather than a GError. In the callback you can know about 
    1212        when the account got connected and if not, why it failed 
     13 
     14        * Cond locks in the queues of the store accounts while the callbacks 
     15        are happening. This is a significant policy change in locking 
     16        behaviour that should be well tested.  
    1317 
    1418        * This was a major API change in TnyAccount 
  • devel/pvanhoof/sessionwork/libtinymail-camel/camel-lite/camel/providers/pop3/camel-pop3-engine.c

    r2517 r2521  
    336336        g_static_rec_mutex_lock (pe->lock); 
    337337 
     338        camel_object_ref (pe); 
     339 
    338340        if (pcwait && pcwait->state >= CAMEL_POP3_COMMAND_OK) { 
     341                camel_object_unref (pe); 
     342 
    339343                g_static_rec_mutex_unlock (pe->lock); 
    340344                return 0; 
     
    343347        pc = pe->current; 
    344348        if (pc == NULL) { 
     349                camel_object_unref (pe); 
    345350                g_static_rec_mutex_unlock (pe->lock); 
    346351                return 0; 
     
    432437                if (have_err) 
    433438                        camel_service_disconnect (CAMEL_SERVICE (pe->store), FALSE, &ex); 
     439 
     440                camel_object_unref (pe); 
    434441                g_static_rec_mutex_unlock (pe->lock); 
    435442                return 0; 
     
    439446                camel_service_disconnect (CAMEL_SERVICE (pe->store), FALSE, &ex); 
    440447 
     448        camel_object_unref (pe); 
    441449        g_static_rec_mutex_unlock (pe->lock); 
    442450 
     
    465473        camel_service_disconnect (CAMEL_SERVICE (pe->store), FALSE, &ex); 
    466474 
     475        camel_object_unref (pe); 
    467476        g_static_rec_mutex_unlock (pe->lock); 
    468477 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-folder.c

    r2510 r2521  
    934934        GError *err; 
    935935        TnySessionCamel *session; 
     936 
     937        GCond* condition; 
     938        gboolean had_callback; 
     939        GMutex *mutex; 
     940 
    936941} SyncFolderInfo; 
    937942 
     
    955960        tny_idle_stopper_destroy (info->stopper); 
    956961        info->stopper = NULL; 
    957          
    958         g_slice_free (SyncFolderInfo, thr_user_data); 
     962 
     963        g_mutex_lock (info->mutex); 
     964        g_cond_broadcast (info->condition); 
     965        info->had_callback = TRUE; 
     966        g_mutex_unlock (info->mutex); 
    959967 
    960968        return; 
     
    10511059 
    10521060        g_static_rec_mutex_unlock (priv->folder_lock); 
     1061 
     1062        info->mutex = g_mutex_new (); 
     1063        info->condition = g_cond_new (); 
     1064        info->had_callback = FALSE; 
    10531065 
    10541066        if (info->callback) 
     
    10611073                _tny_camel_folder_unreason (priv); 
    10621074        } 
     1075 
     1076        /* Wait on the queue for the mainloop callback to be finished */ 
     1077        g_mutex_lock (info->mutex); 
     1078        if (!info->had_callback) 
     1079                g_cond_wait (info->condition, info->mutex); 
     1080        g_mutex_unlock (info->mutex); 
     1081 
     1082        g_mutex_free (info->mutex); 
     1083        g_cond_free (info->condition); 
     1084 
     1085        g_slice_free (SyncFolderInfo, thr_user_data); 
    10631086 
    10641087        return NULL; 
     
    11481171        GError *err; 
    11491172        TnySessionCamel *session; 
     1173 
     1174        GCond* condition; 
     1175        gboolean had_callback; 
     1176        GMutex *mutex; 
     1177 
    11501178} RefreshFolderInfo; 
    11511179 
     
    11721200        tny_idle_stopper_destroy (info->stopper); 
    11731201        info->stopper = NULL; 
    1174          
    1175         g_slice_free (RefreshFolderInfo, thr_user_data); 
     1202 
     1203        g_mutex_lock (info->mutex); 
     1204        g_cond_broadcast (info->condition); 
     1205        info->had_callback = TRUE; 
     1206        g_mutex_unlock (info->mutex); 
    11761207 
    11771208        return; 
     
    12691300        } 
    12701301 
    1271  
    12721302        g_static_rec_mutex_unlock (priv->folder_lock); 
     1303 
     1304        info->mutex = g_mutex_new (); 
     1305        info->condition = g_cond_new (); 
     1306        info->had_callback = FALSE; 
    12731307 
    12741308        if (info->callback) 
     
    12811315                _tny_camel_folder_unreason (priv); 
    12821316        } 
     1317 
     1318        /* Wait on the queue for the mainloop callback to be finished */ 
     1319        g_mutex_lock (info->mutex); 
     1320        if (!info->had_callback) 
     1321                g_cond_wait (info->condition, info->mutex); 
     1322        g_mutex_unlock (info->mutex); 
     1323 
     1324        g_mutex_free (info->mutex); 
     1325        g_cond_free (info->condition); 
     1326        g_slice_free (RefreshFolderInfo, info); 
    12831327 
    12841328        return NULL; 
     
    15631607        TnyIdleStopper *stopper; 
    15641608        gboolean cancelled; 
     1609 
     1610        GCond* condition; 
     1611        gboolean had_callback; 
     1612        GMutex *mutex; 
     1613 
    15651614} GetMsgInfo; 
    15661615 
     
    15941643        info->stopper = NULL; 
    15951644 
    1596         g_slice_free (GetMsgInfo, info); 
     1645        g_mutex_lock (info->mutex); 
     1646        g_cond_broadcast (info->condition); 
     1647        info->had_callback = TRUE; 
     1648        g_mutex_unlock (info->mutex); 
     1649 
     1650        return; 
    15971651} 
    15981652 
     
    16751729                info->err = g_error_copy ((const GError *) err); 
    16761730                if (info->msg && G_IS_OBJECT (info->msg)) 
    1677                         g_object_unref (G_OBJECT (info->msg)); 
     1731                        g_object_unref (info->msg); 
    16781732                info->msg = NULL; 
    16791733        } else 
    16801734                info->err = NULL; 
    16811735 
    1682         g_object_unref (G_OBJECT (info->header)); 
     1736        g_object_unref (info->header); 
     1737 
     1738        info->mutex = g_mutex_new (); 
     1739        info->condition = g_cond_new (); 
     1740        info->had_callback = FALSE; 
    16831741 
    16841742        if (info->callback) 
     
    16891747        } else {/* thread reference */ 
    16901748                _tny_camel_folder_unreason (priv); 
    1691                 g_object_unref (G_OBJECT (info->self)); 
    1692         } 
    1693  
     1749                g_object_unref (info->self); 
     1750        } 
     1751 
     1752        /* Wait on the queue for the mainloop callback to be finished */ 
     1753        g_mutex_lock (info->mutex); 
     1754        if (!info->had_callback) 
     1755                g_cond_wait (info->condition, info->mutex); 
     1756        g_mutex_unlock (info->mutex); 
     1757 
     1758        g_mutex_free (info->mutex); 
     1759        g_cond_free (info->condition); 
     1760 
     1761        g_slice_free (GetMsgInfo, info); 
    16941762 
    16951763        return NULL; 
     
    25152583        gboolean cancelled; 
    25162584        GList *rems, *adds; 
     2585 
     2586        GCond* condition; 
     2587        gboolean had_callback; 
     2588        GMutex *mutex; 
     2589 
    25172590} CopyFolderInfo; 
    25182591 
     
    25462619        g_free (info->new_name); 
    25472620 
    2548         g_slice_free (CopyFolderInfo, info); 
     2621 
     2622        g_mutex_lock (info->mutex); 
     2623        g_cond_broadcast (info->condition); 
     2624        info->had_callback = TRUE; 
     2625        g_mutex_unlock (info->mutex); 
     2626 
     2627        return; 
    25492628} 
    25502629 
     
    26332712        g_static_rec_mutex_unlock (priv->folder_lock); 
    26342713 
     2714        info->mutex = g_mutex_new (); 
     2715        info->condition = g_cond_new (); 
     2716        info->had_callback = FALSE; 
     2717 
    26352718        if (info->callback) 
    26362719        { 
     
    26412724                g_object_unref (info->into); 
    26422725                g_object_unref (info->self); 
    2643 /*              _tny_camel_folder_unreason (priv); */ 
    2644         } 
     2726        } 
     2727 
     2728        /* Wait on the queue for the mainloop callback to be finished */ 
     2729        g_mutex_lock (info->mutex); 
     2730        if (!info->had_callback) 
     2731                g_cond_wait (info->condition, info->mutex); 
     2732        g_mutex_unlock (info->mutex); 
     2733 
     2734        g_mutex_free (info->mutex); 
     2735        g_cond_free (info->condition); 
     2736 
     2737        g_slice_free (CopyFolderInfo, info); 
    26452738 
    26462739        return NULL; 
     
    27522845        gint to_unread; 
    27532846        gboolean cancelled; 
     2847 
     2848        GCond* condition; 
     2849        gboolean had_callback; 
     2850        GMutex *mutex; 
     2851 
    27542852} TransferMsgsInfo; 
    27552853 
     
    28172915        info->stopper = NULL; 
    28182916 
    2819         g_slice_free (TransferMsgsInfo, info); 
     2917 
     2918        g_mutex_lock (info->mutex); 
     2919        g_cond_broadcast (info->condition); 
     2920        info->had_callback = TRUE; 
     2921        g_mutex_unlock (info->mutex); 
    28202922 
    28212923        return; 
     
    32043306                info->err = NULL; 
    32053307 
     3308 
     3309        info->mutex = g_mutex_new (); 
     3310        info->condition = g_cond_new (); 
     3311        info->had_callback = FALSE; 
     3312 
    32063313        /* Call callback function, if it exists */ 
    32073314        if (info->callback) 
     
    32183325                g_object_unref (G_OBJECT (info->folder_dst)); 
    32193326        } 
     3327 
     3328        /* Wait on the queue for the mainloop callback to be finished */ 
     3329        g_mutex_lock (info->mutex); 
     3330        if (!info->had_callback) 
     3331                g_cond_wait (info->condition, info->mutex); 
     3332        g_mutex_unlock (info->mutex); 
     3333 
     3334        g_mutex_free (info->mutex); 
     3335        g_cond_free (info->condition); 
     3336 
     3337        g_slice_free (TransferMsgsInfo, info); 
    32203338 
    32213339        return NULL; 
     
    39134031        TnyFolderStoreQuery *query; 
    39144032        gpointer user_data; 
    3915         guint depth; TnySessionCamel *session; 
     4033        guint depth;  
     4034        TnySessionCamel *session; 
     4035 
     4036        GCond* condition; 
     4037        gboolean had_callback; 
     4038        GMutex *mutex; 
     4039 
    39164040} GetFoldersInfo; 
    39174041 
     
    39334057        _tny_session_stop_operation (info->session); 
    39344058 
    3935         g_slice_free (GetFoldersInfo, info); 
     4059        g_mutex_lock (info->mutex); 
     4060        g_cond_broadcast (info->condition); 
     4061        info->had_callback = TRUE; 
     4062        g_mutex_unlock (info->mutex); 
    39364063 
    39374064        return; 
     
    39674094        if (info->query) 
    39684095                g_object_unref (G_OBJECT (info->query)); 
     4096 
     4097        info->mutex = g_mutex_new (); 
     4098        info->condition = g_cond_new (); 
     4099        info->had_callback = FALSE; 
    39694100 
    39704101 
     
    39804111                g_object_unref (G_OBJECT (info->list)); 
    39814112        } 
     4113 
     4114        /* Wait on the queue for the mainloop callback to be finished */ 
     4115        g_mutex_lock (info->mutex); 
     4116        if (!info->had_callback) 
     4117                g_cond_wait (info->condition, info->mutex); 
     4118        g_mutex_unlock (info->mutex); 
     4119 
     4120        g_mutex_free (info->mutex); 
     4121        g_cond_free (info->condition); 
     4122 
     4123        g_slice_free (GetFoldersInfo, info); 
    39824124 
    39834125        return NULL; 
     
    41054247        gint unread; 
    41064248        gint total; 
     4249 
     4250        GCond* condition; 
     4251        gboolean had_callback; 
     4252        GMutex *mutex; 
     4253 
    41074254} PokeStatusInfo; 
    41084255 
     
    41304277                notify_folder_observers_about (self, change); 
    41314278 
     4279 
    41324280        g_object_unref (change); 
    41334281 
     
    41414289 
    41424290        g_object_unref (info->self); 
    4143         g_slice_free (PokeStatusInfo, info); 
     4291 
     4292        g_mutex_lock (info->mutex); 
     4293        g_cond_broadcast (info->condition); 
     4294        info->had_callback = TRUE; 
     4295        g_mutex_unlock (info->mutex); 
    41444296} 
    41454297 
     
    41794331        { 
    41804332                info->self = TNY_FOLDER (g_object_ref (folder)); 
     4333 
     4334                info->mutex = g_mutex_new (); 
     4335                info->condition = g_cond_new (); 
     4336                info->had_callback = FALSE; 
     4337 
    41814338                g_idle_add_full (G_PRIORITY_HIGH,  
    41824339                        tny_camel_folder_poke_status_callback,  
    41834340                        info, tny_camel_folder_poke_status_destroyer); 
    4184         } 
     4341 
     4342 
     4343                /* Wait on the queue for the mainloop callback to be finished */ 
     4344                g_mutex_lock (info->mutex); 
     4345                if (!info->had_callback) 
     4346                        g_cond_wait (info->condition, info->mutex); 
     4347                g_mutex_unlock (info->mutex); 
     4348 
     4349                g_mutex_free (info->mutex); 
     4350                g_cond_free (info->condition); 
     4351 
     4352                g_slice_free (PokeStatusInfo, info); 
     4353 
     4354        } else if (info) 
     4355                g_slice_free (PokeStatusInfo, info); 
    41854356 
    41864357        /* Thread reference */ 
  • devel/pvanhoof/sessionwork/libtinymail-camel/tny-camel-store-account.c

    r2513 r2521  
    10901090        TnyFolderStoreQuery *query; 
    10911091        gpointer user_data; 
    1092         guint depth; TnySessionCamel *session; 
     1092        guint depth;  
     1093        TnySessionCamel *session; 
     1094 
     1095        GCond* condition; 
     1096        gboolean had_callback; 
     1097        GMutex *mutex; 
     1098 
    10931099} GetFoldersInfo; 
    10941100 
     
    11081114        _tny_session_stop_operation (info->session); 
    11091115 
    1110         g_slice_free (GetFoldersInfo, info); 
     1116 
     1117        g_mutex_lock (info->mutex); 
     1118        g_cond_broadcast (info->condition); 
     1119        info->had_callback = TRUE; 
     1120        g_mutex_unlock (info->mutex); 
    11111121 
    11121122        return; 
     
    11401150        if (info->query) 
    11411151                g_object_unref (G_OBJECT (info->query)); 
     1152 
     1153        info->mutex = g_mutex_new (); 
     1154        info->condition = g_cond_new (); 
     1155        info->had_callback = FALSE; 
    11421156 
    11431157        if (info->callback) 
     
    11571171        } 
    11581172 
    1159  
     1173        /* Wait on the queue for the mainloop callback to be finished */ 
     1174        g_mutex_lock (info->mutex); 
     1175        if (!info->had_callback) 
     1176                g_cond_wait (info->condition, info->mutex); 
     1177        g_mutex_unlock (info->mutex); 
     1178 
     1179        g_mutex_free (info->mutex); 
     1180        g_cond_free (info->condition); 
     1181 
     1182        g_slice_free (GetFoldersInfo, info); 
    11601183 
    11611184        return NULL;