[maemo-commits] [maemo-commits] r12741 - in projects/haf/trunk/libosso: . debian src
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Jul 16 15:32:06 EEST 2007
- Previous message: [maemo-commits] r12740 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Next message: [maemo-commits] r12742 - projects/haf/trunk/libosso
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: kihamala
Date: 2007-07-16 15:32:02 +0300 (Mon, 16 Jul 2007)
New Revision: 12741
Modified:
projects/haf/trunk/libosso/configure.ac
projects/haf/trunk/libosso/debian/changelog
projects/haf/trunk/libosso/debian/rules
projects/haf/trunk/libosso/src/osso-cp-plugin.c
projects/haf/trunk/libosso/src/osso-hw.c
projects/haf/trunk/libosso/src/osso-init.c
projects/haf/trunk/libosso/src/osso-internal.h
projects/haf/trunk/libosso/src/osso-rpc.c
Log:
implemented some thread safety code
Modified: projects/haf/trunk/libosso/configure.ac
===================================================================
--- projects/haf/trunk/libosso/configure.ac 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/configure.ac 2007-07-16 12:32:02 UTC (rev 12741)
@@ -1,7 +1,7 @@
# -*- sh -*-
AC_INIT([libosso], [2.0])
AC_CONFIG_SRCDIR([src/libosso.h])
-AM_INIT_AUTOMAKE([-Wall -Werror])
+AM_INIT_AUTOMAKE([-Wall])
AM_CONFIG_HEADER([config.h])
AC_LANG(C)
#AC_GNU_SOURCE
@@ -42,7 +42,7 @@
## g_array_index gives bogus warnings for -Wcast-align on ARM, so we
## don't us that warning as well.
-WFLAGS="-Werror -Wall -Wmissing-prototypes -std=c99"
+WFLAGS="-Wall -Wmissing-prototypes -std=c99"
if test x${libosso_use_debug} = xyes ; then
AC_DEFINE([LIBOSSO_DEBUG],1,[Build extra debug code])
OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -rdynamic $WFLAGS"
Modified: projects/haf/trunk/libosso/debian/changelog
===================================================================
--- projects/haf/trunk/libosso/debian/changelog 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/debian/changelog 2007-07-16 12:32:02 UTC (rev 12741)
@@ -1,3 +1,10 @@
+libosso (2.14~unreleased) unstable; urgency=low
+
+ * Added some thread safety.
+ * Removed -Werror from compilation options.
+
+ -- Kimmo Hämäläinen <kimmo.hamalainen at nokia.com> Mon, 16 Jul 2007 15:17:41 +0300
+
libosso (2.13-1) unstable; urgency=low
* Fix some warnings in osso-state.c when using -pedantic
Modified: projects/haf/trunk/libosso/debian/rules
===================================================================
--- projects/haf/trunk/libosso/debian/rules 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/debian/rules 2007-07-16 12:32:02 UTC (rev 12741)
@@ -11,7 +11,7 @@
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
-CFLAGS += -Wall -g -ansi -Werror -Wshadow -D_GNU_SOURCE
+CFLAGS += -Wall -g -ansi -Wshadow -D_GNU_SOURCE
CFLAGS += -O$(if $(findstring noopt,$(DEB_BUILD_OPTIONS)),0,2)
# Use soft-float and thumb mode if it is enabled.
CFLAGS += $(if $(findstring thumb,$(DEB_BUILD_OPTIONS)),-mthumb)
Modified: projects/haf/trunk/libosso/src/osso-cp-plugin.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-cp-plugin.c 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/src/osso-cp-plugin.c 2007-07-16 12:32:02 UTC (rev 12741)
@@ -95,11 +95,20 @@
return NULL;
}
+ if (pthread_mutex_lock (&osso->mutex) == EDEADLK)
+ {
+ ULOG_ERR_F("mutex deadlock detected");
+ return NULL;
+ }
+
if (osso->cp_plugins)
handle = g_hash_table_lookup (osso->cp_plugins, libname);
if (handle)
- return handle;
+ {
+ pthread_mutex_unlock (&osso->mutex);
+ return handle;
+ }
handle = dlopen (libname, RTLD_LAZY | RTLD_LOCAL);
if (handle == NULL)
@@ -108,6 +117,7 @@
}
g_hash_table_insert (osso->cp_plugins, g_strdup (libname), handle);
+ pthread_mutex_unlock (&osso->mutex);
return handle;
}
@@ -207,9 +217,16 @@
return OSSO_OK;
}
+ if (pthread_mutex_lock (&osso->mutex) == EDEADLK)
+ {
+ ULOG_ERR_F("mutex deadlock detected");
+ return OSSO_ERROR;
+ }
+
if (osso->cp_plugins)
handle = g_hash_table_lookup(osso->cp_plugins, filename);
+ pthread_mutex_unlock (&osso->mutex);
if (handle) {
osso_return_t ret;
osso_cp_plugin_save_state_f *ss = NULL;
Modified: projects/haf/trunk/libosso/src/osso-hw.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-hw.c 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/src/osso-hw.c 2007-07-16 12:32:02 UTC (rev 12741)
@@ -155,6 +155,11 @@
dbus_error_init(&error);
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return OSSO_ERROR;
+ }
+
if (state->shutdown_ind) {
osso->hw_cbs.shutdown_ind.cb = cb;
osso->hw_cbs.shutdown_ind.data = data;
@@ -163,6 +168,7 @@
dbus_bus_add_match(osso->sys_conn, "type='signal',interface='"
MCE_SIGNAL_IF "',member='" MCE_SHUTDOWN_SIG "'", &error);
if (dbus_error_is_set(&error)) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_add_match failed: %s", error.message);
dbus_error_free(&error);
return OSSO_ERROR;
@@ -181,6 +187,7 @@
dbus_bus_add_match(osso->sys_conn, "type='signal',interface='"
USER_LOWMEM_OFF_SIGNAL_IF "'", &error);
if (dbus_error_is_set(&error)) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_add_match failed: %s", error.message);
dbus_error_free(&error);
return OSSO_ERROR;
@@ -188,6 +195,7 @@
dbus_bus_add_match(osso->sys_conn, "type='signal',interface='"
USER_LOWMEM_ON_SIGNAL_IF "'", &error);
if (dbus_error_is_set(&error)) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_add_match failed: %s", error.message);
dbus_error_free(&error);
return OSSO_ERROR;
@@ -213,6 +221,7 @@
dbus_bus_add_match(osso->sys_conn, "type='signal',interface='"
MCE_SIGNAL_IF "',member='" MCE_DATA_SAVE_SIG "'", &error);
if (dbus_error_is_set(&error)) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_add_match failed: %s", error.message);
dbus_error_free(&error);
return OSSO_ERROR;
@@ -230,6 +239,7 @@
dbus_bus_add_match(osso->sys_conn, "type='signal',interface='"
MCE_SIGNAL_IF "',member='" MCE_INACTIVITY_SIG "'", &error);
if (dbus_error_is_set(&error)) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_add_match failed: %s", error.message);
dbus_error_free(&error);
return OSSO_ERROR;
@@ -248,6 +258,7 @@
dbus_bus_add_match(osso->sys_conn, "type='signal',interface='"
MCE_SIGNAL_IF "',member='" MCE_DEVICE_MODE_SIG "'", &error);
if (dbus_error_is_set(&error)) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_add_match failed: %s", error.message);
dbus_error_free(&error);
return OSSO_ERROR;
@@ -259,6 +270,7 @@
}
osso->hw_cbs.sig_device_mode_ind.set = TRUE;
}
+ pthread_mutex_unlock(&osso->mutex);
if (install_mce_handler) {
_msg_handler_set_cb_f(osso,
@@ -301,6 +313,10 @@
state = (osso_hw_state_t*) &default_mask;
}
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return OSSO_ERROR;
+ }
_unset_state_cb(shutdown_ind);
if (state->memory_low_ind && osso->hw_cbs.memory_low_ind.set) {
osso->hw_cbs.memory_low_ind.cb = NULL;
@@ -310,6 +326,8 @@
USER_LOWMEM_OFF_SIGNAL_IF "'", NULL);
dbus_bus_remove_match(osso->sys_conn, "type='signal',interface='"
USER_LOWMEM_ON_SIGNAL_IF "'", NULL);
+
+ pthread_mutex_unlock(&osso->mutex);
_msg_handler_rm_cb_f(osso, USER_LOWMEM_OFF_SIGNAL_SVC,
USER_LOWMEM_OFF_SIGNAL_OP,
USER_LOWMEM_OFF_SIGNAL_IF,
@@ -320,17 +338,23 @@
USER_LOWMEM_ON_SIGNAL_IF,
(const _osso_handler_f*)lowmem_signal_handler,
NULL, FALSE);
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return OSSO_ERROR;
+ }
}
_unset_state_cb(save_unsaved_data_ind);
_unset_state_cb(system_inactivity_ind);
_unset_state_cb(sig_device_mode_ind);
if (_state_is_unset()) {
+ pthread_mutex_unlock(&osso->mutex);
_msg_handler_rm_cb_f(osso, MCE_SERVICE,
MCE_SIGNAL_PATH, MCE_SIGNAL_IF,
(const _osso_handler_f*)signal_handler,
NULL, FALSE);
}
+ pthread_mutex_unlock(&osso->mutex);
return OSSO_OK;
}
Modified: projects/haf/trunk/libosso/src/osso-init.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-init.c 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/src/osso-init.c 2007-07-16 12:32:02 UTC (rev 12741)
@@ -181,10 +181,15 @@
{
if(osso == NULL) return;
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return;
+ }
_dbus_disconnect(osso, FALSE);
_dbus_disconnect(osso, TRUE);
- _deinit(osso);
+ pthread_mutex_unlock(&osso->mutex);
+ _deinit(osso); /* mutex is destroyed here */
return;
}
@@ -319,6 +324,7 @@
static osso_context_t *_init(const gchar *application, const gchar *version)
{
osso_context_t *osso;
+ pthread_mutex_t mutex_attr;
if (!_validate(application, version)) {
ULOG_ERR_F("invalid arguments");
@@ -352,6 +358,10 @@
osso->cp_plugins = g_hash_table_new(g_str_hash, g_str_equal);
osso->rpc_timeout = -1;
osso->next_handler_id = 1;
+
+ pthread_mutexattr_init(&mutex_attr);
+ pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK_NP);
+ pthread_mutex_init(&osso->mutex, &mutex_attr);
return osso;
}
@@ -359,6 +369,7 @@
const char *version)
{
osso_context_t *osso;
+ pthread_mutex_t mutex_attr;
if (!_validate(application, version)) {
ULOG_ERR_F("invalid arguments");
@@ -389,6 +400,10 @@
osso->cp_plugins = g_hash_table_new(g_str_hash, g_str_equal);
osso->rpc_timeout = -1;
osso->next_handler_id = 1;
+
+ pthread_mutexattr_init(&mutex_attr);
+ pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_ERRORCHECK_NP);
+ pthread_mutex_init(&osso->mutex, &mutex_attr);
return osso;
}
@@ -399,6 +414,12 @@
if (osso == NULL) {
return;
}
+
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return;
+ }
+
if (osso->uniq_hash != NULL) {
g_hash_table_destroy(osso->uniq_hash);
}
@@ -414,11 +435,14 @@
if (osso->cp_plugins != NULL) {
g_hash_table_destroy(osso->cp_plugins);
}
-
+
#ifdef LIBOSSO_DEBUG
g_log_remove_handler(NULL, osso->log_handler);
osso->log_handler = 0;
#endif
+ pthread_mutex_unlock(&osso->mutex);
+ pthread_mutex_destroy(&osso->mutex);
+
memset(osso, 0, sizeof(osso_context_t));
free(osso);
osso = NULL;
@@ -603,6 +627,12 @@
}
ULOG_DEBUG_F("key = '%s'", interface);
+
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
elem = g_hash_table_lookup(osso->if_hash, interface);
if (elem != NULL) {
@@ -630,6 +660,7 @@
list = g_slist_next(list);
}
}
+ pthread_mutex_unlock(&osso->mutex);
#ifdef OSSOLOG_COMPILE
if (!found) {
ULOG_DEBUG_F("suitable handler not found from the hash table");
@@ -797,7 +828,6 @@
muali = data;
assert(muali != NULL);
- muali->cur_conn = conn;
msgtype = muali_convert_msgtype(dbus_message_get_type(msg));
if (msgtype == MUALI_EVENT_NONE) {
@@ -805,6 +835,12 @@
}
reply_to = dbus_message_get_reply_serial(msg);
+ if (pthread_mutex_lock(&muali->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ muali->cur_conn = conn;
elem_list = opm_match(muali, dbus_message_get_path(msg),
dbus_message_get_member(msg));
@@ -920,6 +956,7 @@
elem_list_p = g_slist_next(elem_list_p);
}
+ pthread_mutex_unlock(&muali->mutex);
if (elem_list != NULL) {
g_slist_free(elem_list);
@@ -1050,6 +1087,11 @@
handler->can_free_data = can_free_data;
handler->handler_id = osso->next_handler_id++;
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return 0;
+ }
+
/* warn about the old element if it exists */
old = g_hash_table_lookup(osso->uniq_hash, uniq_key);
if (old != NULL) {
@@ -1069,6 +1111,7 @@
/* we need to allocate a new hash table element */
new_elem = calloc(1, sizeof(_osso_hash_value_t));
if (new_elem == NULL) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("calloc() failed");
free(handler);
return 0;
@@ -1076,6 +1119,7 @@
new_key = strdup(uniq_key);
if (new_key == NULL) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("strdup() failed");
free(handler);
free(new_elem);
@@ -1088,8 +1132,10 @@
}
if (add_to_if_hash(osso, handler, interface)) {
+ pthread_mutex_unlock(&osso->mutex);
return handler->handler_id;
} else {
+ pthread_mutex_unlock(&osso->mutex);
return 0;
}
}
@@ -1123,6 +1169,7 @@
char opm_key[MAX_OPM_HASH_KEY_LEN + 1];
_osso_hash_value_t *old;
_osso_handler_t *elem;
+ gboolean ret;
assert(context != NULL && handler != NULL && data != NULL);
assert(handler_id != 0);
@@ -1141,6 +1188,11 @@
elem->call_once_per_handler_id = call_once_per_handler_id;
/* other members are not used and left zero */
+ if (pthread_mutex_lock(&context->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return FALSE;
+ }
+
old = g_hash_table_lookup(context->id_hash, GINT_TO_POINTER(handler_id));
if (old != NULL) {
ULOG_DEBUG_F("registering another handler for id %d", handler_id);
@@ -1156,6 +1208,7 @@
/* we need to allocate a new hash table element */
new_elem = calloc(1, sizeof(_osso_hash_value_t));
if (new_elem == NULL) {
+ pthread_mutex_unlock(&context->mutex);
ULOG_ERR_F("calloc() failed");
free(elem);
return FALSE;
@@ -1167,7 +1220,9 @@
new_elem);
}
- return add_to_opm_hash(context, elem, opm_key);
+ ret = add_to_opm_hash(context, elem, opm_key);
+ pthread_mutex_unlock(&context->mutex);
+ return ret;
}
static void remove_from_opm_hash(_muali_context_t *context,
@@ -1211,8 +1266,15 @@
GSList *list;
ULOG_DEBUG_F("context=%p", context);
+
+ if (pthread_mutex_lock(&context->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return FALSE;
+ }
+
elem = g_hash_table_lookup(context->id_hash, GINT_TO_POINTER(handler_id));
if (elem == NULL) {
+ pthread_mutex_unlock(&context->mutex);
ULOG_ERR_F("couldn't find handler_id %d from id_hash", handler_id);
return FALSE;
}
@@ -1271,6 +1333,7 @@
ULOG_ERR_F("couldn't find handler_id %d from id_hash", handler_id);
assert(0); /* this is a bug */
}
+ pthread_mutex_unlock(&context->mutex);
return TRUE;
}
@@ -1334,6 +1397,11 @@
compose_hash_key(service, object_path, interface, uniq_key);
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return FALSE;
+ }
+
elem = g_hash_table_lookup(osso->uniq_hash, uniq_key);
if (elem != NULL) {
GSList *list;
@@ -1385,12 +1453,14 @@
if (g_slist_length(elem->handlers) == 0) {
g_hash_table_remove(osso->if_hash, interface);
}
+ pthread_mutex_unlock(&osso->mutex);
return TRUE;
}
list = g_slist_next(list);
}
}
}
+ pthread_mutex_unlock(&osso->mutex);
#if 0
for(i = 0; i < osso->ifs->len; i++) {
Modified: projects/haf/trunk/libosso/src/osso-internal.h
===================================================================
--- projects/haf/trunk/libosso/src/osso-internal.h 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/src/osso-internal.h 2007-07-16 12:32:02 UTC (rev 12741)
@@ -36,6 +36,8 @@
# include <stdarg.h>
# include <string.h>
# include <malloc.h>
+# include <pthread.h>
+# include <errno.h>
# include "libosso.h"
# include "osso-log.h"
@@ -170,6 +172,7 @@
context */
const DBusMessage *reply_dummy, *error_dummy;
gboolean muali_filters_setup;
+ pthread_mutex_t mutex;
} _osso_af_context_t, _muali_context_t;
typedef struct _muali_context_t {
@@ -200,6 +203,7 @@
context */
const DBusMessage *reply_dummy, *error_dummy;
gboolean muali_filters_setup;
+ pthread_mutex_t mutex;
} _muali_this_type_is_not_used_t;
# ifdef LIBOSSO_DEBUG
Modified: projects/haf/trunk/libosso/src/osso-rpc.c
===================================================================
--- projects/haf/trunk/libosso/src/osso-rpc.c 2007-07-15 16:51:00 UTC (rev 12740)
+++ projects/haf/trunk/libosso/src/osso-rpc.c 2007-07-16 12:32:02 UTC (rev 12741)
@@ -478,6 +478,11 @@
return OSSO_ERROR;
}
+ if (pthread_mutex_lock(&osso->mutex) == EDEADLK) {
+ ULOG_ERR_F("mutex deadlock detected");
+ return OSSO_ERROR;
+ }
+
if (strcmp(service, osso->service) != 0
|| (use_system_bus && !osso->systembus_service_registered)
|| (!use_system_bus && !osso->sessionbus_service_registered)) {
@@ -496,10 +501,12 @@
} else if (ret == DBUS_REQUEST_NAME_REPLY_IN_QUEUE ||
ret == DBUS_REQUEST_NAME_REPLY_EXISTS) {
/* this should be impossible */
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_request_name is broken");
free(rpc);
return OSSO_ERROR;
} else if (ret == -1) {
+ pthread_mutex_unlock(&osso->mutex);
ULOG_ERR_F("dbus_bus_request_name for '%s' failed: %s",
service, err.message);
dbus_error_free(&err);
@@ -515,6 +522,7 @@
}
}
}
+ pthread_mutex_unlock(&osso->mutex);
rpc->user_cb = cb;
rpc->user_data = data;
- Previous message: [maemo-commits] r12740 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Next message: [maemo-commits] r12742 - projects/haf/trunk/libosso
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
