From f6aad1e77a1eb509ad75288ec3c5aba8423f14e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sun, 9 Dec 2012 20:15:21 +0100 Subject: [PATCH] Compile with -std=gnu99. Small cleanups --- SConstruct | 2 +- src/ucore_threadqueue.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index fc95129..9bfe80f 100644 --- a/SConstruct +++ b/SConstruct @@ -54,7 +54,7 @@ env = Environment(tools = ['default', 'textfile']) env.AddMethod(InstallPerm) Export('env', 'build_type', 'prefix', 'version_info', 'test_xml') -env.Append(CFLAGS = ['-Wall', '-Wextra', '-Wundef', '-Wcast-qual','-Wshadow' ,'-Wcast-align','-pipe', '-ggdb', '-pthread']) +env.Append(CFLAGS = ['-std=gnu99','-Wall', '-Wextra', '-Wundef', '-Wcast-qual','-Wshadow' ,'-Wcast-align','-pipe', '-ggdb', '-pthread']) env.Append(LINKFLAGS = ['-O2', '-pthread']) env.Append(CPPDEFINES = ['_FILE_OFFSET_BITS=64']) env.Append(CPPPATH = ['#include']) diff --git a/src/ucore_threadqueue.c b/src/ucore_threadqueue.c index b553fc4..df0f4f1 100644 --- a/src/ucore_threadqueue.c +++ b/src/ucore_threadqueue.c @@ -9,7 +9,8 @@ * @param timeout a timeout duration * @param result the absolute time from now when the timeout expires */ -void uc_get_absolute_time(struct timespec *result, const struct timespec *timeout) +static inline void uc_get_absolute_time(struct timespec *result, + const struct timespec *timeout) { struct timeval now; //TODO investigate using clock_gettime() instead of gettimeofday @@ -53,12 +54,15 @@ int uc_thread_queue_init(struct uc_threadqueue *queue, long max_elements) queue->max_elements = max_elements; queue->last = &queue->first; - return 0; - + return rc; } int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg) { + if (queue == NULL || msg == NULL) { + return EINVAL; + } + pthread_mutex_lock(&queue->mutex); //Wait if the queue is full @@ -81,6 +85,8 @@ int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg) queue->first = msg; } + queue->num_elements++; + //signal blocked readers if (queue->num_read_waiters == 1) { //if there's just one thread waiting to pop elements @@ -91,7 +97,6 @@ int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg) pthread_cond_broadcast(&queue->read_cond); } - queue->num_elements++; pthread_mutex_unlock(&queue->mutex); @@ -184,7 +189,6 @@ int uc_thread_queue_walk(struct uc_threadqueue *queue, uc_thread_queue_walk_func return 0; } -//maybe caller should supply a callback for cleaning the elements ? int uc_thread_queue_destroy(struct uc_threadqueue *queue, uc_thread_queue_walk_func free_func) { int rc; @@ -223,6 +227,10 @@ int uc_thread_queue_destroy(struct uc_threadqueue *queue, uc_thread_queue_walk_f long uc_thread_queue_length(struct uc_threadqueue *queue) { long length; + + if (queue == NULL ) { + return -EINVAL; + } // get the length properly pthread_mutex_lock(&queue->mutex); length = queue->num_elements;