Implement tryadd, adding itmes with a timeout

This commit is contained in:
Nils O. Selåsdal
2013-01-02 16:54:20 +01:00
parent dbe91d2d13
commit 3e7fd8a34b
3 changed files with 99 additions and 6 deletions
+10 -2
View File
@@ -166,11 +166,19 @@ int uc_thread_queue_init(struct uc_threadqueue *queue, long max_elements);
* the front of the queue, i.e. it can be considered a "priority" message.
*
* @param queue Pointer to the queue on where the message should be added.
* @param timeout timeout on how long to wait on a message, or NULL for no timeout
* @param data the "message".
* @return 0 on succes ENOMEM if out of memory EINVAL if queue is NULL, or other
* @return 0 on succes ENOMEM if out of memory EINVAL if queue is NULL, ETIMEDOUT if timeout occured or other
* errno values if pthread functions failed.
*/
int uc_thread_queue_add(struct uc_threadqueue *queue, struct uc_threadmsg *msg);
int uc_thread_queue_tryadd(struct uc_threadqueue *queue, const struct timespec *timeout, struct uc_threadmsg *msg);
/**
* Like uc_thread_queue_add but will wait indefintly.
* @see uc_thread_queue_add
*/
#define uc_thread_queue_add(queue, msg)\
uc_thread_queue_tryadd(queue, NULL, msg)
/**
* Gets a message from a queue