Compile with -std=gnu99.

Small cleanups
This commit is contained in:
Nils O. Selåsdal
2012-12-09 20:15:21 +01:00
parent 29fd133ff2
commit f6aad1e77a
2 changed files with 14 additions and 6 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ env = Environment(tools = ['default', 'textfile'])
env.AddMethod(InstallPerm) env.AddMethod(InstallPerm)
Export('env', 'build_type', 'prefix', 'version_info', 'test_xml') 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(LINKFLAGS = ['-O2', '-pthread'])
env.Append(CPPDEFINES = ['_FILE_OFFSET_BITS=64']) env.Append(CPPDEFINES = ['_FILE_OFFSET_BITS=64'])
env.Append(CPPPATH = ['#include']) env.Append(CPPPATH = ['#include'])
+13 -5
View File
@@ -9,7 +9,8 @@
* @param timeout a timeout duration * @param timeout a timeout duration
* @param result the absolute time from now when the timeout expires * @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; struct timeval now;
//TODO investigate using clock_gettime() instead of gettimeofday //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->max_elements = max_elements;
queue->last = &queue->first; queue->last = &queue->first;
return 0; return rc;
} }
int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg) 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); pthread_mutex_lock(&queue->mutex);
//Wait if the queue is full //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->first = msg;
} }
queue->num_elements++;
//signal blocked readers //signal blocked readers
if (queue->num_read_waiters == 1) { if (queue->num_read_waiters == 1) {
//if there's just one thread waiting to pop elements //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); pthread_cond_broadcast(&queue->read_cond);
} }
queue->num_elements++;
pthread_mutex_unlock(&queue->mutex); 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; 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 uc_thread_queue_destroy(struct uc_threadqueue *queue, uc_thread_queue_walk_func free_func)
{ {
int rc; 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 uc_thread_queue_length(struct uc_threadqueue *queue)
{ {
long length; long length;
if (queue == NULL ) {
return -EINVAL;
}
// get the length properly // get the length properly
pthread_mutex_lock(&queue->mutex); pthread_mutex_lock(&queue->mutex);
length = queue->num_elements; length = queue->num_elements;