Assert for missing feature
[mirrors/Programs.git] / c / pthread_extra / pthread_msgqueue.c
index 168dc7f676fb7eb57b3a684ca11de7aadbcb878a..44ad399ecb9ef195b78cae64994af93cd4c685db 100644 (file)
@@ -39,6 +39,10 @@ size_t pthread_mq_waiting(pthread_mq_t *mq) {
        return mq->msg_count;
 }
 
+size_t pthread_mq_vacant(pthread_mq_t *mq) {
+       return (mq->msg_count_max - mq->msg_count);
+}
+
 bool pthread_mq_reset(pthread_mq_t *mq) {
        if(pthread_mutex_lock(&mq->lock)) return false;
        mq->msg_count = 0;
@@ -48,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;
 
@@ -62,7 +66,7 @@ bool pthread_mq_send_generic(pthread_mq_t *mq, void * data, bool to_front, const
                        ret = pthread_cond_wait(&mq->cond_writable, &mq->lock);
                } else {
                        //printf("STimed: %p\n", abs_timeout);
-                       assert(abs_timeout != NULL);
+                       //assert(abs_timeout != NULL);
                        ret = pthread_cond_timedwait(&mq->cond_writable, &mq->lock, abs_timeout);
                }
                if(ret) {
@@ -71,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++;
@@ -84,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
@@ -96,7 +104,7 @@ bool pthread_mq_receive_generic(pthread_mq_t *mq, void * data, bool peek, const
                        ret = pthread_cond_wait(&mq->cond_readable, &mq->lock);
                } else {
                        //printf("RTimed: %p\n", abs_timeout);
-                       assert(abs_timeout != NULL);
+                       //assert(abs_timeout != NULL);
                        ret = pthread_cond_timedwait(&mq->cond_readable, &mq->lock, abs_timeout);
                }
                if(ret) {
@@ -110,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;
This page took 0.101395 seconds and 4 git commands to generate.