celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1644359 - in /celix/trunk: log_service/private/src/log.c utils/private/src/celix_threads.c utils/public/include/celix_threads.h
Date Wed, 10 Dec 2014 09:49:38 GMT
Author: abroekhuis
Date: Wed Dec 10 09:49:37 2014
New Revision: 1644359

URL: http://svn.apache.org/r1644359
Log:
CELIX-119: Updates to logservice.

Modified:
    celix/trunk/log_service/private/src/log.c
    celix/trunk/utils/private/src/celix_threads.c
    celix/trunk/utils/public/include/celix_threads.h

Modified: celix/trunk/log_service/private/src/log.c
URL: http://svn.apache.org/viewvc/celix/trunk/log_service/private/src/log.c?rev=1644359&r1=1644358&r2=1644359&view=diff
==============================================================================
--- celix/trunk/log_service/private/src/log.c (original)
+++ celix/trunk/log_service/private/src/log.c Wed Dec 10 09:49:37 2014
@@ -90,6 +90,7 @@ celix_status_t log_destroy(log_pt logger
 
 	celixThreadMutex_destroy(&logger->listenerLock);
 	celixThreadMutex_destroy(&logger->deliverLock);
+	celixThreadCondition_destroy(&logger->entriesToDeliver);
 
 	arrayList_destroy(logger->listenerEntries);
 	arrayList_destroy(logger->listeners);
@@ -196,22 +197,25 @@ celix_status_t log_frameworkEvent(void *
 celix_status_t log_addLogListener(log_pt logger, log_listener_pt listener) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	celixThreadMutex_lock(&logger->listenerLock);
+	status = celixThreadMutex_lock(&logger->listenerLock);
 
-	arrayList_add(logger->listeners, listener);
-	log_startListenerThread(logger);
+	if (status == CELIX_SUCCESS) {
+		arrayList_add(logger->listeners, listener);
+		log_startListenerThread(logger);
 
-	celixThreadMutex_unlock(&logger->listenerLock);
+		status = celixThreadMutex_unlock(&logger->listenerLock);
+	}
 
 	return status;
 }
 
 celix_status_t log_removeLogListener(log_pt logger, log_listener_pt listener) {
 	celix_status_t status = CELIX_SUCCESS;
+    celix_status_t threadStatus = CELIX_SUCCESS;
 	bool last = false;
 
-	celixThreadMutex_lock(&logger->deliverLock);
-	celixThreadMutex_lock(&logger->listenerLock);
+    status = CELIX_DO_IF(status, celixThreadMutex_lock(&logger->deliverLock));
+    status = CELIX_DO_IF(status, celixThreadMutex_lock(&logger->listenerLock));
 
 	if (status == CELIX_SUCCESS) {
 		arrayList_removeElement(logger->listeners, listener);
@@ -220,11 +224,11 @@ celix_status_t log_removeLogListener(log
 			last = true;
 		}
 
-		celixThreadMutex_unlock(&logger->listenerLock);
-		celixThreadMutex_unlock(&logger->deliverLock);
+        status = CELIX_DO_IF(status, celixThreadMutex_unlock(&logger->listenerLock));
+        status = CELIX_DO_IF(status, celixThreadMutex_unlock(&logger->deliverLock));
 
 		if (last) {
-			celixThread_join(logger->listenerThread, NULL);
+		    status = CELIX_DO_IF(status, celixThread_join(logger->listenerThread, &threadStatus));
 		}
 
 		if (status == CELIX_SUCCESS) {
@@ -242,11 +246,13 @@ celix_status_t log_removeLogListener(log
 celix_status_t log_removeAllLogListener(log_pt logger) {
 	celix_status_t status = CELIX_SUCCESS;
 
-	celixThreadMutex_lock(&logger->listenerLock);
+	status = celixThreadMutex_lock(&logger->listenerLock);
 
-	arrayList_clear(logger->listeners);
+    if (status == CELIX_SUCCESS) {
+    	arrayList_clear(logger->listeners);
 
-	celixThreadMutex_unlock(&logger->listenerLock);
+    	status = celixThreadMutex_unlock(&logger->listenerLock);
+    }
 
 	return status;
 }
@@ -255,8 +261,8 @@ static celix_status_t log_startListenerT
 	celix_status_t status = CELIX_SUCCESS;
 
 	logger->running = true;
-
-	status = celixThread_create(&logger->listenerThread, NULL, &log_listenerThread,
logger);
+    logger->running = true;
+    status = celixThread_create(&logger->listenerThread, NULL, log_listenerThread,
logger);
 
 	return status;
 }
@@ -287,21 +293,24 @@ static void * log_listenerThread(void *d
 			if (!arrayList_isEmpty(logger->listenerEntries)) {
 				log_entry_pt entry = (log_entry_pt) arrayList_remove(logger->listenerEntries, 0);
 
-				status = celixThreadMutex_lock(&logger->listenerLock);
-				if (status != CELIX_SUCCESS) {
-					logger->running = false;
-				} else {
-					array_list_iterator_pt it = arrayListIterator_create(logger->listeners);
-					while (arrayListIterator_hasNext(it)) {
-						log_listener_pt listener = arrayListIterator_next(it);
-						listener->logged(listener, entry);
-					}
-					arrayListIterator_destroy(it);
-
-					status = celixThreadMutex_unlock(&logger->listenerLock);
+				if (entry) {
+					status = celixThreadMutex_lock(&logger->listenerLock);
 					if (status != CELIX_SUCCESS) {
 						logger->running = false;
 						break;
+					} else {
+						array_list_iterator_pt it = arrayListIterator_create(logger->listeners);
+						while (arrayListIterator_hasNext(it)) {
+							log_listener_pt listener = arrayListIterator_next(it);
+							listener->logged(listener, entry);
+						}
+						arrayListIterator_destroy(it);
+
+						status = celixThreadMutex_unlock(&logger->listenerLock);
+						if (status != CELIX_SUCCESS) {
+							logger->running = false;
+							break;
+						}
 					}
 				}
 			}
@@ -314,9 +323,12 @@ static void * log_listenerThread(void *d
 
 			if (status != CELIX_SUCCESS) {
 				logger->running = false;
+				break;
 			}
 		}
 
 	}
-	return NULL;
+
+    celixThread_exit(status);
+    return NULL;
 }

Modified: celix/trunk/utils/private/src/celix_threads.c
URL: http://svn.apache.org/viewvc/celix/trunk/utils/private/src/celix_threads.c?rev=1644359&r1=1644358&r2=1644359&view=diff
==============================================================================
--- celix/trunk/utils/private/src/celix_threads.c (original)
+++ celix/trunk/utils/private/src/celix_threads.c Wed Dec 10 09:49:37 2014
@@ -102,6 +102,10 @@ celix_status_t celixThreadCondition_init
     return pthread_cond_init(condition, attr);
 }
 
+celix_status_t celixThreadCondition_destroy(celix_thread_cond_t *condition) {
+    return pthread_cond_destroy(condition);
+}
+
 celix_status_t celixThreadCondition_wait(celix_thread_cond_t *cond, celix_thread_mutex_t
*mutex) {
     return pthread_cond_wait(cond, mutex);
 }

Modified: celix/trunk/utils/public/include/celix_threads.h
URL: http://svn.apache.org/viewvc/celix/trunk/utils/public/include/celix_threads.h?rev=1644359&r1=1644358&r2=1644359&view=diff
==============================================================================
--- celix/trunk/utils/public/include/celix_threads.h (original)
+++ celix/trunk/utils/public/include/celix_threads.h Wed Dec 10 09:49:37 2014
@@ -68,6 +68,7 @@ typedef pthread_cond_t celix_thread_cond
 typedef pthread_condattr_t celix_thread_condattr_t;
 
 celix_status_t celixThreadCondition_init(celix_thread_cond_t *condition, celix_thread_condattr_t
*attr);
+celix_status_t celixThreadCondition_destroy(celix_thread_cond_t *condition);
 celix_status_t celixThreadCondition_wait(celix_thread_cond_t *cond, celix_thread_mutex_t
*mutex);
 celix_status_t celixThreadCondition_broadcast(celix_thread_cond_t *cond);
 celix_status_t celixThreadCondition_signal(celix_thread_cond_t *cond);



Mime
View raw message