#define TO_WORKER (0)
#define FROM_WORKER (1)
-#define WHICH_TO_FLAGS(_x) (((_x) + 1) & 0x03)
-//#define FLAGS_TO_WHICH(_x) (((_x) & 0x03) - 1)
-
typedef enum fr_channel_signal_t {
- FR_CHANNEL_SIGNAL_DATA_READY = 0,
+ FR_CHANNEL_SIGNAL_DATA_TO_WORKER = 0,
+ FR_CHANNEL_SIGNAL_DATA_FROM_WORKER,
FR_CHANNEL_SIGNAL_WORKER_SLEEPING,
FR_CHANNEL_SIGNAL_OPEN,
FR_CHANNEL_SIGNAL_CLOSE,
* - <0 on error
* - 0 on success
*/
-static int fr_channel_data_ready(fr_channel_t *ch, fr_time_t when, fr_channel_end_t *end, int which)
+static int fr_channel_data_ready(fr_channel_t *ch, fr_time_t when, fr_channel_end_t *end, fr_channel_signal_t which)
{
struct kevent kev;
* that a thread listening on multiple channels can
* receive events unique to each one.
*/
- EV_SET(&kev, FR_CHANNEL_SIGNAL_DATA_READY, EVFILT_USER, EV_ADD, NOTE_FFOR | WHICH_TO_FLAGS(which), 0, ch);
+ EV_SET(&kev, which, EVFILT_USER, EV_ADD, 0, 0, ch);
return kevent(end->kq, &kev, 1, NULL, 0, NULL);
}
/*
* Tell the other end that there is new data ready.
*/
- return fr_channel_data_ready(ch, when, end, TO_WORKER);
+ return fr_channel_data_ready(ch, when, end, FR_CHANNEL_SIGNAL_DATA_TO_WORKER);
}
/** Receive a reply message from the channel
* thread.
*/
if (end->num_outstanding == 0) {
- return fr_channel_data_ready(ch, when, end, FROM_WORKER);
+ return fr_channel_data_ready(ch, when, end, FR_CHANNEL_SIGNAL_DATA_FROM_WORKER);
}
/*
return 0;
}
- return fr_channel_data_ready(ch, when, end, FROM_WORKER);
+ return fr_channel_data_ready(ch, when, end, FR_CHANNEL_SIGNAL_DATA_FROM_WORKER);
}
* that a thread listening on multiple channels can
* receive events unique to each one.
*/
- EV_SET(&kev, FR_CHANNEL_SIGNAL_WORKER_SLEEPING, EVFILT_USER, EV_ADD, NOTE_FFOR | WHICH_TO_FLAGS(which), end->ack, ch);
+ EV_SET(&kev, FR_CHANNEL_SIGNAL_WORKER_SLEEPING, EVFILT_USER, EV_ADD, 0, end->ack, ch);
return kevent(end->kq, &kev, 1, NULL, 0, NULL);
}
* return the channel to the caller, and rely on it to
* service the channel.
*/
- if (kev->ident == FR_CHANNEL_SIGNAL_DATA_READY) {
+ if (kev->ident == FR_CHANNEL_SIGNAL_DATA_FROM_WORKER) {
+ *p_channel = ch;
+ return FR_CHANNEL_DATA_READY_RECEIVER;
+ }
+
+ if (kev->ident == FR_CHANNEL_SIGNAL_DATA_TO_WORKER) {
*p_channel = ch;
- return FR_CHANNEL_DATA_READY;
+ return FR_CHANNEL_DATA_READY_WORKER;
}
/*
* The worker hasn't seen our last few packets. Signal
* that there is data ready.
*/
- rcode = fr_channel_data_ready(ch, when, end, FROM_WORKER);
+ rcode = fr_channel_data_ready(ch, when, end, FR_CHANNEL_SIGNAL_DATA_FROM_WORKER);
if (rcode < 0) return FR_CHANNEL_ERROR;
return FR_CHANNEL_NOOP;