last_result = false; \
} while (0)
+#define VCONF_CTOR __attribute__((constructor))
+#define VCONF_DTOR __attribute__((destructor))
+
static void _vconf_restore_noti_cb(gpointer key, gpointer value, gpointer user_data);
static void _vconf_con_close(void);
static gboolean _vconf_call_noti_cb(gpointer data);
-static pthread_mutex_t vconf_lock = PTHREAD_MUTEX_INITIALIZER;
+static GRecMutex vconf_mutex;
static int _refcnt;
static struct buxton_client *client;
static struct buxton_layer *system_layer;
static struct noti_cb *_vconf_find_noti_cb(struct noti *noti, vconf_callback_fn cb);
static void _vconf_to_vconf_t(const struct buxton_value *val, keynode_t *node);
+static void _vconf_mutex_lock(void)
+{
+ g_rec_mutex_lock(&vconf_mutex);
+}
+
+static void _vconf_mutex_unlock(void)
+{
+ g_rec_mutex_unlock(&vconf_mutex);
+}
+
static GSource *_vconf_idle_add_full(GMainContext *context, guint priority, GSourceFunc func,
gpointer data)
{
return cb_info;
}
-__attribute__((destructor))
-static void _vconf_finish(void)
+VCONF_CTOR static void _vconf_init(void)
+{
+ g_rec_mutex_init(&vconf_mutex);
+}
+
+VCONF_DTOR static void _vconf_finish(void)
{
/* force close */
if (_refcnt > 0) {
if (gsource_tbl)
g_hash_table_remove_all(gsource_tbl);
+
+ if (g_rec_mutex_trylock(&vconf_mutex))
+ g_rec_mutex_unlock(&vconf_mutex);
+
+ g_rec_mutex_clear(&vconf_mutex);
}
EXPORT char *vconf_keynode_get_name(keynode_t *keynode)
return;
/* LCOV_EXCL_START */
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
if (!noti_tbl) {
_refcnt = 0;
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return;
}
if (r != 0) {
_refcnt = 0;
LOGE("Can't connect to buxton: %d", buxton_err_get_errno());
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return;
}
g_hash_table_foreach(noti_tbl, (GHFunc)_vconf_restore_noti_cb, NULL);
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
/* LCOV_EXCL_STOP */
}
cb_info->source = NULL;
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
noti = g_hash_table_lookup(noti_tbl, node->keyname);
if (!noti) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
g_hash_table_remove(gsource_tbl, GINT_TO_POINTER(cb_info->id));
return G_SOURCE_REMOVE;
}
if (!_vconf_find_noti_cb(noti, noticb->cb)) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
g_hash_table_remove(gsource_tbl, GINT_TO_POINTER(cb_info->id));
return G_SOURCE_REMOVE;
}
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
noticb->cb(node, noticb->user_data);
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
g_hash_table_remove(gsource_tbl, GINT_TO_POINTER(cb_info->id));
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return G_SOURCE_REMOVE;
}
struct noti* noti;
GList *iter;
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
noti = g_hash_table_lookup(noti_tbl, key);
if (!noti) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return;
}
noticb = iter->data;
cb_info = _vconf_create_callback_info(key, val, noticb);
if (!cb_info) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return;
}
g_hash_table_insert(gsource_tbl, GINT_TO_POINTER(cb_info->id),
cb_info);
}
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
}
static struct noti_cb *_vconf_find_noti_cb(struct noti *noti, vconf_callback_fn cb)
return -1;
}
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
r = _vconf_create_noti(key, cb, user_data, ¬i);
if (r != 0) {
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
}
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
if (r != 0) {
VCONF_SET_ERRNO(r);
return -1;
}
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
noti = g_hash_table_lookup(noti_tbl, key);
if (!noti) {
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(ENOENT);
return -1;
}
noticb = _vconf_find_noti_cb(noti, cb);
if (!noticb || !noticb->active) {
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(ENOENT);
return -1;
}
if (cnt > 0) {
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return 0;
}
/* decrease reference count */
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return 0;
}
{
int r;
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return r;
}
}
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return r;
}
int r;
struct buxton_value *v;
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return r;
}
}
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return r;
}
return -1;
}
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
r = buxton_err_get_errno();
LOGE("get key list: errno %d", r);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
buxton_free_keys(names);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return 0;
}
return -1;
}
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
r = buxton_unset_value_sync(client, _vconf_get_layer(in_key), in_key);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
if (r != 0) {
r = buxton_err_get_errno();
return -1;
}
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
r = buxton_err_get_errno();
LOGE("get key list: errno %d", r);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
if (strncmp(in_dir, names[i], dirlen))
continue;
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
r = vconf_unset(names[i]);
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
if (r != 0) {
buxton_free_keys(names);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
return -1;
}
}
buxton_free_keys(names);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
/* LCOV_EXCL_STOP */
return 0;
return -1;
}
- pthread_mutex_lock(&vconf_lock);
+ _vconf_mutex_lock();
r = _vconf_con_open();
if (r != 0) {
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
VCONF_SET_ERRNO(r);
return -1;
}
r = buxton_get_value_sync(client, _vconf_get_layer(in_key), in_key, &v);
_vconf_con_close();
- pthread_mutex_unlock(&vconf_lock);
+ _vconf_mutex_unlock();
if (r != 0) {
r = buxton_err_get_errno();