X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=c%2Fpthread_extra%2Fpthread_msgqueue.c;h=44ad399ecb9ef195b78cae64994af93cd4c685db;hb=7e0f3dba1713edfea98cdfe7909c08f68fa5f7b7;hp=b8562965eef620cce7a21c634bab85129071c4c9;hpb=77c7dc7ffcaa64879e90178df5585f22790f46be;p=mirrors%2FPrograms.git diff --git a/c/pthread_extra/pthread_msgqueue.c b/c/pthread_extra/pthread_msgqueue.c index b856296..44ad399 100644 --- a/c/pthread_extra/pthread_msgqueue.c +++ b/c/pthread_extra/pthread_msgqueue.c @@ -52,7 +52,7 @@ bool pthread_mq_reset(pthread_mq_t *mq) { return true; } -bool pthread_mq_send_generic(pthread_mq_t *mq, void * data, bool to_front, const struct timespec *restrict abs_timeout) { +bool pthread_mq_send_generic(pthread_mq_t *mq, void * data, pthread_mq_flags_t flags, const struct timespec *restrict abs_timeout) { //printf("S-Timed: %p\n", abs_timeout); int ret; @@ -75,7 +75,11 @@ bool pthread_mq_send_generic(pthread_mq_t *mq, void * data, bool to_front, const } } + //Handle overwrite + assert(!(flags & PTHREAD_XMQ_OVERW) && "FIXME: Overwrite not implemented yet!"); + //Write data to queue + bool to_front = (flags & PTHREAD_XMQ_FRONT); size_t idx = ( ( mq->head_idx + (to_front?mq->msg_count_max-1:mq->msg_count) ) % mq->msg_count_max ); void *ptr = mq->data + (idx * mq->msg_size); mq->msg_count++; @@ -88,7 +92,7 @@ bool pthread_mq_send_generic(pthread_mq_t *mq, void * data, bool to_front, const return true; } -bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, bool peek, const struct timespec *restrict abs_timeout) { +bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, pthread_mq_flags_t flags, const struct timespec *restrict abs_timeout) { int ret; //Lock queue @@ -114,6 +118,7 @@ bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, bool peek, const memcpy(data, ptr, mq->msg_size); //Delete data from queue if not peeking + bool peek = (flags & PTHREAD_XMQ_PEEK); if(!peek) { mq->msg_count--; mq->head_idx = (mq->head_idx+1) % mq->msg_count_max;