incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1545574 - in /incubator/celix/trunk/framework/private/src: bundle.c bundle_archive.c bundle_cache.c framework.c
Date Tue, 26 Nov 2013 09:05:22 GMT
Author: abroekhuis
Date: Tue Nov 26 09:05:21 2013
New Revision: 1545574

URL: http://svn.apache.org/r1545574
Log:
Small updates wrt memory and pool usage.

Modified:
    incubator/celix/trunk/framework/private/src/bundle.c
    incubator/celix/trunk/framework/private/src/bundle_archive.c
    incubator/celix/trunk/framework/private/src/bundle_cache.c
    incubator/celix/trunk/framework/private/src/framework.c

Modified: incubator/celix/trunk/framework/private/src/bundle.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle.c?rev=1545574&r1=1545573&r2=1545574&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle.c Tue Nov 26 09:05:21 2013
@@ -109,7 +109,7 @@ celix_status_t bundle_createFromArchive(
 	status = bundle_createModule(*bundle, &module);
 	if (status == CELIX_SUCCESS) {
         apr_status_t apr_status;
-		
+
 		bundle_addModule(*bundle, module);
         apr_status = apr_thread_mutex_create(&(*bundle)->lock, APR_THREAD_MUTEX_UNNESTED,
(*bundle)->memoryPool);
         if (apr_status != APR_SUCCESS) {
@@ -137,6 +137,9 @@ celix_status_t bundle_destroy(bundle_pt 
 	}
 	arrayListIterator_destroy(iter);
 	arrayList_destroy(bundle->modules);
+	apr_thread_mutex_destroy(bundle->lock);
+
+	apr_pool_destroy(bundle->memoryPool);
 	return CELIX_SUCCESS;
 }
 

Modified: incubator/celix/trunk/framework/private/src/bundle_archive.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_archive.c?rev=1545574&r1=1545573&r2=1545574&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_archive.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_archive.c Tue Nov 26 09:05:21 2013
@@ -151,11 +151,6 @@ celix_status_t bundleArchive_create(char
 static apr_status_t bundleArchive_destroy(void *archiveP) {
     apr_status_t status = APR_SUCCESS;
 	bundle_archive_pt archive = archiveP;
-	if (archive != NULL) {
-		if (archive->archiveRootDir != NULL) {
-			status = apr_dir_close(archive->archiveRootDir);
-		}
-	}
 	archive = NULL;
 
 	framework_logIfError(status, NULL, "Could not create archive");
@@ -748,39 +743,35 @@ static celix_status_t bundleArchive_init
 		if (apr_dir_make(archive->archiveRoot, APR_UREAD|APR_UWRITE|APR_UEXECUTE, archive->mp)
!= APR_SUCCESS) {
 			status = CELIX_FILE_IO_EXCEPTION;
 		} else {
-			apr_status_t apr_status = apr_dir_open(&archive->archiveRootDir, archive->archiveRoot,
archive->mp);
+            apr_pool_t *spool = NULL;
+
+		    apr_pool_create(&spool, archive->mp);
+			apr_status_t apr_status = apr_dir_open(&archive->archiveRootDir, archive->archiveRoot,
spool);
 			if (apr_status != APR_SUCCESS) {
 				status = CELIX_FILE_IO_EXCEPTION;
 			} else {
 				apr_file_t *bundleIdFile;
 				apr_status_t apr_status;
-				apr_pool_t *spool = NULL;
 				char *bundleId = NULL;
 
-				apr_pool_create(&spool, archive->mp);
 				bundleId = (char *)apr_palloc(spool, sizeof(*bundleId) * (strlen(archive->archiveRoot)
+ 11));
 				bundleId = apr_pstrcat(spool, archive->archiveRoot, "/bundle.id", NULL);
-				
-				apr_status = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_CREATE|APR_FOPEN_WRITE,
APR_OS_DEFAULT, archive->mp);
-				apr_pool_destroy(spool);
 
+				apr_status = apr_file_open(&bundleIdFile, bundleId, APR_FOPEN_CREATE|APR_FOPEN_WRITE,
APR_OS_DEFAULT, spool);
 				if (apr_status != APR_SUCCESS) {
 					status = CELIX_FILE_IO_EXCEPTION;
 				} else {
 					char * bundleLocation;
 					apr_file_t *bundleLocationFile;
-					apr_pool_t *subpool = NULL;
 
 					apr_file_printf(bundleIdFile, "%ld", archive->id);
 					// Ignore close status, let it fail if needed again
 					apr_file_close(bundleIdFile);
-					apr_pool_create(&subpool, archive->mp);
 
-					bundleLocation = (char *) apr_palloc(subpool, strlen(archive->archiveRoot) + 17);
-					strcpy(bundleLocation,archive->archiveRoot);
-					strcat(bundleLocation, "/bundle.location");
-					
-					apr_status = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE,
APR_OS_DEFAULT, archive->mp);
+					bundleLocation = (char *) apr_palloc(spool, strlen(archive->archiveRoot) + 17);
+					bundleLocation = apr_pstrcat(spool, archive->archiveRoot, "/bundle.location", NULL);
+
+					apr_status = apr_file_open(&bundleLocationFile, bundleLocation, APR_FOPEN_CREATE|APR_FOPEN_WRITE,
APR_OS_DEFAULT, spool);
 					if (apr_status != APR_SUCCESS) {
 						status = CELIX_FILE_IO_EXCEPTION;
 					} else {
@@ -790,9 +781,10 @@ static celix_status_t bundleArchive_init
 
 						status = bundleArchive_writeLastModified(archive);
 					}
-					apr_pool_destroy(subpool);
 				}
+				status = apr_dir_close(archive->archiveRootDir);
 			}
+            apr_pool_destroy(spool);
 		}
 	}
 

Modified: incubator/celix/trunk/framework/private/src/bundle_cache.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/bundle_cache.c?rev=1545574&r1=1545573&r2=1545574&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/bundle_cache.c (original)
+++ incubator/celix/trunk/framework/private/src/bundle_cache.c Tue Nov 26 09:05:21 2013
@@ -144,7 +144,6 @@ celix_status_t bundleCache_createArchive
 
 	if (cache && location && bundlePool) {
 		archiveRoot = apr_psprintf(bundlePool, "%s/bundle%ld",  cache->cacheDir, id);
-
         status = bundleArchive_create(archiveRoot, id, location, inputFile, bundlePool, bundle_archive);
 	}
 

Modified: incubator/celix/trunk/framework/private/src/framework.c
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/src/framework.c?rev=1545574&r1=1545573&r2=1545574&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/src/framework.c (original)
+++ incubator/celix/trunk/framework/private/src/framework.c Tue Nov 26 09:05:21 2013
@@ -190,7 +190,9 @@ celix_status_t framework_create(framewor
             (*framework)->shutdownGate = NULL;
             (*framework)->configurationMap = config;
 
-            status = CELIX_DO_IF(status, bundle_create(&(*framework)->bundle, (*framework)->mp));
+            apr_pool_t *pool = NULL;
+            apr_pool_create(&pool, (*framework)->mp);
+            status = CELIX_DO_IF(status, bundle_create(&(*framework)->bundle, pool));
             status = CELIX_DO_IF(status, arrayList_create((*framework)->mp, &(*framework)->globalLockWaitersList));
             status = CELIX_DO_IF(status, bundle_setFramework((*framework)->bundle, (*framework)));
             if (status == CELIX_SUCCESS) {
@@ -504,7 +506,7 @@ celix_status_t fw_installBundle2(framewo
         }
   	}
 
-  	if (status == CELIX_SUCCESS) {
+    if (status == CELIX_SUCCESS) {
         *bundle = framework_getBundle(framework, location);
         if (*bundle != NULL) {
             framework_releaseInstallLock(framework, location);
@@ -537,11 +539,10 @@ celix_status_t fw_installBundle2(framewo
                 }
             }
         }
-        status = CELIX_DO_IF(status, framework_releaseInstallLock(framework, location));
-  	}
+    }
+    status = CELIX_DO_IF(status, framework_releaseInstallLock(framework, location));
 
     if (status != CELIX_SUCCESS) {
-        status = CELIX_DO_IF(status, framework_releaseInstallLock(framework, location));
     	fw_logCode(FW_LOG_ERROR, status, "Could not install bundle");
     } else {
         status = CELIX_DO_IF(status, fw_fireBundleEvent(framework, BUNDLE_EVENT_INSTALLED,
*bundle));
@@ -671,10 +672,10 @@ celix_status_t fw_startBundle(framework_
                     // apr_dso_load(&handle, libraryPath, bundle->memoryPool);
                     handle = fw_openLibrary(libraryPath);
                     if (handle == NULL) {
-                        char err[256];
+                        char err[1024];
                         sprintf(err, "library could not be opened: %s", fw_getLastError());
                         // #TODO this is wrong
-                        // error = err;
+                        error = err;
                         status =  CELIX_BUNDLE_EXCEPTION;
                     }
 
@@ -890,7 +891,7 @@ celix_status_t fw_stopBundle(framework_p
                 // #TODO remove listeners for bundle
 
                 // #TODO enable dlclose call
-//              dlclose(bundle_getHandle(bundle));
+              dlclose(bundle_getHandle(bundle));
 
                 if (context != NULL) {
                     status = CELIX_DO_IF(status, bundleContext_destroy(context));
@@ -990,14 +991,14 @@ celix_status_t fw_uninstallBundle(framew
 
 
     if (status != CELIX_SUCCESS) {
-        module_pt module = NULL;
-        char *symbolicName = NULL;
-        long id = 0;
-        bundle_getCurrentModule(bundle, &module);
-        module_getSymbolicName(module, &symbolicName);
-        bundle_getBundleId(bundle, &id);
+//        module_pt module = NULL;
+//        char *symbolicName = NULL;
+//        long id = 0;
+//        bundle_getCurrentModule(bundle, &module);
+//        module_getSymbolicName(module, &symbolicName);
+//        bundle_getBundleId(bundle, &id);
 
-        framework_logIfError(status, error, "Cannot uninstall bundle: %s [%ld]", symbolicName,
id);
+        framework_logIfError(status, error, "Cannot uninstall bundle");
     }
 
     return status;
@@ -2186,7 +2187,7 @@ celix_status_t bundleActivator_stop(void
 
 	    fw_log(FW_LOG_INFO, "FRAMEWORK: Start shutdownthread");
 	    if (apr_thread_create(&shutdownThread, NULL, framework_shutdown, framework, framework->mp)
== APR_SUCCESS) {
-            apr_thread_detach(shutdownThread);
+            apr_thread_join(&status, shutdownThread);
 	    } else {
             fw_log(FW_LOG_ERROR,  "Could not create shutdown thread, normal exit not possible.");
 	        status = CELIX_FRAMEWORK_EXCEPTION;



Mime
View raw message