Compile with -std=gnu99.
Small cleanups
This commit is contained in:
+1
-1
@@ -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'])
|
||||
|
||||
+13
-5
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user