[Pkg-maemo-commits] r249 ./libosso/debian: * Merge r235..248 from trunk.

Jonny Lamb jonnylamb at jonnylamb.com
Sun Jul 22 20:02:17 UTC 2007


------------------------------------------------------------
revno: 249
committer: Jonny Lamb <jonnylamb at jonnylamb.com>
branch nick: libosso
timestamp: Sun 2007-07-22 21:02:17 +0100
message:
  * Merge r235..248 from trunk.
modified:
  configure
  configure.ac
  debian/changelog
  debian/rules
  src/Makefile.am
  src/Makefile.in
  src/muali.h
  src/osso-cp-plugin.c
  src/osso-hw.c
  src/osso-init.c
  src/osso-internal.h
  src/osso-mem.c
  src/osso-rpc.c
    ------------------------------------------------------------
    revno: 217.1.18
    merged: vcs-imports at canonical.com-20070703120118-5o97s49gust63gi9
    committer: kihamala
    timestamp: Tue 2007-07-03 12:01:18 +0000
    message:
      patch from Leonid
    ------------------------------------------------------------
    revno: 217.1.19
    merged: vcs-imports at canonical.com-20070703124928-hhdtouk578h8elg9
    committer: kihamala
    timestamp: Tue 2007-07-03 12:49:28 +0000
    message:
      tagging it
    ------------------------------------------------------------
    revno: 217.1.20
    merged: vcs-imports at canonical.com-20070716123202-qdcub6jedjx4ef8y
    committer: kihamala
    timestamp: Mon 2007-07-16 12:32:02 +0000
    message:
      implemented some thread safety code
    ------------------------------------------------------------
    revno: 217.1.21
    merged: vcs-imports at canonical.com-20070716123315-hq323s114v8qfveb
    committer: kihamala
    timestamp: Mon 2007-07-16 12:33:15 +0000
    message:
      rerun autogen
    ------------------------------------------------------------
    revno: 217.1.22
    merged: vcs-imports at canonical.com-20070716124017-p9naiv313l7c5hvo
    committer: kihamala
    timestamp: Mon 2007-07-16 12:40:17 +0000
    message:
      fixed wrong type
    ------------------------------------------------------------
    revno: 217.1.23
    merged: vcs-imports at canonical.com-20070716135030-qul9duo06jcfr79j
    committer: kihamala
    timestamp: Mon 2007-07-16 13:50:30 +0000
    message:
      added MCE_CFLAGS/LIBS
    ------------------------------------------------------------
    revno: 217.1.24
    merged: vcs-imports at canonical.com-20070716135334-uw96fq5oh7p3q2u7
    committer: kihamala
    timestamp: Mon 2007-07-16 13:53:34 +0000
    message:
      fixed a warning
    ------------------------------------------------------------
    revno: 217.1.25
    merged: vcs-imports at canonical.com-20070716135721-red8cp4agehuk5cv
    committer: kihamala
    timestamp: Mon 2007-07-16 13:57:21 +0000
    message:
      fixed a warning
    ------------------------------------------------------------
    revno: 217.1.26
    merged: vcs-imports at canonical.com-20070716141445-cv01srsh5fvxcew6
    committer: kihamala
    timestamp: Mon 2007-07-16 14:14:45 +0000
    message:
      added _GNU_SOURCE to configure.ac
    ------------------------------------------------------------
    revno: 217.1.27
    merged: vcs-imports at canonical.com-20070717070205-odw7838nah3nazwp
    committer: kihamala
    timestamp: Tue 2007-07-17 07:02:05 +0000
    message:
      fix to thread code
    ------------------------------------------------------------
    revno: 217.1.28
    merged: vcs-imports at canonical.com-20070717071418-8qrd7ttmlyw6udyw
    committer: kihamala
    timestamp: Tue 2007-07-17 07:14:18 +0000
    message:
      made a macro for the locking
    ------------------------------------------------------------
    revno: 217.1.29
    merged: vcs-imports at canonical.com-20070717072312-hg79lnsihwh35qy7
    committer: kihamala
    timestamp: Tue 2007-07-17 07:23:12 +0000
    message:
      using macros
    ------------------------------------------------------------
    revno: 217.1.30
    merged: vcs-imports at canonical.com-20070717075128-a768xjmjgtyb1vw6
    committer: kihamala
    timestamp: Tue 2007-07-17 07:51:28 +0000
    message:
      more macro replacing
    ------------------------------------------------------------
    revno: 217.1.31
    merged: vcs-imports at canonical.com-20070717080506-tdmocbw4o7xy6j1p
    committer: kihamala
    timestamp: Tue 2007-07-17 08:05:06 +0000
    message:
      tagging it
-------------- next part --------------
=== modified file 'configure'
--- a/configure	2007-06-08 18:57:22 +0000
+++ b/configure	2007-07-22 20:02:17 +0000
@@ -2041,16 +2041,16 @@
 ## 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
 
 cat >>confdefs.h <<\_ACEOF
 #define LIBOSSO_DEBUG 1
 _ACEOF
 
-    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -rdynamic $WFLAGS"
+    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -D_GNU_SOURCE -rdynamic $WFLAGS"
 else
-    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -O2 -rdynamic $WFLAGS"
+    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -D_GNU_SOURCE -O2 -rdynamic $WFLAGS"
 fi
 
 
@@ -20631,6 +20631,8 @@
   fi
 
 
+
+
 # Checks for header files.
 echo "$as_me:$LINENO: checking for ANSI C header files" >&5
 echo $ECHO_N "checking for ANSI C header files... $ECHO_C" >&6

=== modified file 'configure.ac'
--- a/configure.ac	2007-06-08 18:57:22 +0000
+++ b/configure.ac	2007-07-22 20:02:17 +0000
@@ -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,12 +42,12 @@
 ## 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"
+    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -D_GNU_SOURCE -rdynamic $WFLAGS"
 else
-    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -O2 -rdynamic $WFLAGS"
+    OSSO_CFLAGS="-g -ansi -D_BSD_SOURCE -D_GNU_SOURCE -O2 -rdynamic $WFLAGS"
 fi
 
 AC_SUBST([OSSO_CFLAGS])
@@ -157,6 +157,8 @@
 AM_CONDITIONAL([BUILD_UNIT_TESTS], [test "x${build_unit_tests}" = "xyes"])
 
 PKG_CHECK_MODULES([MCE], [mce >= 1.5])
+AC_SUBST([MCE_LIBS])
+AC_SUBST([MCE_CFLAGS])
 
 # Checks for header files.
 AC_HEADER_STDC

=== modified file 'debian/changelog'
--- a/debian/changelog	2007-06-08 18:57:22 +0000
+++ b/debian/changelog	2007-07-22 20:02:17 +0000
@@ -1,5 +1,6 @@
-libosso (2.12-1.debian-1) UNRELEASED; urgency=low
+libosso (2.14-1.debian-1) UNRELEASED; urgency=low
 
+  [ Loic Minier ]
   * Set Maintainer to Debian Maemo Maintainers.
   * Update download URL in copyright file.
   * Wrap build-deps and deps.
@@ -23,14 +24,27 @@
   * Fix casing of Libosso in description; thanks Kimmo H??m??l??inen.
   * Merge r217..234 from trunk.
 
- -- Loic Minier <lool at dooz.org>  Thu, 07 Jun 2007 15:10:12 +0200
+  [ Jonny Lamb ]
+  * Merge r235..248 from trunk.
+
+ -- Jonny Lamb <jonnylamb at jonnylamb.com>  Sun, 22 Jul 2007 21:00:45 +0100
+
+libosso (2.14-1) unstable; urgency=low
+
+  * Added some thread safety by adding a mutex for osso_context_t.
+  * Removed -Werror from compilation options.
+  * Added MCE_CFLAGS and MCE_LIBS to Makefile.am.
+  * Fixed some compilation warnings pointed out by Richard Hult.
+
+ -- Kimmo H??m??l??inen <kimmo.hamalainen at nokia.com>  Tue, 17 Jul 2007 11:05:37 +0300
 
 libosso (2.13-1) unstable; urgency=low
 
-  * UNRELEASED
   * Fix some warnings in osso-state.c when using -pedantic
+  * Patch from Leonid to improve saw_malloc_hook() in osso-mem.c.
+    Fixes: NB#62391
 
- -- Kimmo H??m??l??inen <kimmo.hamalainen at nokia.com>  Thu,  7 Jun 2007 11:30:03 +0300
+ -- Kimmo H??m??l??inen <kimmo.hamalainen at nokia.com>  Tue, 03 Jul 2007 15:00:40 +0300
 
 libosso (2.12-1) unstable; urgency=low
 

=== modified file 'debian/rules'
--- a/debian/rules	2007-06-08 18:57:22 +0000
+++ b/debian/rules	2007-07-22 20:02:17 +0000
@@ -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
 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 file 'src/Makefile.am'
--- a/src/Makefile.am	2007-03-28 07:44:06 +0000
+++ b/src/Makefile.am	2007-07-16 13:50:30 +0000
@@ -1,4 +1,4 @@
-AM_CFLAGS = $(OSSO_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \
+AM_CFLAGS = $(MCE_CFLAGS) $(OSSO_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \
 	    -I$(top_srcdir) -I$(top_srcdir)/src
 
 AM_CPPFLAGS = \
@@ -7,7 +7,8 @@
 
 lib_LTLIBRARIES = libosso.la
 
-libosso_la_LIBADD = -ldl -lc $(GTHREAD_LIBS) $(GLIB_LIBS) $(DBUS_LIBS)
+libosso_la_LIBADD = -ldl -lc $(MCE_LIBS) $(GTHREAD_LIBS) $(GLIB_LIBS) \
+		    $(DBUS_LIBS)
 libosso_la_LDFLAGS = -version-info 4:0:3
 
 ossoincludedir=$(includedir)

=== modified file 'src/Makefile.in'
--- a/src/Makefile.in	2007-06-08 18:57:22 +0000
+++ b/src/Makefile.in	2007-07-22 20:02:17 +0000
@@ -53,7 +53,7 @@
 LTLIBRARIES = $(lib_LTLIBRARIES)
 am__DEPENDENCIES_1 =
 libosso_la_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
-	$(am__DEPENDENCIES_1)
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_libosso_la_OBJECTS = osso-state.lo osso-init.lo \
 	osso-application-top.lo osso-application-autosave.lo \
 	osso-hw.lo osso-mime.lo osso-system-note.lo osso-rpc.lo \
@@ -218,7 +218,7 @@
 sharedstatedir = @sharedstatedir@
 sysconfdir = @sysconfdir@
 target_alias = @target_alias@
-AM_CFLAGS = $(OSSO_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \
+AM_CFLAGS = $(MCE_CFLAGS) $(OSSO_CFLAGS) $(GLIB_CFLAGS) $(DBUS_CFLAGS) \
 	    -I$(top_srcdir) -I$(top_srcdir)/src
 
 AM_CPPFLAGS = \
@@ -226,7 +226,9 @@
 	-DOSSO_CTRLPANELPLUGINDIR=\"${prefix}/lib/hildon-control-panel\"
 
 lib_LTLIBRARIES = libosso.la
-libosso_la_LIBADD = -ldl -lc $(GTHREAD_LIBS) $(GLIB_LIBS) $(DBUS_LIBS)
+libosso_la_LIBADD = -ldl -lc $(MCE_LIBS) $(GTHREAD_LIBS) $(GLIB_LIBS) \
+		    $(DBUS_LIBS)
+
 libosso_la_LDFLAGS = -version-info 4:0:3
 ossoincludedir = $(includedir)
 ossoinclude_HEADERS = libosso.h osso-log.h log-functions.h osso-mem.h muali.h

=== modified file 'src/muali.h'
--- a/src/muali.h	2007-01-22 15:59:44 +0000
+++ b/src/muali.h	2007-07-16 13:57:21 +0000
@@ -112,7 +112,7 @@
          * argument of type MUALI_TYPE_INVALID. args is NULL if the
          * message has no arguments.
          * Note that this is ignored in case of a vararg function. */
-        const muali_arg_t *args;
+        muali_arg_t *args;
 } muali_event_info_t;
 
 typedef void (muali_handler_t)(muali_context_t *context,

=== modified file 'src/osso-cp-plugin.c'
--- a/src/osso-cp-plugin.c	2007-06-06 07:10:44 +0000
+++ b/src/osso-cp-plugin.c	2007-07-17 07:51:28 +0000
@@ -95,11 +95,16 @@
       return NULL;
     }
 
+  LOCK_OR_RETURN(osso->mutex, 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 +113,7 @@
     }
 
   g_hash_table_insert (osso->cp_plugins, g_strdup (libname), handle);
+  pthread_mutex_unlock (&osso->mutex);
   return handle;
 }
 
@@ -207,9 +213,12 @@
         return OSSO_OK;
     }
 
+    LOCK_OR_RETURN(osso->mutex, 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 file 'src/osso-hw.c'
--- a/src/osso-hw.c	2007-03-20 13:53:10 +0000
+++ b/src/osso-hw.c	2007-07-17 07:51:28 +0000
@@ -155,6 +155,8 @@
 
     dbus_error_init(&error);
 
+    LOCK_OR_RETURN(osso->mutex, OSSO_ERROR);
+
     if (state->shutdown_ind) {
         osso->hw_cbs.shutdown_ind.cb = cb;
         osso->hw_cbs.shutdown_ind.data = data;
@@ -163,6 +165,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 +184,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,10 +192,12 @@
             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;
             }
+            pthread_mutex_unlock(&osso->mutex);
             _msg_handler_set_cb_f(osso, USER_LOWMEM_OFF_SIGNAL_SVC,
                                   USER_LOWMEM_OFF_SIGNAL_OP,
                                   USER_LOWMEM_OFF_SIGNAL_IF,
@@ -200,6 +206,7 @@
                                   USER_LOWMEM_ON_SIGNAL_OP,
                                   USER_LOWMEM_ON_SIGNAL_IF,
                                   lowmem_signal_handler, NULL, FALSE);
+            LOCK_OR_RETURN(osso->mutex, OSSO_ERROR);
         }
         osso->hw_cbs.memory_low_ind.set = TRUE;
 
@@ -213,6 +220,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 +238,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 +257,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 +269,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 +312,8 @@
 	state = (osso_hw_state_t*) &default_mask;
     }
 
+    LOCK_OR_RETURN(osso->mutex, 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 +323,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 +335,20 @@
                              USER_LOWMEM_ON_SIGNAL_IF,
                              (const _osso_handler_f*)lowmem_signal_handler,
                              NULL, FALSE);
+        LOCK_OR_RETURN(osso->mutex, 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 file 'src/osso-init.c'
--- a/src/osso-init.c	2007-06-08 18:57:22 +0000
+++ b/src/osso-init.c	2007-07-22 20:02:17 +0000
@@ -179,12 +179,14 @@
 /************************************************************************/
 void osso_deinitialize(osso_context_t *osso)
 {
-    if(osso == NULL) return;
+    if (osso == NULL) return;
     
+    LOCK_OR_RETURN(osso->mutex, );
     _dbus_disconnect(osso, FALSE);
     _dbus_disconnect(osso, TRUE);
     
-    _deinit(osso);
+    pthread_mutex_unlock(&osso->mutex);
+    _deinit(osso); /* mutex is destroyed here */
     
     return;
 }
@@ -319,6 +321,7 @@
 static osso_context_t *_init(const gchar *application, const gchar *version)
 {
     osso_context_t *osso;
+    pthread_mutexattr_t mutex_attr;
     
     if (!_validate(application, version)) {
 	ULOG_ERR_F("invalid arguments");
@@ -352,6 +355,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 +366,7 @@
                                    const char *version)
 {
     osso_context_t *osso;
+    pthread_mutexattr_t mutex_attr;
     
     if (!_validate(application, version)) {
 	ULOG_ERR_F("invalid arguments");
@@ -389,6 +397,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 +411,9 @@
     if (osso == NULL) {
 	return;
     }
+
+    LOCK_OR_RETURN(osso->mutex, );
+
     if (osso->uniq_hash != NULL) {
         g_hash_table_destroy(osso->uniq_hash);
     }
@@ -414,11 +429,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 +621,9 @@
     }
 
     ULOG_DEBUG_F("key = '%s'", interface);
+
+    LOCK_OR_RETURN(osso->mutex, DBUS_HANDLER_RESULT_NOT_YET_HANDLED);
+
     elem = g_hash_table_lookup(osso->if_hash, interface);
 
     if (elem != NULL) {
@@ -620,8 +641,10 @@
                 ULOG_DEBUG_F("before calling the handler");
                 ULOG_DEBUG_F(" handler = %p", handler->handler);
                 ULOG_DEBUG_F(" data = %p", handler->data);
+
                 (*handler->handler)(osso, msg, handler->data, 0);
                 ULOG_DEBUG_F("after calling the handler");
+
 #ifdef OSSOLOG_COMPILE
                 found = TRUE;
 #endif
@@ -630,6 +653,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 +821,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 +828,9 @@
     }
     reply_to = dbus_message_get_reply_serial(msg);
 
+    LOCK_OR_RETURN(muali->mutex, 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 +946,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 +1077,8 @@
     handler->can_free_data = can_free_data;
     handler->handler_id = osso->next_handler_id++;
 
+    LOCK_OR_RETURN(osso->mutex, 0);
+
     /* warn about the old element if it exists */
     old = g_hash_table_lookup(osso->uniq_hash, uniq_key);
     if (old != NULL) {
@@ -1069,6 +1098,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 +1106,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 +1119,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 +1156,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 +1175,8 @@
     elem->call_once_per_handler_id = call_once_per_handler_id;
     /* other members are not used and left zero */
 
+    LOCK_OR_RETURN(context->mutex, 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 +1192,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 +1204,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 +1250,12 @@
     GSList *list;
 
     ULOG_DEBUG_F("context=%p", context);
+
+    LOCK_OR_RETURN(context->mutex, 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 +1314,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 +1378,8 @@
 
     compose_hash_key(service, object_path, interface, uniq_key);
 
+    LOCK_OR_RETURN(osso->mutex, FALSE);
+
     elem = g_hash_table_lookup(osso->uniq_hash, uniq_key);
     if (elem != NULL) {
         GSList *list;
@@ -1385,12 +1431,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 file 'src/osso-internal.h'
--- a/src/osso-internal.h	2007-03-30 13:59:04 +0000
+++ b/src/osso-internal.h	2007-07-17 07:14:18 +0000
@@ -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"
@@ -80,6 +82,14 @@
 #define MUALI_MAX_ARGS 256
 #define MUALI_MAX_MATCH_SIZE 256
 
+#define LOCK_OR_RETURN(V, R) \
+    if (pthread_mutex_lock(&V) == EDEADLK) { \
+        ULOG_ERR_F("mutex deadlock detected"); \
+        g_critical("mutex deadlock detected"); \
+        return R; \
+    }
+
+
 typedef struct {
     osso_hw_cb_f *cb;
     gpointer data;
@@ -170,6 +180,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 +211,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 file 'src/osso-mem.c'
--- a/src/osso-mem.c	2007-06-08 18:57:22 +0000
+++ b/src/osso-mem.c	2007-07-22 20:02:17 +0000
@@ -274,23 +274,26 @@
  * ------------------------------------------------------------------------- */
 static void* saw_malloc_hook(size_t size, const void* caller)
 {
-   void* ptr;  /* Allocated pointer, NULL means OOM situation happened */
+   static unsigned count = 0; /* Validation count per number of allocations */
+   void* ptr;       /* Allocated pointer, NULL means OOM situation happened */
 
    THREAD_LOCK();
 
    /* Restore the real malloc hook */
    __malloc_hook = saw_old_malloc_hook;
 
-   /* Check for OOM-potential situation */
-   if (size >= saw_max_block_size)
+   /* Check for OOM-potential situation by size or allocated blocks counter */
+   if (size >= saw_max_block_size || !count)
    {
       /* We must test amount of memory to predict future */
       const struct mallinfo mi = mallinfo();
-      ptr = (mi.arena + mi.hblkhd + size >= saw_max_heap_size ? NULL : malloc(size));
+      ptr = (mi.arena + mi.hblkhd + size >= saw_max_heap_size || osso_mem_in_lowmem_state() ? NULL : malloc(size));
+      count = 1024;
    }
    else
    {
       ptr = malloc(size);
+      count--;
    }
 
    /* Restore malloc hook to self */
@@ -298,8 +301,12 @@
 
    /* Test allocation, call OOM function if necessary  */
    /* Note: SAW may be removed but that is safe for us */
-   if (!ptr && saw_user_oom_func)
-      saw_user_oom_func(saw_max_heap_size + size, saw_max_heap_size, saw_user_context);
+   if ( !ptr )
+   {
+      count = 0;  /* force the next validation */
+      if (saw_user_oom_func)
+         saw_user_oom_func(saw_max_heap_size + size, saw_max_heap_size, saw_user_context);
+   }
 
    THREAD_UNLOCK();
 

=== modified file 'src/osso-rpc.c'
--- a/src/osso-rpc.c	2007-06-08 18:57:22 +0000
+++ b/src/osso-rpc.c	2007-07-22 20:02:17 +0000
@@ -478,6 +478,8 @@
         return OSSO_ERROR;
     }
     
+    LOCK_OR_RETURN(osso->mutex, OSSO_ERROR);
+
     if (strcmp(service, osso->service) != 0
         || (use_system_bus && !osso->systembus_service_registered)
         || (!use_system_bus && !osso->sessionbus_service_registered)) {
@@ -496,10 +498,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 +519,7 @@
             }
         }
     }
+    pthread_mutex_unlock(&osso->mutex);
 
     rpc->user_cb = cb;
     rpc->user_data = data;
@@ -958,7 +963,8 @@
                 int *serial)
 {
         int i;
-        char buf[20], *p;
+        char buf[20];
+        const char *p;
 
         /* get bus type */
         for (i = 0, p = id; *p != ','; ++p, ++i) {
@@ -1371,7 +1377,7 @@
         cb_data->message_id = (long)msg_serial;
 
         cb_data->user_cb = reply_handler;
-        cb_data->user_data = user_data;
+        cb_data->user_data = (gpointer)user_data;
         cb_data->match_rule = NULL;
         cb_data->event_type = 0;
         cb_data->bus_type = bus_type;



More information about the Pkg-maemo-commits mailing list