diff options
| author | Garrett D'Amore <garrett@damore.org> | 2016-12-22 15:23:21 -0800 |
|---|---|---|
| committer | Garrett D'Amore <garrett@damore.org> | 2016-12-22 15:23:21 -0800 |
| commit | 934c1316ae47754a2e368c65228c3cbfe552680f (patch) | |
| tree | e81c4d2854df83e3d908c9269dd35c0600fa6acb /src/core/msgqueue.h | |
| parent | ee969ad99dc1e07e1c38876223e7aed13463b121 (diff) | |
| download | nng-934c1316ae47754a2e368c65228c3cbfe552680f.tar.gz nng-934c1316ae47754a2e368c65228c3cbfe552680f.tar.bz2 nng-934c1316ae47754a2e368c65228c3cbfe552680f.zip | |
Inline locks (fewer allocs), simpler absolute times for wakeups. nn_sock_recv.
Diffstat (limited to 'src/core/msgqueue.h')
| -rw-r--r-- | src/core/msgqueue.h | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/core/msgqueue.h b/src/core/msgqueue.h index e44e203a..d97482af 100644 --- a/src/core/msgqueue.h +++ b/src/core/msgqueue.h @@ -27,37 +27,47 @@ extern int nni_msgqueue_create(nni_msgqueue **, int); // messages that may be in the queue. extern void nni_msgqueue_destroy(nni_msgqueue *); -// nni_msgqueue_put attempts to put a message to the queue. It will wait -// for the timeout (us), if the value is positive. If the value is negative -// then it will wait forever. If the value is zero, it will just check, and -// return immediately whether a message can be put or not. Valid returns are -// NNG_ECLOSED if the queue is closed or NNG_ETIMEDOUT if the message cannot -// be placed after a time, or NNG_EAGAIN if the operation cannot succeed -// immediately and a zero timeout is specified. Note that timeout granularity -// may be limited -- for example Windows systems have a millisecond resolution -// timeout capability. -extern int nni_msgqueue_put(nni_msgqueue *, nni_msg *, int); +// nni_msgqueue_put puts the message to the queue. It blocks until it +// was able to do so, or the queue is closed, returning either 0 on +// success or NNG_ECLOSED if the queue was closed. If NNG_ECLOSED is +// returned, the caller is responsible for freeing the message with +// nni_msg_free(), otherwise the message is "owned" by the queue, and +// the caller is not permitted to access it further. +extern int nni_msgqueue_put(nni_msgqueue *, nni_msg *); -// nni_msgqueue_get gets the message from the queue, using a timeout just -// like nni_msgqueue_put. -extern int nni_msgqueue_get(nni_msgqueue *, nni_msg **, int); +// nni_msgqueue_get gets the message from the queue. It blocks until a +// message is available, or the queue is closed, returning either 0 on +// success or NNG_ECLOSED if the queue was closed. If a message is +// provided, the caller is assumes ownership of the message and must +// call nni_msg_free() when it is finished with it. +extern int nni_msgqueue_get(nni_msgqueue *, nni_msg **); + +// nni_msgqueue_put_until is like nni_msgqueue_put, except that if the +// system clock reaches the specified time without being able to place +// the message in the queue, it will return NNG_ETIMEDOUT. +extern int nni_msgqueue_put_until(nni_msgqueue *, nni_msg *, nni_time); + +// nni_msgqueue_get_until is like nni_msgqueue_put, except that if the +// system clock reaches the specified time without being able to retrieve +// a message from the queue, it will return NNG_ETIMEDOUT. +extern int nni_msgqueue_get_until(nni_msgqueue *, nni_msg **, nni_time); // nni_msgqueue_put_sig is an enhanced version of nni_msgqueue_put, but it // can be interrupted by nni_msgqueue_signal using the same final pointer, // which can be thought of as a turnstile. If interrupted it returns EINTR. // The turnstile should be initialized to zero. -extern int nni_msgqueue_put_sig(nni_msgqueue *, nni_msg *, int, int *); +extern int nni_msgqueue_put_sig(nni_msgqueue *, nni_msg *, nni_signal *); // nni_msgqueue_get_sig is an enhanced version of nni_msgqueue_get_t, but it // can be interrupted by nni_msgqueue_signal using the same final pointer, // which can be thought of as a turnstile. If interrupted it returns EINTR. // The turnstile should be initialized to zero. -extern int nni_msgqueue_get_sig(nni_msgqueue *, nni_msg **, int, int *); +extern int nni_msgqueue_get_sig(nni_msgqueue *, nni_msg **, nni_signal *); // nni_msgqueue_signal delivers a signal / interrupt to waiters blocked in // the msgqueue, if they have registered an interest in the same turnstile. // It modifies the turnstile's value under the lock to a non-zero value. -extern void nni_msgqueue_signal(nni_msgqueue *, int *); +extern void nni_msgqueue_signal(nni_msgqueue *, nni_signal *); // nni_msgqueue_close closes the queue. After this all operates on the // message queue will return NNG_ECLOSED. Messages inside the queue |
