Resolve empty message of forking when glib debug enabled 44/199544/5 accepted/tizen/unified/20190325.070934 submit/tizen/20190322.043412 submit/tizen/20190322.112426
authorYoungHun Kim <yh8004.kim@samsung.com>
Wed, 13 Feb 2019 01:44:12 +0000 (10:44 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Fri, 15 Mar 2019 10:42:39 +0000 (19:42 +0900)
 - Change the time to close pipe of forking by EPIPE
 - Change the mutex pair of resource handle

Change-Id: Id2764bc8bf9cd6332c3f31c91d8e19c0ffcb4f3e

packaging/mm-resource-manager.spec
src/common/mm_resource_manager_utils.h
src/daemon/backend/murphy/mm_resource_manager_mloop.c
src/daemon/backend/murphy/mm_resource_manager_rset.c
src/daemon/mm_resource_manager_daemon.c
src/daemon/mm_resource_manager_daemon_dbus.c
src/daemon/mm_resource_manager_daemon_dbus.h
src/daemon/mm_resource_manager_daemon_priv.c
src/lib/mm_resource_manager_priv.c

index 5a5f908..42dcff6 100644 (file)
@@ -1,6 +1,6 @@
 Name:       mm-resource-manager
 Summary:    A Multimedia Resource Manager API
-Version:    0.2.13
+Version:    0.2.14
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index 0550767..b7d5d07 100644 (file)
                }                                                           \
        } while (0)
 
+#define MM_RM_UNLOCK2_RETVM_IF(expr, mtx, mtx2, val, fmt, arg...)          \
+       do {                                                            \
+               if (expr) {                                                 \
+                       LOGE(FONT_COLOR_RED""fmt""FONT_COLOR_RESET, ##arg);     \
+                       g_mutex_unlock(&mtx);                                   \
+                       g_mutex_unlock(&mtx2);                                   \
+                       return(val);                                            \
+               }                                                           \
+       } while (0)
+
 #define MM_RM_RETM_IF_E(expr, fmt, arg...)                          \
        do {                                                            \
                int err = expr;                                             \
index 98deb9f..f697454 100644 (file)
  * limitations under the License.
  */
 
-#include <glib.h>
-#include <murphy/common/mainloop.h>
 #include <murphy/common/glib-glue.h>
-#include <murphy/plugins/resource-native/libmurphy-resource/resource-api.h>
-
 #include "lib/mm_resource_manager.h"
-#include "common/mm_resource_manager_utils.h"
+#include "daemon/mm_resource_manager_daemon_dbus.h"
 #include "daemon/backend/murphy/mm_resource_manager_mloop.h"
 
 static void __mm_resource_manager_mloop_state_callback(mrp_res_context_t *context,
@@ -107,6 +103,8 @@ int _mm_resource_manager_mloop_create(mm_resource_manager_mloop_s **mrp)
 
        *mrp = handle;
 
+       _mmrm_dmn_notify_fork_done();
+
        MM_RM_INFO("Successfully performed mloop create");
 
        return ret;
@@ -139,10 +137,12 @@ int _mm_resource_manager_mloop_destroy(mm_resource_manager_mloop_s *mrp)
                g_main_loop_unref(mrp->m_loop);
        }
 
-       MM_RM_DEBUG("Joining worker thread...");
-       g_thread_join(mrp->worker);
-       MM_RM_DEBUG("Joined to worker thread");
-       mrp->worker = NULL;
+       if (mrp->worker) {
+               MM_RM_DEBUG("Joining worker thread...");
+               g_thread_join(mrp->worker);
+               mrp->worker = NULL;
+               MM_RM_DEBUG("Joined to worker thread");
+       }
 
        g_mutex_unlock(&mrp->lock);
 
index d453800..0e2d511 100644 (file)
@@ -272,8 +272,7 @@ static void _mm_resource_manager_rset_state_callback(mrp_res_context_t *cx, cons
        for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
                res = mrp_res_get_resource_by_name(rs, _mm_resource_manager_get_res_str(i));
                if (res == NULL)
-                       MM_RM_INFO(" -- %s not present in resource set",
-                                       _mm_resource_manager_get_res_str(i));
+                       MM_RM_INFO(" -- %s not present in resource set", _mm_resource_manager_get_res_str(i));
                else
                        MM_RM_INFO(" -- resource name [%s] -> [%s]'", res->name, state_str[res->state]);
        }
index 762f4ed..12b7782 100644 (file)
@@ -47,7 +47,7 @@ typedef enum {
 
 static GMainLoop *main_loop;
 static gboolean restart = FALSE;
-int notify_fd;
+int notify_fd[2];
 
 
 static gboolean fork_wait(void);
@@ -78,12 +78,12 @@ static gboolean fork_wait(void)
        MM_RM_RETVM_IF((pid = fork()) < 0, FALSE, "Daemon fork failed");
 
        if (pid != 0) {
-               close(fds[1]);
                /* Read in a string from the pipe */
                MM_RM_RETVM_IF(read(fds[0], msg, sizeof(msg)) < 0,
                        FALSE, "Failed to create pipe to get child status");
 
                close(fds[0]);
+               close(fds[1]);
 
                /* Parent process closes up output side of pipe */
                if (!strcmp(msg, MSG_DONE)) {
@@ -95,9 +95,8 @@ static gboolean fork_wait(void)
                }
        } else if (pid == 0) {
                /* Child process closes up input side of pipe */
-               close(fds[0]);
-
-               notify_fd = fds[1];
+               notify_fd[0] = fds[0];
+               notify_fd[1] = fds[1];
        }
 
        return TRUE;
index 9169a24..cc54c1d 100755 (executable)
 
 static MMResourceManager *interface;
 
-extern int notify_fd;
+extern int notify_fd[2];
 
 static void __gv2c_array(GVariantIter *gv, mm_resource_manager_dmn_res_request_s **c);
-static void _notify_fork_done(void);
+static gboolean on_get_conf(MMResourceManager *interface,
+               GDBusMethodInvocation *invocation, gpointer user_data);
 static gboolean on_create_handle(MMResourceManager *interface,
                GDBusMethodInvocation *invocation, const gint app_class,
                gpointer user_data);
@@ -47,6 +48,12 @@ int _mmrm_dmn_dbus_init()
        MM_RM_RETVM_IF(interface == NULL,
                        MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION,
                        "Interface cannot be created");
+
+       g_signal_connect(interface, "handle-conf", G_CALLBACK(on_get_conf), NULL);
+       g_signal_connect(interface, "handle-create", G_CALLBACK(on_create_handle), NULL);
+       g_signal_connect(interface, "handle-destroy", G_CALLBACK(on_destroy_handle), NULL);
+       g_signal_connect(interface, "handle-commit", G_CALLBACK(on_commit_handle), NULL);
+
        g_bus_own_name(G_BUS_TYPE_SYSTEM, RMD_GDBUS_NAME,
                        G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL, NULL, NULL,
                        NULL);
@@ -68,6 +75,11 @@ int _mmrm_dmn_dbus_get_conf(mm_resource_manager_res_volume **max_volume,
        mm_resource_manager_conf_s *conf;
 
        conf = mm_resource_manager_get_conf();
+
+       MM_RM_RETVM_IF(conf == NULL,
+                       MM_RESOURCE_MANAGER_ERROR_INVALID_OPERATION,
+                       "mm_resource_manager_conf is NULL");
+
        *max_volume = conf->max_volume;
        *cond_volume = &conf->condition_volume;
 
@@ -130,7 +142,16 @@ int _mmrm_dmn_dbus_status_callback(mm_resource_manager_status_e status)
        return MM_RESOURCE_MANAGER_ERROR_NONE;
 }
 
+void _mmrm_dmn_notify_fork_done(void)
+{
+       /* Send "string" through the output side of pipe */
+       MM_RM_RETM_IF(write(notify_fd[1], MSG_DONE, strlen(MSG_DONE) + 1) < 0,
+               "Failed to notify parent process that child initialization is done");
 
+       MM_RM_DEBUG("[%d] Notify parent process that child initialization is done", notify_fd[1]);
+       close(notify_fd[0]);
+       close(notify_fd[1]);
+}
 
 static void __gv2c_array(GVariantIter *gv, mm_resource_manager_dmn_res_request_s **c)
 {
@@ -145,23 +166,13 @@ static void __gv2c_array(GVariantIter *gv, mm_resource_manager_dmn_res_request_s
        *c = rs;
 }
 
-void _notify_fork_done(void)
-{
-       /* Send "string" through the output side of pipe */
-       MM_RM_RETM_IF(write(notify_fd, MSG_DONE, strlen(MSG_DONE) + 1) < 0,
-               "Failed to notify parent process that child initialization is done");
-
-       MM_RM_DEBUG("[%d] Notify parent process that child initialization is done", notify_fd);
-       close(notify_fd);
-}
-
 static gboolean on_get_conf(MMResourceManager *interface,
                GDBusMethodInvocation *invocation, gpointer user_data)
 {
        int i, j;
        gint error = 0;
-       mm_resource_manager_res_volume *max_volume;
-       mm_resource_manager_condition_volume_a *cond_volume;
+       mm_resource_manager_res_volume *max_volume = NULL;
+       mm_resource_manager_condition_volume_a *cond_volume = NULL;
        GVariantBuilder *res_type_builder;
        GVariantBuilder *res_cond_builder;
        GVariant *res_type_conf;
@@ -170,29 +181,25 @@ static gboolean on_get_conf(MMResourceManager *interface,
        error = _mmrm_dmn_dbus_get_conf(&max_volume, &cond_volume);
 
        res_type_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-       for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
-               g_variant_builder_add_value(res_type_builder,
-                               g_variant_new("i", max_volume[i]));
-       }
+       for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++)
+               g_variant_builder_add_value(res_type_builder, g_variant_new("i", max_volume[i]));
+
        res_type_conf = g_variant_builder_end(res_type_builder);
        g_variant_builder_unref(res_type_builder);
 
        res_type_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
        for (i = 0; i < MM_RESOURCE_MANAGER_RES_TYPE_MAX; i++) {
                res_cond_builder = g_variant_builder_new(G_VARIANT_TYPE_ARRAY);
-               for (j = 0; j < MM_RESOURCE_MANAGER_RES_TYPE_COND_MAX; j++) {
-                       g_variant_builder_add_value(res_cond_builder,
-                                       g_variant_new("i", cond_volume[i][j]));
-               }
-               g_variant_builder_add_value(res_type_builder,
-                               g_variant_builder_end(res_cond_builder));
+               for (j = 0; j < MM_RESOURCE_MANAGER_RES_TYPE_COND_MAX; j++)
+                       g_variant_builder_add_value(res_cond_builder, g_variant_new("i", cond_volume[i][j]));
+
+               g_variant_builder_add_value(res_type_builder, g_variant_builder_end(res_cond_builder));
                g_variant_builder_unref(res_cond_builder);
        }
        res_cond_conf = g_variant_builder_end(res_type_builder);
        g_variant_builder_unref(res_type_builder);
 
-       mmresource_manager_complete_conf(interface, invocation, error,
-                       res_type_conf, res_cond_conf);
+       mmresource_manager_complete_conf(interface, invocation, error, res_type_conf, res_cond_conf);
 
        return TRUE;
 }
@@ -250,8 +257,7 @@ static gboolean on_commit_handle(MMResourceManager *interface,
        for (i = 0; i < acquire_len; i++)
                g_variant_builder_add_value(flags_builder, g_variant_new("b", flags[i]));
        not_acquired_flags = g_variant_builder_end(flags_builder);
-       mmresource_manager_complete_commit(interface, invocation, error,
-                       not_acquired_flags);
+       mmresource_manager_complete_commit(interface, invocation, error, not_acquired_flags);
 
        g_free(flags);
        g_variant_builder_unref(flags_builder);
@@ -267,16 +273,9 @@ static void on_bus_acquired(GDBusConnection *connection, const gchar *name,
        GError* error = NULL;
        MM_RM_DEBUG("name of bus = %s, userID = %d", name, getuid());
 
-       g_signal_connect(interface, "handle-conf", G_CALLBACK(on_get_conf), NULL);
-       g_signal_connect(interface, "handle-create", G_CALLBACK(on_create_handle), NULL);
-       g_signal_connect(interface, "handle-destroy", G_CALLBACK(on_destroy_handle), NULL);
-       g_signal_connect(interface, "handle-commit", G_CALLBACK(on_commit_handle), NULL);
-
        if (!g_dbus_interface_skeleton_export(G_DBUS_INTERFACE_SKELETON(interface),
                        connection, RMD_GDBUS_PATH, &error)) {
                MM_RM_ERROR("failed to export interface. msg : %s", error->message);
                g_error_free(error);
        }
-
-       _notify_fork_done();
 }
index 8497cd0..aceaf82 100644 (file)
@@ -23,8 +23,9 @@
 
 #include <glib.h>
 
-int _mmrm_dmn_dbus_init();
-int _mmrm_dmn_dbus_deinit();
+int _mmrm_dmn_dbus_init(void);
+int _mmrm_dmn_dbus_deinit(void);
+void _mmrm_dmn_notify_fork_done(void);
 int _mmrm_dmn_dbus_get_conf(mm_resource_manager_res_volume **max_volume,
                mm_resource_manager_condition_volume_a **cond_volume);
 int _mmrm_dmn_dbus_create(mm_resource_manager_app_class_e app_class,
index b09efff..f90b8e4 100644 (file)
@@ -776,8 +776,7 @@ static gboolean __wait_for_release_cb_sync(mm_resource_manager_id id)
                if (read_size == sizeof(recv_id)) {
                        ret = id == recv_id;
                        if (ret == FALSE)
-                               MM_RM_ERROR("Sync is received from wrong client #%"PRIu64,
-                                               recv_id);
+                               MM_RM_ERROR("Sync is received from wrong client #%"PRIu64, recv_id);
                        /*
                         * Wait POLLHUP to avoid situation when client sent last sync
                         * through the pipe, but not already closed the pipe handle and
@@ -785,12 +784,10 @@ static gboolean __wait_for_release_cb_sync(mm_resource_manager_id id)
                         * the next sync.
                         */
                        sync.revents = 0;
-                       if (poll(&sync, 1, RELEASE_CB_SYNC_TIMEOUT * 1000) == 0 ||
-                                       (sync.revents & (POLLHUP | POLLERR)) == 0)
+                       if (poll(&sync, 1, RELEASE_CB_SYNC_TIMEOUT * 1000) == 0 || (sync.revents & (POLLHUP | POLLERR)) == 0)
                                MM_RM_ERROR("The client didn't close the FIFO");
                } else {
-                       MM_RM_ERROR("Read is failed (revents=%hd,read_size=%zd)",
-                                       sync.revents, read_size);
+                       MM_RM_ERROR("Read is failed (revents=%hd,read_size=%zd)", sync.revents, read_size);
                        ret = FALSE;
                }
        }
index 1a8dc62..5390dbb 100644 (file)
@@ -223,7 +223,7 @@ int _mm_resource_manager_destroy(mm_resource_manager_h rm)
        g_mutex_lock(&handle->resources_lock);
        ret = __dbus_destroy(handle);
        if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
-               MM_RM_ERROR("Dbus destroy request failed");
+               MM_RM_ERROR("Dbus destroy request failed 0x%x", ret);
 
        __destroy_dispatcher(handle);
 
@@ -251,11 +251,10 @@ int _mm_resource_manager_mark_for_acquire(
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        ret = __create_resource(handle, type, volume, &resource);
-       MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
-                       handle->resources_lock, ret, "Resource cannot be created");
+       MM_RM_UNLOCK2_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
+                       handle->resources_lock, handles_lock, ret, "Resource cannot be created");
        g_ptr_array_add(handle->resources, resource);
 
        *resource_h = resource;
@@ -264,6 +263,7 @@ int _mm_resource_manager_mark_for_acquire(
                        "resource manager #%"PRIu64, *resource_h, type, volume,
                        _mm_rm_hash64(handle->id));
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        return ret;
 }
@@ -282,11 +282,10 @@ int _mm_resource_manager_resize_marked(mm_resource_manager_h rm,
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        i = __get_resource_index(handle, resource);
-       MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
-                       handle->resources_lock,
+       MM_RM_UNLOCK2_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
+                       handle->resources_lock, handles_lock,
                        MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
                        "Invalid resource handle");
        if (new_volume == resource->volume) {
@@ -303,8 +302,8 @@ int _mm_resource_manager_resize_marked(mm_resource_manager_h rm,
        case MM_RESOURCE_MANAGER_RES_STATE_FOR_ACQUIRE:
                if (add_volume > 0) {
                        ret = __check_resource(handle, resource->type, add_volume);
-                       MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
-                               handle->resources_lock, ret, "Resource check failed");
+                       MM_RM_UNLOCK2_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
+                               handle->resources_lock, handles_lock, ret, "Resource check failed");
                }
                resource->volume = new_volume;
                break;
@@ -312,8 +311,8 @@ int _mm_resource_manager_resize_marked(mm_resource_manager_h rm,
        case MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE:
        case MM_RESOURCE_MANAGER_RES_STATE_ACQUIRED:
                ret = __create_resource(handle, resource->type, add_volume, &tmp_resource);
-               MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
-                               handle->resources_lock, ret, "Resource cannot be created");
+               MM_RM_UNLOCK2_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
+                               handle->resources_lock, handles_lock, ret, "Resource cannot be created");
 
                tmp_resource->volume = resource->volume;
                tmp_resource->state = MM_RESOURCE_MANAGER_RES_STATE_FOR_RELEASE;
@@ -329,6 +328,7 @@ int _mm_resource_manager_resize_marked(mm_resource_manager_h rm,
        MM_RM_INFO("Resource %p is resized for acquire in resource manager #%"PRIu64,
                        resource_h, _mm_rm_hash64(handle->id));
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        return ret;
 }
@@ -343,11 +343,10 @@ int _mm_resource_manager_mark_for_release(mm_resource_manager_h rm,
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        i = __get_resource_index(handle, resource);
-       MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
-                       handle->resources_lock,
+       MM_RM_UNLOCK2_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
+                       handle->resources_lock, handles_lock,
                        MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
                        "Invalid resource handle");
 
@@ -356,6 +355,7 @@ int _mm_resource_manager_mark_for_release(mm_resource_manager_h rm,
        MM_RM_INFO("Resource %p is marked for release in resource manager #%"PRIu64,
                        resource_h, _mm_rm_hash64(handle->id));
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        return MM_RESOURCE_MANAGER_ERROR_NONE;
 }
@@ -368,18 +368,17 @@ int _mm_resource_manager_mark_all_for_release(mm_resource_manager_h rm)
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        for (i = 0; i < handle->resources->len; i++) {
                if (!__mark_resource_for_release(handle->resources, i,
-                               (mm_resource_manager_res_p) handle->resources->pdata[i])) {
+                               (mm_resource_manager_res_p) handle->resources->pdata[i]))
                        i--;
-               }
        }
 
        MM_RM_INFO("All resources are marked for release in resource manager #%"PRIu64,
                        _mm_rm_hash64(handle->id));
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        return MM_RESOURCE_MANAGER_ERROR_NONE;
 }
@@ -395,11 +394,10 @@ int _mm_resource_manager_get_resource_info(mm_resource_manager_h rm,
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        i = __get_resource_index(handle, resource);
-       MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
-                       handle->resources_lock,
+       MM_RM_UNLOCK2_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
+                       handle->resources_lock, handles_lock,
                        MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
                        "Invalid resource handle");
 
@@ -410,6 +408,7 @@ int _mm_resource_manager_get_resource_info(mm_resource_manager_h rm,
        MM_RM_INFO("Info structure of resource %p in resource manager #%"PRIu64" is filled",
                        resource_h, _mm_rm_hash64(handle->id));
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        return MM_RESOURCE_MANAGER_ERROR_NONE;
 }
@@ -422,16 +421,15 @@ int _mm_resource_manager_commit(mm_resource_manager_h rm)
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        ret = __dbus_commit(handle);
-       if (ret == MM_RESOURCE_MANAGER_ERROR_NONE) {
+       if (ret == MM_RESOURCE_MANAGER_ERROR_NONE)
                MM_RM_INFO("Changes in resource manager #%"PRIu64" have been committed successfully",
                                _mm_rm_hash64(handle->id));
-       } else {
+       else
                MM_RM_ERROR("Dbus commit request failed");
-       }
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        return ret;
 }
@@ -444,11 +442,11 @@ int _mm_resource_manager_set_status_cb(mm_resource_manager_h rm,
        g_mutex_lock(&handles_lock);
        MM_RESOURCE_MANAGER_CHECK(handle);
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
 
        handle->status_cb.cb = cb;
        handle->status_cb.user_data = user_data;
        g_mutex_unlock(&handle->resources_lock);
+       g_mutex_unlock(&handles_lock);
 
        MM_RM_INFO("Status callback %p in resource manager #%"PRIu64" is set", cb,
                        _mm_rm_hash64(handle->id));
@@ -504,7 +502,6 @@ void __mm_resource_manager_release_callback(mm_resource_manager_s *handle,
        MM_RM_HASH64(handle_id);
        if (handle_id == id) {
                g_mutex_lock(&handle->resources_lock);
-               g_mutex_unlock(&handles_lock);
                for (j = 0; j < handle->resources->len; j++) {
                        resource = (mm_resource_manager_res_s*)handle->resources->pdata[j];
                        if (resource->type == type && resource->volume == volume) {
@@ -531,8 +528,6 @@ void __mm_resource_manager_release_callback(mm_resource_manager_s *handle,
                                MM_RM_ERROR("Resources cannot be released after release cb");
                        }
                }
-       } else {
-               g_mutex_unlock(&handles_lock);
        }
 }
 
@@ -540,7 +535,6 @@ void __mm_resource_manager_status_callback(mm_resource_manager_s *handle,
                mm_resource_manager_status_e status)
 {
        g_mutex_lock(&handle->resources_lock);
-       g_mutex_unlock(&handles_lock);
        if (handle->status_cb.cb) {
                ((mm_resource_manager_status_cb)handle->status_cb.cb)(handle, status,
                                handle->status_cb.user_data);
@@ -807,8 +801,7 @@ static int __dbus_destroy(mm_resource_manager_s *handle)
                        NULL, &error);
        MM_RM_RET_IF_GERR(error, "DBus destroy msg cannot be sent");
 
-       MM_RM_DEBUG("Destroy for id - #%"PRIu64" returned error - %d",
-                       _mm_rm_hash64(handle->id), rm_error);
+       MM_RM_DEBUG("Destroy for id - #%"PRIu64" returned error - %d", _mm_rm_hash64(handle->id), rm_error);
 
        return MM_RESOURCE_MANAGER_ERROR_NONE;
 }
@@ -845,7 +838,7 @@ static int __dbus_commit(mm_resource_manager_s *handle)
                        release_num++;
                        break;
                default:
-                       ;
+                       break;
                }
        }
 
@@ -914,7 +907,6 @@ static void __dbus_release_callback(MMResourceManager *object, guint64 arg_id,
                gint arg_resource_type, gint arg_volume)
 {
        mm_resource_manager_s *handle;
-       gboolean unlock = TRUE;
        int i;
 
        g_mutex_lock(&handles_lock);
@@ -923,19 +915,15 @@ static void __dbus_release_callback(MMResourceManager *object, guint64 arg_id,
                if (handle->dbus_proxy == object) {
                        __mm_resource_manager_release_callback(handle, arg_id,
                                        arg_resource_type, arg_volume);
-                       unlock = FALSE;
                        break;
                }
        }
-
-       if (unlock)
-               g_mutex_unlock(&handles_lock);
+       g_mutex_unlock(&handles_lock);
 }
 
 static void __dbus_status_callback(MMResourceManager *object, gint arg_status)
 {
        mm_resource_manager_s *handle;
-       gboolean unlock = TRUE;
        int i;
 
        g_mutex_lock(&handles_lock);
@@ -943,13 +931,10 @@ static void __dbus_status_callback(MMResourceManager *object, gint arg_status)
                handle = (mm_resource_manager_s*)handles->pdata[i];
                if (handle->dbus_proxy == object) {
                        __mm_resource_manager_status_callback(handle, arg_status);
-                       unlock = FALSE;
                        break;
                }
        }
-
-       if (unlock)
-               g_mutex_unlock(&handles_lock);
+       g_mutex_unlock(&handles_lock);
 }
 
 static gpointer __dispatcher_thread(gpointer user_data)