#include "lib/mm_resource_manager_priv.h"
#include "common/mm_resource_manager_dbus.h"
-
+static GMutex handles_lock;
+static GPtrArray *handles;
#define MM_RESOURCE_MANAGER(x) ((mm_resource_manager_s *) (x))
#define MM_RESOURCE_MANAGER_CHECK(x) \
GThread *dispatcher_thread;
} mm_resource_manager_s;
-
-
-static GMutex handles_lock;
-static GPtrArray *handles;
-
-
-
static void __init_lib() __attribute__((constructor));
static void __deinit_lib() __attribute__((destructor));
static int __check_resource(mm_resource_manager_s *rm,
mm_resource_manager_res_volume volume);
static void __mm_resource_manager_status_callback(mm_resource_manager_s *handle,
mm_resource_manager_status_e status);
+static void __mm_resource_handles_lock(void);
+static void __mm_resource_handles_unlock(void);
+static void __mm_resources_lock(mm_resource_manager_s *h);
+static void __mm_resources_unlock(mm_resource_manager_s *h);
+
static int __dbus_init(mm_resource_manager_s *handle);
static int __dbus_deinit(mm_resource_manager_s *handle);
static void __destroy_dispatcher(mm_resource_manager_s *handle);
-
int _mm_resource_manager_create(mm_resource_manager_app_class_e app_class,
mm_resource_manager_release_cb cb, void *cb_data,
mm_resource_manager_h *rm)
g_mutex_init(&handle->resources_lock);
*rm = (mm_resource_manager_h *) handle;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
g_ptr_array_add(handles, handle);
MM_RM_INFO("Resource manager #%"PRIu64" is created", _mm_rm_hash64(handle->id));
- g_mutex_unlock(&handles_lock);
+ __mm_resource_handles_unlock();
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
mm_resource_manager_id id;
int ret = MM_RESOURCE_MANAGER_ERROR_NONE;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
g_ptr_array_remove_fast(handles, handle);
- g_mutex_unlock(&handles_lock);
+ __mm_resource_handles_unlock();
id = handle->id;
- g_mutex_lock(&handle->resources_lock);
+ MM_RM_INFO("Resource manager #%"PRIu64" would be destroyed", _mm_rm_hash64(id));
+
+ __mm_resources_lock(handle);
ret = __dbus_destroy(handle);
if (ret != MM_RESOURCE_MANAGER_ERROR_NONE)
MM_RM_ERROR("Dbus destroy request failed 0x%x", ret);
__destroy_dispatcher(handle);
g_ptr_array_free(handle->resources, TRUE);
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
g_mutex_clear(&handle->resources_lock);
free(handle);
mm_resource_manager_s *handle = MM_RESOURCE_MANAGER(rm);
mm_resource_manager_res_p resource;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
ret = __create_resource(handle, type, volume, &resource);
MM_RM_UNLOCK_RETVM_IF(ret != MM_RESOURCE_MANAGER_ERROR_NONE,
MM_RM_INFO("Resource %p of type %d with volume %d is marked for acquire in "
"resource manager #%"PRIu64, *resource_h, type, volume,
_mm_rm_hash64(handle->id));
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
return ret;
}
int i;
int ret = MM_RESOURCE_MANAGER_ERROR_NONE;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
i = __get_resource_index(handle, resource);
MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
MM_RESOURCE_MANAGER_ERROR_INVALID_PARAMETER,
"Invalid resource handle");
if (new_volume == resource->volume) {
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
MM_RM_DEBUG("New volume equals the old. Resize is not needed.");
return ret;
}
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);
+ __mm_resources_unlock(handle);
return ret;
}
mm_resource_manager_res_p resource = (mm_resource_manager_res_p) resource_h;
int i;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
i = __get_resource_index(handle, resource);
MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
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);
+ __mm_resources_unlock(handle);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
mm_resource_manager_s *handle = MM_RESOURCE_MANAGER(rm);
int i;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
for (i = 0; i < handle->resources->len; i++) {
if (!__mark_resource_for_release(handle->resources, 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);
+ __mm_resources_unlock(handle);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
mm_resource_manager_res_p resource = (mm_resource_manager_res_p) resource_h;
int i;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
i = __get_resource_index(handle, resource);
MM_RM_UNLOCK_RETVM_IF(i == MM_RESOURCE_MANAGER_RES_NOT_FOUND,
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);
+ __mm_resources_unlock(handle);
return MM_RESOURCE_MANAGER_ERROR_NONE;
}
mm_resource_manager_s *handle = MM_RESOURCE_MANAGER(rm);
int ret;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
ret = __dbus_commit(handle);
if (ret == MM_RESOURCE_MANAGER_ERROR_NONE)
_mm_rm_hash64(handle->id));
else
MM_RM_ERROR("Dbus commit request failed");
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
return ret;
}
{
mm_resource_manager_s *handle = MM_RESOURCE_MANAGER(rm);
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
MM_RESOURCE_MANAGER_CHECK(handle);
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
handle->status_cb.cb = cb;
handle->status_cb.user_data = user_data;
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
MM_RM_INFO("Status callback %p in resource manager #%"PRIu64" is set", cb,
_mm_rm_hash64(handle->id));
handle_id = handle->id;
MM_RM_HASH64(handle_id);
if (handle_id == id) {
- g_mutex_lock(&handle->resources_lock);
- g_mutex_unlock(&handles_lock);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
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) {
break;
}
}
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
if (release_all) {
if (_mm_resource_manager_mark_all_for_release(handle) == MM_RESOURCE_MANAGER_ERROR_NONE
}
}
} else {
- g_mutex_unlock(&handles_lock);
+ __mm_resource_handles_unlock();
}
}
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);
+ __mm_resources_lock(handle);
+ __mm_resource_handles_unlock();
if (handle->status_cb.cb) {
((mm_resource_manager_status_cb)handle->status_cb.cb)(handle, status,
handle->status_cb.user_data);
}
- g_mutex_unlock(&handle->resources_lock);
+ __mm_resources_unlock(handle);
}
+static void __mm_resource_handles_lock(void)
+{
+ MM_RM_INFO("handles lock");
+ g_mutex_lock(&handles_lock);
+}
+
+static void __mm_resource_handles_unlock(void)
+{
+ g_mutex_unlock(&handles_lock);
+ MM_RM_INFO("handles unlocked");
+}
+
+static void __mm_resources_lock(mm_resource_manager_s *h)
+{
+ MM_RM_RETM_IF(!h, "handle is NULL");
+ MM_RM_INFO("[handle %p]resources lock", h);
+ g_mutex_lock(&h->resources_lock);
+}
+
+static void __mm_resources_unlock(mm_resource_manager_s *h)
+{
+ MM_RM_RETM_IF(!h, "handle is NULL");
+ g_mutex_unlock(&h->resources_lock);
+ MM_RM_INFO("[handle %p]resources unlocked", h);
+}
static int __check_resource(mm_resource_manager_s *rm,
mm_resource_manager_res_type_e type,
gboolean unlock = TRUE;
int i;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
for (i = 0; i < handles->len; i++) {
handle = (mm_resource_manager_s*)handles->pdata[i];
if (handle->dbus_proxy == object) {
}
if (unlock)
- g_mutex_unlock(&handles_lock);
+ __mm_resource_handles_unlock();
}
static void __dbus_status_callback(MMResourceManager *object, gint arg_status)
gboolean unlock = TRUE;
int i;
- g_mutex_lock(&handles_lock);
+ __mm_resource_handles_lock();
for (i = 0; i < handles->len; i++) {
handle = (mm_resource_manager_s*)handles->pdata[i];
if (handle->dbus_proxy == object) {
}
if (unlock)
- g_mutex_unlock(&handles_lock);
+ __mm_resource_handles_unlock();
}
static gpointer __dispatcher_thread(gpointer user_data)