Author: abroekhuis
Date: Tue Jul 26 06:45:34 2011
New Revision: 1150995

URL: http://svn.apache.org/viewvc?rev=1150995&view=rev
Log:
Updated error handling, fixed a bug in the dependency manager

Modified:
    incubator/celix/trunk/dependency_manager/service_component.c
    incubator/celix/trunk/framework/private/include/bundle.h
    incubator/celix/trunk/framework/private/include/framework.h
    incubator/celix/trunk/framework/private/src/bundle.c
    incubator/celix/trunk/framework/private/src/framework.c

Modified: incubator/celix/trunk/dependency_manager/service_component.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/dependency_manager/service_component.c?rev=1150995&r1=1150994&r2=1150995&view=diff
==============================================================================
--- incubator/celix/trunk/dependency_manager/service_component.c (original)
+++ incubator/celix/trunk/dependency_manager/service_component.c Tue Jul 26 
06:45:34 2011
@@ -447,5 +447,6 @@ void executor_scheduleNext(EXECUTOR exec
        pthread_mutex_unlock(&executor->mutex);
        if (entry != NULL) {
                entry->function(entry->service, entry->argument);
+               executor_scheduleNext(executor);
        }
 }

Modified: incubator/celix/trunk/framework/private/include/bundle.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/bundle.h?rev=1150995&r1=1150994&r2=1150995&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/bundle.h (original)
+++ incubator/celix/trunk/framework/private/include/bundle.h Tue Jul 26 
06:45:34 2011
@@ -35,7 +35,7 @@ celix_status_t bundle_create(BUNDLE * bu
 celix_status_t bundle_createFromArchive(BUNDLE * bundle, FRAMEWORK framework, 
BUNDLE_ARCHIVE archive, apr_pool_t *bundlePool);
 celix_status_t bundle_destroy(BUNDLE bundle);
 
-bool bundle_isSystemBundle(BUNDLE bundle);
+celix_status_t bundle_isSystemBundle(BUNDLE bundle, bool *systemBundle);
 BUNDLE_ARCHIVE bundle_getArchive(BUNDLE bundle);
 MODULE bundle_getCurrentModule(BUNDLE bundle);
 ARRAY_LIST bundle_getModules(BUNDLE bundle);
@@ -49,9 +49,9 @@ BUNDLE_CONTEXT bundle_getContext(BUNDLE 
 void bundle_setContext(BUNDLE bundle, BUNDLE_CONTEXT context);
 celix_status_t bundle_getEntry(BUNDLE bundle, char * name, apr_pool_t *pool, 
char **entry);
 
-void startBundle(BUNDLE bundle, int options);
+celix_status_t startBundle(BUNDLE bundle, int options);
 celix_status_t bundle_update(BUNDLE bundle, char *inputFile);
-void stopBundle(BUNDLE bundle, int options);
+celix_status_t stopBundle(BUNDLE bundle, int options);
 celix_status_t bundle_uninstall(BUNDLE bundle);
 
 void bundle_setState(BUNDLE bundle, BUNDLE_STATE state);
@@ -71,9 +71,9 @@ int compareTo(SERVICE_REFERENCE a, SERVI
 
 
 BUNDLE_STATE bundle_getState(BUNDLE bundle);
-bool bundle_isLockable(BUNDLE bundle);
-pthread_t bundle_getLockingThread(BUNDLE bundle);
-bool bundle_lock(BUNDLE bundle);
+celix_status_t bundle_isLockable(BUNDLE bundle, bool *lockable);
+celix_status_t bundle_getLockingThread(BUNDLE bundle, apr_os_thread_t *thread);
+celix_status_t bundle_lock(BUNDLE bundle, bool *locked);
 celix_status_t bundle_unlock(BUNDLE bundle, bool *unlocked);
 
 celix_status_t bundle_closeAndDelete(BUNDLE bundle);

Modified: incubator/celix/trunk/framework/private/include/framework.h
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/include/framework.h?rev=1150995&r1=1150994&r2=1150995&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/include/framework.h (original)
+++ incubator/celix/trunk/framework/private/include/framework.h Tue Jul 26 
06:45:34 2011
@@ -48,7 +48,7 @@ celix_status_t framework_getBundleEntry(
 
 celix_status_t fw_startBundle(FRAMEWORK framework, BUNDLE bundle, int options);
 celix_status_t framework_updateBundle(FRAMEWORK framework, BUNDLE bundle, char 
*inputFile);
-void fw_stopBundle(FRAMEWORK framework, BUNDLE bundle, bool record);
+celix_status_t fw_stopBundle(FRAMEWORK framework, BUNDLE bundle, bool record);
 
 celix_status_t fw_registerService(FRAMEWORK framework, SERVICE_REGISTRATION * 
registration, BUNDLE bundle, char * serviceName, void * svcObj, PROPERTIES 
properties);
 celix_status_t fw_registerServiceFactory(FRAMEWORK framework, 
SERVICE_REGISTRATION * registration, BUNDLE bundle, char * serviceName, 
service_factory_t factory, PROPERTIES properties);

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1150995&r1=1150994&r2=1150995&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Tue Jul 26 06:45:34 
2011
@@ -150,36 +150,43 @@ ACTIVATOR bundle_getActivator(BUNDLE bun
        return bundle->activator;
 }
 
-void bundle_setActivator(BUNDLE bundle, ACTIVATOR activator) {
+celix_status_t bundle_setActivator(BUNDLE bundle, ACTIVATOR activator) {
        bundle->activator = activator;
+       return CELIX_SUCCESS;
 }
 
-BUNDLE_CONTEXT bundle_getContext(BUNDLE bundle) {
-       return bundle->context;
+celix_status_t bundle_getContext(BUNDLE bundle, BUNDLE_CONTEXT *context) {
+       *context = bundle->context;
+       return CELIX_SUCCESS;
 }
 
-void bundle_setContext(BUNDLE bundle, BUNDLE_CONTEXT context) {
+celix_status_t bundle_setContext(BUNDLE bundle, BUNDLE_CONTEXT context) {
        bundle->context = context;
+       return CELIX_SUCCESS;
 }
 
 celix_status_t bundle_getEntry(BUNDLE bundle, char * name, apr_pool_t *pool, 
char **entry) {
        return framework_getBundleEntry(bundle->framework, bundle, name, pool, 
entry);
 }
 
-BUNDLE_STATE bundle_getState(BUNDLE bundle) {
-       return bundle->state;
+celix_status_t bundle_getState(BUNDLE bundle, BUNDLE_STATE *state) {
+       *state = bundle->state;
+       return CELIX_SUCCESS;
 }
 
-void bundle_setState(BUNDLE bundle, BUNDLE_STATE state) {
+celix_status_t bundle_setState(BUNDLE bundle, BUNDLE_STATE state) {
        bundle->state = state;
+       return CELIX_SUCCESS;
 }
 
-MANIFEST bundle_getManifest(BUNDLE bundle) {
-       return bundle->manifest;
+celix_status_t bundle_getManifest(BUNDLE bundle, MANIFEST *manifest) {
+       *manifest = bundle->manifest;
+       return CELIX_SUCCESS;
 }
 
-void bundle_setManifest(BUNDLE bundle, MANIFEST manifest) {
+celix_status_t bundle_setManifest(BUNDLE bundle, MANIFEST manifest) {
        bundle->manifest = manifest;
+       return CELIX_SUCCESS;
 }
 
 celix_status_t bundle_createModule(BUNDLE bundle, MODULE *module) {
@@ -227,40 +234,52 @@ celix_status_t bundle_createModule(BUNDL
        return status;
 }
 
-void startBundle(BUNDLE bundle, int options) {
+celix_status_t startBundle(BUNDLE bundle, int options) {
+       celix_status_t status = CELIX_SUCCESS;
     if (bundle != NULL) {
-        fw_startBundle(bundle->framework, bundle, options);
+        status = fw_startBundle(bundle->framework, bundle, options);
     }
+    return status;
 }
 
 celix_status_t bundle_update(BUNDLE bundle, char *inputFile) {
        return framework_updateBundle(bundle->framework, bundle, inputFile);
 }
 
-void stopBundle(BUNDLE bundle, int options) {
-       fw_stopBundle(bundle->framework, bundle, ((options & 1) == 0));
+celix_status_t stopBundle(BUNDLE bundle, int options) {
+       return fw_stopBundle(bundle->framework, bundle, ((options & 1) == 0));
 }
 
 celix_status_t bundle_uninstall(BUNDLE bundle) {
-    celix_status_t status = CELIX_SUCCESS;
-
-    fw_uninstallBundle(bundle->framework, bundle);
-
-    return status;
+    return fw_uninstallBundle(bundle->framework, bundle);
 }
 
 celix_status_t bundle_setPersistentStateInactive(BUNDLE bundle) {
-       if (!bundle_isSystemBundle(bundle)) {
-               bundleArchive_setPersistentState(bundle->archive, 
BUNDLE_INSTALLED);
+       celix_status_t status = CELIX_SUCCESS;
+       bool systemBundle;
+
+       status = bundle_isSystemBundle(bundle, &systemBundle);
+       if (status == CELIX_SUCCESS) {
+               if (!systemBundle) {
+                       status = 
bundleArchive_setPersistentState(bundle->archive, BUNDLE_INSTALLED);
+               }
        }
-       return CELIX_SUCCESS;
+
+       return status;
 }
 
 celix_status_t bundle_setPersistentStateUninstalled(BUNDLE bundle) {
-    if (!bundle_isSystemBundle(bundle)) {
-        bundleArchive_setPersistentState(bundle->archive, BUNDLE_UNINSTALLED);
-    }
-    return CELIX_SUCCESS;
+       celix_status_t status = CELIX_SUCCESS;
+       bool systemBundle;
+
+       status = bundle_isSystemBundle(bundle, &systemBundle);
+       if (status == CELIX_SUCCESS) {
+               if (!systemBundle) {
+                       status = 
bundleArchive_setPersistentState(bundle->archive, BUNDLE_UNINSTALLED);
+               }
+       }
+
+    return status;
 }
 
 celix_status_t bundle_isUsed(BUNDLE bundle, bool *used) {
@@ -313,48 +332,80 @@ celix_status_t bundle_addModule(BUNDLE b
        return CELIX_SUCCESS;
 }
 
-bool bundle_isSystemBundle(BUNDLE bundle) {
+celix_status_t bundle_isSystemBundle(BUNDLE bundle, bool *systemBundle) {
+       celix_status_t status = CELIX_SUCCESS;
        long bundleId;
-       bundleArchive_getId(bundle_getArchive(bundle), &bundleId);
-       return bundleId == 0;
+
+       status = bundleArchive_getId(bundle_getArchive(bundle), &bundleId);
+       if (status == CELIX_SUCCESS) {
+               *systemBundle = (bundleId == 0);
+       }
+
+       return status;
 }
 
-bool bundle_isLockable(BUNDLE bundle) {
-       bool lockable = false;
-       apr_thread_mutex_lock(bundle->lock);
+celix_status_t bundle_isLockable(BUNDLE bundle, bool *lockable) {
+       celix_status_t status = CELIX_SUCCESS;
+       apr_status_t apr_status;
 
-       lockable = (bundle->lockCount == 0) || (bundle->lockThread == 
pthread_self());
+       apr_status = apr_thread_mutex_lock(bundle->lock);
+       if (apr_status != APR_SUCCESS) {
+               status = CELIX_BUNDLE_EXCEPTION;
+       } else {
+               bool equals;
+               status = thread_equalsSelf(bundle->lockThread, &equals);
+               if (status == CELIX_SUCCESS) {
+                       *lockable = (bundle->lockCount == 0) || (equals);
+               }
 
-       apr_thread_mutex_unlock(bundle->lock);
+               apr_status = apr_thread_mutex_unlock(bundle->lock);
+               if (apr_status != APR_SUCCESS) {
+                       status = CELIX_BUNDLE_EXCEPTION;
+               }
+       }
 
-       return lockable;
+       return status;
 }
 
-pthread_t bundle_getLockingThread(BUNDLE bundle) {
-       pthread_t lockingThread = NULL;
-       apr_thread_mutex_lock(bundle->lock);
+celix_status_t bundle_getLockingThread(BUNDLE bundle, apr_os_thread_t *thread) 
{
+       celix_status_t status = CELIX_SUCCESS;
+       apr_status_t apr_status;
 
-       lockingThread = bundle->lockThread;
+       apr_status = apr_thread_mutex_lock(bundle->lock);
+       if (apr_status != APR_SUCCESS) {
+               status = CELIX_BUNDLE_EXCEPTION;
+       } else {
+               *thread = bundle->lockThread;
 
-       apr_thread_mutex_unlock(bundle->lock);
+               apr_status = apr_thread_mutex_unlock(bundle->lock);
+               if (apr_status != APR_SUCCESS) {
+                       status = CELIX_BUNDLE_EXCEPTION;
+               }
+       }
 
-       return lockingThread;
+       return status;
 }
 
-bool bundle_lock(BUNDLE bundle) {
-       apr_thread_mutex_lock(bundle->lock);
+celix_status_t bundle_lock(BUNDLE bundle, bool *locked) {
+       celix_status_t status = CELIX_SUCCESS;
        bool equals;
 
-       thread_equalsSelf(bundle->lockThread, &equals);
-       if ((bundle->lockCount > 0) && !equals) {
-               apr_thread_mutex_unlock(bundle->lock);
-               return false;
+       apr_thread_mutex_lock(bundle->lock);
+
+       status = thread_equalsSelf(bundle->lockThread, &equals);
+       if (status == CELIX_SUCCESS) {
+               if ((bundle->lockCount > 0) && !equals) {
+                       *locked = false;
+               } else {
+                       bundle->lockCount++;
+                       bundle->lockThread = apr_os_thread_current();
+                       *locked = true;
+               }
        }
-       bundle->lockCount++;
-       bundle->lockThread = apr_os_thread_current();
 
        apr_thread_mutex_unlock(bundle->lock);
-       return true;
+
+       return status;
 }
 
 celix_status_t bundle_unlock(BUNDLE bundle, bool *unlocked) {
@@ -367,15 +418,17 @@ celix_status_t bundle_unlock(BUNDLE bund
        if ((bundle->lockCount == 0)) {
                *unlocked = false;
        } else {
-               thread_equalsSelf(bundle->lockThread, &equals);
-               if ((bundle->lockCount > 0) && !equals) {
-                       return false;
-               }
-               bundle->lockCount--;
-               if (bundle->lockCount == 0) {
-                       bundle->lockThread = NULL;
+               status = thread_equalsSelf(bundle->lockThread, &equals);
+               if (status == CELIX_SUCCESS) {
+                       if ((bundle->lockCount > 0) && !equals) {
+                               return false;
+                       }
+                       bundle->lockCount--;
+                       if (bundle->lockCount == 0) {
+                               bundle->lockThread = NULL;
+                       }
+                       *unlocked = true;
                }
-               *unlocked = true;
        }
 
        apr_thread_mutex_unlock(bundle->lock);

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: 
http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1150995&r1=1150994&r2=1150995&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue Jul 26 06:45:34 
2011
@@ -609,74 +609,78 @@ celix_status_t framework_updateBundle(FR
        return CELIX_SUCCESS;
 }
 
-void fw_stopBundle(FRAMEWORK framework, BUNDLE bundle, bool record) {
-       celix_status_t lock = framework_acquireBundleLock(framework, bundle, 
BUNDLE_INSTALLED|BUNDLE_RESOLVED|BUNDLE_STARTING|BUNDLE_ACTIVE);
-       if (lock != CELIX_SUCCESS) {
+celix_status_t fw_stopBundle(FRAMEWORK framework, BUNDLE bundle, bool record) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       status = framework_acquireBundleLock(framework, bundle, 
BUNDLE_INSTALLED|BUNDLE_RESOLVED|BUNDLE_STARTING|BUNDLE_ACTIVE);
+       if (status != CELIX_SUCCESS) {
                printf("Cannot stop bundle");
                framework_releaseBundleLock(framework, bundle);
-               return;
-       }
+       } else {
 
-       if (record) {
-               bundle_setPersistentStateInactive(bundle);
-       }
+               if (record) {
+                       bundle_setPersistentStateInactive(bundle);
+               }
 
-       //if (!fw_isBundlePersistentlyStarted(framework, bundle)) {
-       //}
-
-       switch (bundle_getState(bundle)) {
-               case BUNDLE_UNINSTALLED:
-                       printf("Cannot stop bundle since it is uninstalled.");
-                       framework_releaseBundleLock(framework, bundle);
-                       return;
-               case BUNDLE_STARTING:
-                       printf("Cannot stop bundle since it is starting.");
-                       framework_releaseBundleLock(framework, bundle);
-                       return;
-               case BUNDLE_STOPPING:
-                       printf("Cannot stop bundle since it is stopping.");
-                       framework_releaseBundleLock(framework, bundle);
-                       return;
-               case BUNDLE_INSTALLED:
-               case BUNDLE_RESOLVED:
-                       framework_releaseBundleLock(framework, bundle);
-                       return;
-               case BUNDLE_ACTIVE:
-                       // only valid state
-                       break;
-       }
+               //if (!fw_isBundlePersistentlyStarted(framework, bundle)) {
+               //}
 
-       framework_setBundleStateAndNotify(framework, bundle, BUNDLE_STOPPING);
+               switch (bundle_getState(bundle)) {
+                       case BUNDLE_UNINSTALLED:
+                               printf("Cannot stop bundle since it is 
uninstalled.");
+                               framework_releaseBundleLock(framework, bundle);
+                               return status;
+                       case BUNDLE_STARTING:
+                               printf("Cannot stop bundle since it is 
starting.");
+                               framework_releaseBundleLock(framework, bundle);
+                               return status;
+                       case BUNDLE_STOPPING:
+                               printf("Cannot stop bundle since it is 
stopping.");
+                               framework_releaseBundleLock(framework, bundle);
+                               return status;
+                       case BUNDLE_INSTALLED:
+                       case BUNDLE_RESOLVED:
+                               framework_releaseBundleLock(framework, bundle);
+                               return status;
+                       case BUNDLE_ACTIVE:
+                               // only valid state
+                               break;
+               }
 
-       ACTIVATOR activator = bundle_getActivator(bundle);
-       if (activator->stop != NULL) {
-               activator->stop(activator->userData, bundle_getContext(bundle));
-       }
+               framework_setBundleStateAndNotify(framework, bundle, 
BUNDLE_STOPPING);
 
-       if (activator->destroy != NULL) {
-               activator->destroy(activator->userData, 
bundle_getContext(bundle));
-       }
+               ACTIVATOR activator = bundle_getActivator(bundle);
+               if (activator->stop != NULL) {
+                       activator->stop(activator->userData, 
bundle_getContext(bundle));
+               }
 
-       if (strcmp(module_getId(bundle_getCurrentModule(bundle)), "0") != 0) {
-               activator->start = NULL;
-               activator->stop = NULL;
-               activator->userData = NULL;
-               //free(activator);
-               bundle_setActivator(bundle, NULL);
+               if (activator->destroy != NULL) {
+                       activator->destroy(activator->userData, 
bundle_getContext(bundle));
+               }
 
-               serviceRegistry_unregisterServices(framework->registry, bundle);
-               serviceRegistry_ungetServices(framework->registry, bundle);
+               if (strcmp(module_getId(bundle_getCurrentModule(bundle)), "0") 
!= 0) {
+                       activator->start = NULL;
+                       activator->stop = NULL;
+                       activator->userData = NULL;
+                       //free(activator);
+                       bundle_setActivator(bundle, NULL);
 
-               dlclose(bundle_getHandle(bundle));
-       }
+                       serviceRegistry_unregisterServices(framework->registry, 
bundle);
+                       serviceRegistry_ungetServices(framework->registry, 
bundle);
+
+                       dlclose(bundle_getHandle(bundle));
+               }
 
-       bundleContext_destroy(bundle_getContext(bundle));
-       bundle_setContext(bundle, NULL);
-       manifest_destroy(bundle_getManifest(bundle));
+               bundleContext_destroy(bundle_getContext(bundle));
+               bundle_setContext(bundle, NULL);
+               manifest_destroy(bundle_getManifest(bundle));
 
-       framework_setBundleStateAndNotify(framework, bundle, BUNDLE_RESOLVED);
+               framework_setBundleStateAndNotify(framework, bundle, 
BUNDLE_RESOLVED);
 
-       framework_releaseBundleLock(framework, bundle);
+               framework_releaseBundleLock(framework, bundle);
+       }
+
+       return status;
 }
 
 celix_status_t fw_uninstallBundle(FRAMEWORK framework, BUNDLE bundle) {
@@ -1172,53 +1176,72 @@ celix_status_t framework_setBundleStateA
 }
 
 celix_status_t framework_acquireBundleLock(FRAMEWORK framework, BUNDLE bundle, 
int desiredStates) {
+       celix_status_t status = CELIX_SUCCESS;
+
+       bool locked;
+       apr_os_thread_t lockingThread = NULL;
+
        int err = apr_thread_mutex_lock(framework->bundleLock);
-       if (err != 0) {
+       if (err != APR_SUCCESS) {
                celix_log("Failed to lock");
-               return CELIX_BUNDLE_EXCEPTION;
-       }
-
-       while (!bundle_isLockable(bundle)
-                       || ((framework->globalLockThread != NULL)
-                       && (framework->globalLockThread != pthread_self()))) {
-               if ((desiredStates & bundle_getState(bundle)) == 0) {
-                   apr_thread_mutex_unlock(framework->bundleLock);
-                       return CELIX_ILLEGAL_STATE;
-               } else if (framework->globalLockThread == pthread_self()
-                               && (bundle_getLockingThread(bundle) != NULL)
-                               && 
arrayList_contains(framework->globalLockWaitersList, 
bundle_getLockingThread(bundle))) {
-                       framework->interrupted = true;
-//                     pthread_cond_signal_thread_np(&framework->condition, 
bundle_getLockingThread(bundle));
-                       apr_thread_cond_signal(framework->condition);
-               }
+               status = CELIX_BUNDLE_EXCEPTION;
+       } else {
+               bool lockable = false;
+               bundle_isLockable(bundle, &lockable);
+               while (!lockable
+                               || ((framework->globalLockThread != NULL)
+                               && (framework->globalLockThread != 
pthread_self()))) {
+                       if ((desiredStates & bundle_getState(bundle)) == 0) {
+                               status = CELIX_ILLEGAL_STATE;
+                               break;
+                       } else
+                               bundle_getLockingThread(bundle, &lockingThread);
+                               if (framework->globalLockThread == 
pthread_self()
+                                       && (lockingThread != NULL)
+                                       && 
arrayList_contains(framework->globalLockWaitersList, lockingThread)) {
+                               framework->interrupted = true;
+       //                      
pthread_cond_signal_thread_np(&framework->condition, 
bundle_getLockingThread(bundle));
+                               apr_thread_cond_signal(framework->condition);
+                       }
 
-               apr_thread_cond_wait(framework->condition, 
framework->bundleLock);
-       }
+                       apr_thread_cond_wait(framework->condition, 
framework->bundleLock);
 
-       if ((desiredStates & bundle_getState(bundle)) == 0) {
-           apr_thread_mutex_unlock(framework->bundleLock);
-               return CELIX_ILLEGAL_STATE;
-       }
+                       status = bundle_isLockable(bundle, &lockable);
+                       if (status != CELIX_SUCCESS) {
+                               break;
+                       }
+               }
 
-       if (!bundle_lock(bundle)) {
-           apr_thread_mutex_unlock(framework->bundleLock);
-               return CELIX_ILLEGAL_STATE;
+               if (status == CELIX_SUCCESS) {
+                       if ((desiredStates & bundle_getState(bundle)) == 0) {
+                               status = CELIX_ILLEGAL_STATE;
+                       } else {
+                               if (bundle_lock(bundle, &locked)) {
+                                       if (!locked) {
+                                               status = CELIX_ILLEGAL_STATE;
+                                       }
+                               }
+                       }
+               }
+               apr_thread_mutex_unlock(framework->bundleLock);
        }
 
-       apr_thread_mutex_unlock(framework->bundleLock);
        return CELIX_SUCCESS;
 }
 
 bool framework_releaseBundleLock(FRAMEWORK framework, BUNDLE bundle) {
-    apr_thread_mutex_lock(framework->bundleLock);
     bool unlocked;
+    apr_os_thread_t lockingThread = NULL;
+
+    apr_thread_mutex_lock(framework->bundleLock);
 
     bundle_unlock(bundle, &unlocked);
        if (!unlocked) {
            apr_thread_mutex_unlock(framework->bundleLock);
                return false;
        }
-       if (bundle_getLockingThread(bundle) == NULL) {
+       bundle_getLockingThread(bundle, &lockingThread);
+       if (lockingThread == NULL) {
            apr_thread_cond_broadcast(framework->condition);
        }
 


Reply via email to