summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeongmo Yang <jm80.yang@samsung.com>2016-11-24 10:15:30 +0900
committerJeongmo Yang <jm80.yang@samsung.com>2016-11-24 10:15:51 +0900
commitb0e77e4042b9b06161a3f84d2645eb967ff59a8d (patch)
tree481333e20c6ea1e3ed99cac0289002c942a29a12
parent5eb594d5dd5fd49f154a8d03b9f309b16882f945 (diff)
parent0afb671a114e63fe69f00ac5778e31f629b9d67c (diff)
downloadlibmm-common-b0e77e4042b9b06161a3f84d2645eb967ff59a8d.tar.gz
libmm-common-b0e77e4042b9b06161a3f84d2645eb967ff59a8d.tar.bz2
libmm-common-b0e77e4042b9b06161a3f84d2645eb967ff59a8d.zip
Change-Id: I6656234fde722d13ad61f32dfead86f8db7e07eb
-rw-r--r--include/mm_attrs_private.h6
-rw-r--r--mm_attrs.c21
-rw-r--r--mm_attrs_private.c91
-rw-r--r--packaging/libmm-common.spec2
4 files changed, 61 insertions, 59 deletions
diff --git a/include/mm_attrs_private.h b/include/mm_attrs_private.h
index e9c1093..a303168 100644
--- a/include/mm_attrs_private.h
+++ b/include/mm_attrs_private.h
@@ -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 {
diff --git a/mm_attrs.c b/mm_attrs.c
index be935a3..fefd2d9 100644
--- a/mm_attrs.c
+++ b/mm_attrs.c
@@ -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;
}
diff --git a/mm_attrs_private.c b/mm_attrs_private.c
index 9c8df67..f239b05 100644
--- a/mm_attrs_private.c
+++ b/mm_attrs_private.c
@@ -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;
}
diff --git a/packaging/libmm-common.spec b/packaging/libmm-common.spec
index a31655e..b1d7d38 100644
--- a/packaging/libmm-common.spec
+++ b/packaging/libmm-common.spec
@@ -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