*
*/
+#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;
}
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);
}
* 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) {
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);