Decouple the signalling into a struct IOMuxSignaller

This commit is contained in:
Nils O. Selåsdal
2013-12-24 01:51:40 +01:00
parent 277900b08e
commit b83d2fb2cf
2 changed files with 25 additions and 16 deletions
+9 -2
View File
@@ -10,6 +10,11 @@ extern "C" {
struct IOMuxWaker;
typedef void (*uc_waker_cb)(struct IOMuxWaker *wk);
/** Usef for signalling an IOMux */
struct IOMuxSignaller {
int fd;
};
/** These are primitives to wake up an IOMux.
* An IOMux event loop can be woken up from e.g. an unix signal handler
* or another thread. The IOMuxWaker itself is not thread safe, it's members
@@ -22,11 +27,11 @@ typedef void (*uc_waker_cb)(struct IOMuxWaker *wk);
*/
struct IOMuxWaker {
//private fields
int fds[2];
struct IOMuxFD read_fd;
uc_waker_cb wake_cb;
//public fields
struct IOMuxSignaller signaller;
struct IOMux *mux;
void *cookie;
};
@@ -47,6 +52,8 @@ int uc_iomux_waker_init(struct IOMux *mux, struct IOMuxWaker *wk, uc_waker_cb cb
* Care must be taken so the IOMuxWaker is destroyed
* without race conditions with a thread that wants to _signal the
* waker.
* The embedded IOMuxSignaller of the IOMuxWaker can be used
* by someone else in the uc_iomux_waker_signal() function
*
* @param wk
* @return 0 on success, errno on failure (Things are seriously
@@ -63,7 +70,7 @@ int uc_iomux_waker_destroy(struct IOMuxWaker *wk);
* @return 0 on success, errno on failure (Things are seriously
* wrong if this fails)
*/
int uc_iomux_waker_signal(struct IOMuxWaker *wk);
int uc_iomux_waker_signal(struct IOMuxSignaller *signaller);
#ifdef __cplusplus
}