added hold/release timeout for contacts sync 73/47073/3
authorJeesun Kim <iamjs.kim@samsung.com>
Fri, 31 Jul 2015 13:31:27 +0000 (22:31 +0900)
committerjeesun kim <iamjs.kim@samsung.com>
Fri, 4 Sep 2015 01:36:15 +0000 (18:36 -0700)
Change-Id: If5bfbcaa5e66c518473e26bb02a39af21496e254

common/cal_ondemand.c
server/cal_server_contacts.c

index a9b881f..406aac3 100644 (file)
  *
  */
 
+#include <pthread.h>
+
 #include "cal_internal.h"
 #include "cal_typedef.h"
 #include "cal_mutex.h"
 #include "cal_server.h"
 
+static pthread_mutex_t cal_mutex_timeout = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t cal_mutex_holding = PTHREAD_MUTEX_INITIALIZER;
 static guint cal_timeout_id = 0;
+static gboolean cal_holding = FALSE;
 
 void cal_ondemand_stop(void)
 {
        CAL_FN_CALL();
 
-       cal_mutex_lock(CAL_MUTEX_TIMEOUT);
+       pthread_mutex_lock(&cal_mutex_timeout);
        g_source_remove(cal_timeout_id);
        cal_timeout_id = 0;
-       cal_mutex_unlock(CAL_MUTEX_TIMEOUT);
+       pthread_mutex_unlock(&cal_mutex_timeout);
 }
 
 static gboolean _timeout_cb(gpointer user_data)
 {
-       DBG("exit");
-       cal_server_quit_loop();
+       pthread_mutex_lock(&cal_mutex_holding);
+       if (FALSE == cal_holding) {
+               DBG("exit");
+               cal_server_quit_loop();
+       }
+       pthread_mutex_unlock(&cal_mutex_holding);
        return TRUE;
 }
 
@@ -49,9 +58,23 @@ void cal_ondemand_start(void)
        if (timeout < 1)
                return;
 
-       cal_mutex_lock(CAL_MUTEX_TIMEOUT);
+       pthread_mutex_lock(&cal_mutex_timeout);
        if (cal_timeout_id > 0)
                g_source_remove(cal_timeout_id);
        cal_timeout_id = g_timeout_add_seconds(timeout, _timeout_cb, NULL);
-       cal_mutex_unlock(CAL_MUTEX_TIMEOUT);
+       pthread_mutex_unlock(&cal_mutex_timeout);
+}
+
+void cal_ondemand_hold(void)
+{
+       pthread_mutex_lock(&cal_mutex_holding);
+       cal_holding = TRUE;
+       pthread_mutex_unlock(&cal_mutex_holding);
+}
+
+void cal_ondemand_release(void)
+{
+       pthread_mutex_lock(&cal_mutex_holding);
+       cal_holding = FALSE;
+       pthread_mutex_unlock(&cal_mutex_holding);
 }
index fc55675..760e66d 100644 (file)
@@ -564,7 +564,7 @@ static gpointer _cal_server_contacts_sync_main(gpointer user_data)
                 * while syncing with contacts, calendar-service could be stopped by on-demand.
                 * so, on-demand timeout is stopped.
                 */
-               cal_ondemand_stop();
+               cal_ondemand_hold();
 
                ret = cal_connect();
                if (CALENDAR_ERROR_NONE != ret) {
@@ -587,6 +587,7 @@ static gpointer _cal_server_contacts_sync_main(gpointer user_data)
 
                g_mutex_lock(&_cal_server_contacts_sync_mutex);
                DBG("wait");
+               cal_ondemand_release();
                cal_ondemand_start();
                g_cond_wait(&_cal_server_contacts_sync_cond, &_cal_server_contacts_sync_mutex);
                g_mutex_unlock(&_cal_server_contacts_sync_mutex);