use the notify library in main_notify.c
Avoid some duplicated code in main_notify.c.
This commit is contained in:
parent
4f80f53c29
commit
8814c0c898
@ -28,9 +28,7 @@
|
|||||||
static struct ioOps main_notify_IO;
|
static struct ioOps main_notify_IO;
|
||||||
static int main_pipe[2];
|
static int main_pipe[2];
|
||||||
static pthread_t main_task;
|
static pthread_t main_task;
|
||||||
static pthread_cond_t main_wakeup = PTHREAD_COND_INITIALIZER;
|
static Notify main_notify;
|
||||||
static pthread_mutex_t main_wakeup_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
||||||
static volatile int pending;
|
|
||||||
static pthread_mutex_t select_mutex = PTHREAD_MUTEX_INITIALIZER;
|
static pthread_mutex_t select_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static int ioops_fdset(fd_set * rfds,
|
static int ioops_fdset(fd_set * rfds,
|
||||||
@ -74,6 +72,7 @@ void init_main_notify(void)
|
|||||||
main_notify_IO.consume = ioops_consume;
|
main_notify_IO.consume = ioops_consume;
|
||||||
registerIO(&main_notify_IO);
|
registerIO(&main_notify_IO);
|
||||||
main_task = pthread_self();
|
main_task = pthread_self();
|
||||||
|
notify_init(&main_notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int wakeup_via_pipe(void)
|
static int wakeup_via_pipe(void)
|
||||||
@ -95,10 +94,10 @@ void wakeup_main_task(void)
|
|||||||
{
|
{
|
||||||
assert(!pthread_equal(main_task, pthread_self()));
|
assert(!pthread_equal(main_task, pthread_self()));
|
||||||
|
|
||||||
pending = 1;
|
main_notify.pending = 1;
|
||||||
|
|
||||||
if (!wakeup_via_pipe())
|
if (!wakeup_via_pipe())
|
||||||
pthread_cond_signal(&main_wakeup);
|
notify_signal(&main_notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
void main_notify_lock(void)
|
void main_notify_lock(void)
|
||||||
@ -117,10 +116,8 @@ void wait_main_task(void)
|
|||||||
{
|
{
|
||||||
assert(pthread_equal(main_task, pthread_self()));
|
assert(pthread_equal(main_task, pthread_self()));
|
||||||
|
|
||||||
pthread_mutex_lock(&main_wakeup_mutex);
|
notify_enter(&main_notify);
|
||||||
if (!pending)
|
notify_wait(&main_notify);
|
||||||
pthread_cond_wait(&main_wakeup, &main_wakeup_mutex);
|
notify_leave(&main_notify);
|
||||||
pending = 0;
|
|
||||||
pthread_mutex_unlock(&main_wakeup_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user