Changeset 3813
- Timestamp:
- 11/19/08 15:45:25
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
releases/modest/diablo-pe2/ChangeLog
r3812 r3813 1 1 2008-11-19 Sergio Villar Senin <svillar@igalia.com> 2 2 3 * libtinymail-camel/tny-camel-send-queue.c 4 * libtinymail-camel/tny-camel-send-queue-priv.c: 5 added some extra locking to prevent two send queue threads running 6 at the same time 7 3 8 * libtinymail-camel/tny-camel-mime-part.c 4 (tny_camel_mime_part_decode_to_stream_default): 9 (tny_camel_mime_part_decode_to_stream_default): 5 10 adds a reference to protect wrapper when decoding to a stream 6 11 releases/modest/diablo-pe2/libtinymail-camel/tny-camel-send-queue-priv.h
r3439 r3813 37 37 gboolean observer_attached; 38 38 gint pending_send_notifies; 39 GStaticMutex *running_lock; 39 40 }; 40 41 releases/modest/diablo-pe2/libtinymail-camel/tny-camel-send-queue.c
r3667 r3813 69 69 gint i, total; 70 70 guint signal_id; 71 GCond *condition; 72 GMutex *mutex; 73 gboolean had_callback; 71 74 } ControlInfo; 72 75 … … 309 312 tny_lockable_unlock (apriv->session->priv->ui_lock); 310 313 314 if (info->mutex) { 315 g_mutex_lock (info->mutex); 316 g_cond_broadcast (info->condition); 317 info->had_callback = TRUE; 318 g_mutex_unlock (info->mutex); 319 } 320 311 321 return FALSE; 312 322 } … … 568 578 } 569 579 580 static void 581 wait_for_queue_start_notification (TnySendQueue *self) 582 { 583 ControlInfo *info = g_slice_new0 (ControlInfo); 584 585 info->mutex = g_mutex_new (); 586 info->condition = g_cond_new (); 587 info->had_callback = FALSE; 588 589 info->self = g_object_ref (self); 590 info->signal_id = TNY_SEND_QUEUE_START; 591 592 g_idle_add (emit_queue_control_signals_on_mainloop, info); 593 594 g_mutex_lock (info->mutex); 595 if (!info->had_callback) 596 g_cond_wait (info->condition, info->mutex); 597 g_mutex_unlock (info->mutex); 598 599 g_mutex_free (info->mutex); 600 g_cond_free (info->condition); 601 602 g_slice_free (GetHeadersSync, info); 603 } 604 605 570 606 static gpointer 571 607 thread_main (gpointer data) … … 579 615 GHashTable *failed_headers = NULL; 580 616 581 priv->is_running = TRUE; 617 /* Wait here until the user receives the queue-start notification */ 618 wait_for_queue_start_notification (self); 619 582 620 list = tny_simple_list_new (); 583 621 … … 622 660 get_headers_sync (info->outbox, headers, TRUE, &ferror); 623 661 else { 624 priv->is_running = FALSE;625 662 g_static_rec_mutex_unlock (priv->todo_lock); 626 663 g_static_rec_mutex_unlock (priv->sending_lock); … … 630 667 if (ferror != NULL) 631 668 { 632 priv->is_running = FALSE;633 669 emit_error (self, NULL, NULL, ferror, i, priv->total); 634 670 g_error_free (ferror); … … 677 713 if (length <= 0) 678 714 { 679 priv->is_running = FALSE;680 715 g_object_unref (headers); 681 716 g_static_rec_mutex_unlock (priv->todo_lock); … … 766 801 } else 767 802 { 768 priv->is_running = FALSE;769 803 /* Not good, or we just went offline, let's just kill this thread */ 770 804 length = 0; … … 784 818 errorhandler: 785 819 786 priv->is_running = FALSE;787 788 820 if (failed_headers) 789 821 g_hash_table_destroy (failed_headers); … … 815 847 g_slice_free (MainThreadInfo, info); 816 848 849 g_static_mutex_lock (priv->running_lock); 850 priv->is_running = FALSE; 851 g_static_mutex_unlock (priv->running_lock); 852 817 853 /* Emit the queue-stop signal */ 818 854 emit_queue_control_signals (self, TNY_SEND_QUEUE_STOP); … … 828 864 TnyCamelSendQueuePriv *priv = TNY_CAMEL_SEND_QUEUE_GET_PRIVATE (self); 829 865 866 g_static_mutex_lock (priv->running_lock); 830 867 if (!priv->is_running && priv->trans_account && TNY_IS_TRANSPORT_ACCOUNT (priv->trans_account)) 831 868 { … … 872 909 } 873 910 874 emit_queue_control_signals (self, TNY_SEND_QUEUE_START); 875 911 priv->is_running = TRUE; 876 912 priv->thread = g_thread_create (thread_main, info, FALSE, NULL); 877 913 878 914 if (priv->thread == NULL) { 879 emit_queue_control_signals (self, TNY_SEND_QUEUE_STOP); 915 GError *error; 916 917 priv->is_running = FALSE; 918 919 g_set_error (err, TNY_SYSTEM_ERROR, 920 TNY_SYSTEM_ERROR_UNKNOWN, 921 "Couldn't start thread for send queue"); 922 emit_error (self, NULL, NULL, error, 0, 0); 923 880 924 if (TNY_IS_CAMEL_FOLDER (info->outbox)) { 881 925 TnyCamelFolderPriv *opriv = TNY_CAMEL_FOLDER_GET_PRIVATE (info->outbox); … … 889 933 } 890 934 } 935 g_static_mutex_unlock (priv->running_lock); 891 936 892 937 return; … … 910 955 g_static_rec_mutex_lock (priv->sending_lock); 911 956 957 g_static_mutex_lock (priv->running_lock); 912 958 priv->is_running = FALSE; 959 g_static_mutex_unlock (priv->running_lock); 913 960 914 961 outbox = tny_send_queue_get_outbox (self); … … 992 1039 priv->total++; 993 1040 994 if (!err & !priv->is_running)1041 if (!err) 995 1042 create_worker (info->self, &new_err); 996 1043 … … 1271 1318 priv->sending_lock = NULL; 1272 1319 1320 g_free (priv->running_lock); 1321 priv->running_lock = NULL; 1322 1273 1323 g_object_unref (priv->trans_account); 1274 1324 … … 1442 1492 priv->sending_lock = g_new0 (GStaticRecMutex, 1); 1443 1493 g_static_rec_mutex_init (priv->sending_lock); 1494 priv->running_lock = g_new0 (GStaticMutex, 1); 1495 g_static_mutex_init (priv->running_lock); 1444 1496 1445 1497 priv->is_running = FALSE;
