Move write_lock from attrs to each attribute 82/99482/1 accepted/tizen/common/20161129.173533 accepted/tizen/ivi/20161130.015411 accepted/tizen/mobile/20161130.015154 accepted/tizen/tv/20161130.015239 accepted/tizen/wearable/20161130.015327 submit/tizen/20161129.052917
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 23 Nov 2016 04:46:41 +0000 (13:46 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 23 Nov 2016 04:46:41 +0000 (13:46 +0900)
Previously, a common write_lock is used for set_attribute and get_attribute of string type.
So, get_attribute function for string type should wait if some set_attribute function is working although it's not related each other.
This commit removes a common write lock and add each write_locks to attribute,
then lock dependencies are removed among each attributes.

[Version] 0.2.98
[Profile] Common
[Issue Type] Update
[Dependency module] N/A
[Test] [M(T) - Boot=(OK), sdb=(OK), Home=(OK), Touch=(OK), Version=tizen-3.0-mobile_20161122.5]

Change-Id: I3e11ace7200fd02ea4f05828b5ef5c116b15bbe5
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
include/mm_attrs_private.h
mm_attrs.c
mm_attrs_private.c
packaging/libmm-common.spec

index e9c1093..a303168 100644 (file)
@@ -42,8 +42,8 @@
                (t) == MMF_VALUE_SPEC_DOUBLE_ARRAY || \
                (t) == MMF_VALUE_SPEC_DOUBLE_RANGE)
 
-#define MM_ATTRS_WRITE_LOCK(attrs)             do { pthread_mutex_lock(&attrs->write_lock); } while (0)
-#define MM_ATTRS_WRITE_UNLOCK(attrs)   do { pthread_mutex_unlock(&attrs->write_lock); } while (0)
+#define MM_ATTR_ITEM_WRITE_LOCK(item)  do { pthread_mutex_lock(&item->write_lock); } while (0)
+#define MM_ATTR_ITEM_WRITE_UNLOCK(item)        do { pthread_mutex_unlock(&item->write_lock); } while (0)
 
 enum mmf_value_type {
        MMF_VALUE_TYPE_INT = MM_ATTRS_TYPE_INT,
@@ -122,6 +122,7 @@ struct mmf_attribute {
        mmf_value_t value;
        mmf_value_t tmpval;
        mmf_value_spec_t value_spec;
+       pthread_mutex_t write_lock;
 };
 
 struct mmf_attrs {
@@ -130,7 +131,6 @@ struct mmf_attrs {
        mmf_attribute_t *items;
        mmf_attrs_commit_func_t commit_func;
        void *commit_param;
-       pthread_mutex_t write_lock;
 };
 
 struct mmf_attrs_list {
index be935a3..fefd2d9 100644 (file)
@@ -227,18 +227,18 @@ int mm_attrs_set_string(MMHandleType h, int idx, const char *string, int size)
        mmf_attrs_t *attrs = (mmf_attrs_t *) h;
        return_val_if_fail(attrs && idx >= 0 && idx < attrs->count, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
-               mmf_attribute_t *item = &attrs->items[idx];
+       mmf_attribute_t *item = &attrs->items[idx];
 
        return_val_if_fail(item, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
-       MM_ATTRS_WRITE_LOCK(attrs);
+       MM_ATTR_ITEM_WRITE_LOCK(item);
 
        if (mmf_attribute_check_flags(item, MM_ATTRS_FLAG_WRITABLE))
        {
                int ret = 0;
                ret = mmf_attribute_set_string(item, string, size);
 
-               MM_ATTRS_WRITE_UNLOCK(attrs);
+               MM_ATTR_ITEM_WRITE_UNLOCK(item);
 
                if (ret == 0)
                        return MM_ERROR_NONE;
@@ -246,7 +246,7 @@ int mm_attrs_set_string(MMHandleType h, int idx, const char *string, int size)
                        return MM_ERROR_COMMON_INVALID_ARGUMENT;
        }
 
-       MM_ATTRS_WRITE_UNLOCK(attrs);
+       MM_ATTR_ITEM_WRITE_UNLOCK(item);
 
        return MM_ERROR_COMMON_INVALID_PERMISSION;
 }
@@ -255,19 +255,22 @@ int mm_attrs_set_string(MMHandleType h, int idx, const char *string, int size)
 int mm_attrs_get_string(MMHandleType h, int idx, char **sval, int *size)
 {
        mmf_attrs_t *attrs = (mmf_attrs_t *) h;
+       mmf_attribute_t *item = NULL;
        return_val_if_fail(attrs && idx >= 0 && idx < attrs->count && sval, MM_ERROR_COMMON_INVALID_ARGUMENT);
 
-       MM_ATTRS_WRITE_LOCK(attrs);
+       item = &attrs->items[idx];
 
-       if (!(attrs->items[idx].flags & MM_ATTRS_FLAG_READABLE)) {
+       MM_ATTR_ITEM_WRITE_LOCK(item);
+
+       if (!(item->flags & MM_ATTRS_FLAG_READABLE)) {
                //mmf_debug(MMF_DEBUG_LOG, "Access denied.\n");
-               MM_ATTRS_WRITE_UNLOCK(attrs);
+               MM_ATTR_ITEM_WRITE_UNLOCK(item);
                return MM_ERROR_COMMON_INVALID_PERMISSION;
        }
 
-       *sval = mmf_value_get_string(&attrs->items[idx].value,size);
+       *sval = mmf_value_get_string(&item->value, size);
 
-       MM_ATTRS_WRITE_UNLOCK(attrs);
+       MM_ATTR_ITEM_WRITE_UNLOCK(item);
 
        return MM_ERROR_NONE;
 }
index 9c8df67..f239b05 100644 (file)
@@ -415,6 +415,7 @@ void mmf_attribute_clear(mmf_attribute_t *item)
        mmf_value_clear(&item->tmpval);
        mmf_value_clear(&item->value);
        mmf_value_spec_clear(&item->value_spec);
+       pthread_mutex_destroy(&item->write_lock);
 }
 
 bool mmf_attribute_is_modified(mmf_attribute_t *item)
@@ -526,19 +527,6 @@ MMHandleType mmf_attrs_new(int count)
 
        memset(attrs->items, 0, sizeof(mmf_attribute_t) * count);
 
-       if (pthread_mutex_init(&attrs->write_lock, NULL) != 0) {
-               //mmf_debug(MMF_DEBUG_ERROR, "mutex init failed");
-               if (attrs) {
-                       if (attrs->items) {
-                               free(attrs->items);
-                               attrs->items = NULL;
-                       }
-                       free(attrs);
-                       attrs=NULL;
-               }
-               return 0;
-       }
-
        return (MMHandleType) attrs;
 }
 
@@ -583,7 +571,6 @@ void mmf_attrs_free(MMHandleType h)
                        free(attrs->items);
                        attrs->items = NULL;
                }
-               pthread_mutex_destroy(&attrs->write_lock);
                free(attrs);
        }
 }
@@ -592,43 +579,48 @@ int mmf_attrs_init(MMHandleType h, mmf_attrs_construct_info_t *info, int count)
 {
        return_val_if_fail(h && info && count > 0, -1);
        mmf_attrs_t *attrs = (mmf_attrs_t *) h;
+       mmf_attribute_t *item = NULL;
        int i;
        int size = 0;
 
        for (i = 0; i < count; i++) {
-               mmf_attribute_init(&attrs->items[i],
+               item = &attrs->items[i];
+
+               pthread_mutex_init(&item->write_lock, NULL);
+
+               mmf_attribute_init(item,
                                   info[i].name,
                                   info[i].value_type,
                                   info[i].flags);
 
                switch (info[i].value_type) {
                case MMF_VALUE_TYPE_INT:
-                       assert(attrs->items[i].value.value.i_val == 0);
-                       mmf_value_set_int(&attrs->items[i].value,
+                       assert(item->value.value.i_val == 0);
+                       mmf_value_set_int(&item->value,
                                          (intptr_t)info[i].default_value);
                        break;
                case MMF_VALUE_TYPE_DOUBLE:
                {
                        int i_val = (intptr_t)info[i].default_value;
                        double d_val = (double) i_val;
-                       assert(attrs->items[i].value.value.d_val == 0);
-                       mmf_value_set_double(&attrs->items[i].value, d_val);
+                       assert(item->value.value.d_val == 0);
+                       mmf_value_set_double(&item->value, d_val);
                        break;
                }
                case MMF_VALUE_TYPE_STRING:
-                       assert(attrs->items[i].value.value.s_val == NULL);
+                       assert(item->value.value.s_val == NULL);
                        if (info[i].default_value) {
                                size = strlen(info[i].default_value)+1;
                        }
-                       mmf_value_set_string(&attrs->items[i].value,
+                       mmf_value_set_string(&item->value,
                                             (const char *)info[i].default_value,size);
                        break;
                case MMF_VALUE_TYPE_DATA:
-                       assert(attrs->items[i].value.value.p_val == NULL);
+                       assert(item->value.value.p_val == NULL);
                        if (info[i].default_value) {
                                size = sizeof(info[i].default_value)+1;
                        }
-                       mmf_value_set_data(&attrs->items[i].value, info[i].default_value,size);
+                       mmf_value_set_data(&item->value, info[i].default_value,size);
                        break;
                default:
                        //mmf_debug(MMF_DEBUG_LOG, "ERROR: Invalid MMF_VALUE_TYPE\n");
@@ -645,31 +637,34 @@ int mmf_attrs_commit(MMHandleType h)
        return_val_if_fail(h, -1);
 
        mmf_attrs_t *attrs = (mmf_attrs_t * )h;
+       mmf_attribute_t *item = NULL;
        int i;
        int ret = 0;
 
-       MM_ATTRS_WRITE_LOCK(attrs);
-
        for (i = 0; i < attrs->count; ++i) {
-               if (mmf_attribute_is_modified(&attrs->items[i])) {
+               item = &attrs->items[i];
+
+               MM_ATTR_ITEM_WRITE_LOCK(item);
+
+               if (mmf_attribute_is_modified(item)) {
                        if (attrs->commit_func) {
-                               if (attrs->commit_func(i, attrs->items[i].name,
-                                                                               &attrs->items[i].tmpval,
+                               if (attrs->commit_func(i, item->name,
+                                                                               &item->tmpval,
                                                                                attrs->commit_param)) {
-                                       mmf_attribute_commit(&attrs->items[i]);
+                                       mmf_attribute_commit(item);
                                } else {
                                        /* without this, there is no way to solve modify when commit_func failed. */
-                                       if (attrs->items[i].flags & MM_ATTRS_FLAG_MODIFIED)
-                                               attrs->items[i].flags ^= MM_ATTRS_FLAG_MODIFIED;
+                                       if (item->flags & MM_ATTRS_FLAG_MODIFIED)
+                                               item->flags ^= MM_ATTRS_FLAG_MODIFIED;
                                        ret = -1;
                                }
                        } else {
-                               mmf_attribute_commit(&attrs->items[i]);
+                               mmf_attribute_commit(item);
                        }
                }
-       }
 
-       MM_ATTRS_WRITE_UNLOCK(attrs);
+               MM_ATTR_ITEM_WRITE_UNLOCK(item);
+       }
 
        return ret;
 }
@@ -677,39 +672,43 @@ int mmf_attrs_commit(MMHandleType h)
 int mmf_attrs_commit_err(MMHandleType h, char **err_attr_name)
 {
        mmf_attrs_t *attrs = (mmf_attrs_t * )h;
+       mmf_attribute_t *item = NULL;
        int i;
        int ret = 0;
 
        return_val_if_fail(h, -1);
 
-       MM_ATTRS_WRITE_LOCK(attrs);
-
        for (i = 0; i < attrs->count; ++i) {
-               if (mmf_attribute_is_modified(&attrs->items[i])) {
+               item = &attrs->items[i];
+
+               MM_ATTR_ITEM_WRITE_LOCK(item);
+
+               if (mmf_attribute_is_modified(item)) {
                        if (attrs->commit_func) {
-                               if (attrs->commit_func(i, attrs->items[i].name,
-                                                                               &attrs->items[i].tmpval,
+                               if (attrs->commit_func(i, item->name,
+                                                                               &item->tmpval,
                                                                                attrs->commit_param)) {
-                                       mmf_attribute_commit(&attrs->items[i]);
+                                       mmf_attribute_commit(item);
                                } else {
                                        /* without this, there is no way to solve modify when commit_func failed. */
-                                       if (attrs->items[i].flags & MM_ATTRS_FLAG_MODIFIED)
-                                               attrs->items[i].flags ^= MM_ATTRS_FLAG_MODIFIED;
+                                       if (item->flags & MM_ATTRS_FLAG_MODIFIED)
+                                               item->flags ^= MM_ATTRS_FLAG_MODIFIED;
                                        ret = -1;
 
                                        /* Set Error information */
                                        if (err_attr_name)
-                                               *err_attr_name = strdup(attrs->items[i].name);
+                                               *err_attr_name = strdup(item->name);
 
+                                       MM_ATTR_ITEM_WRITE_UNLOCK(item);
                                        break;
                                }
                        } else {
-                               mmf_attribute_commit(&attrs->items[i]);
+                               mmf_attribute_commit(item);
                        }
                }
-       }
 
-       MM_ATTRS_WRITE_UNLOCK(attrs);
+               MM_ATTR_ITEM_WRITE_UNLOCK(item);
+       }
 
        return ret;
 }
index a31655e..b1d7d38 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmm-common
 Summary:    Multimedia Framework Common Lib
-Version:    0.2.97
+Version:    0.2.98
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0