1 #include <minix/mthread.h>
4 /*===========================================================================*
6 *===========================================================================*/
7 int mthread_event_init(event
)
8 mthread_event_t
*event
; /* The event to be initialized */
10 /* Initialize an event object.
17 r
= mthread_mutex_init(&event
->mutex
, NULL
);
21 r
= mthread_cond_init(&event
->cond
, NULL
);
23 mthread_mutex_destroy(&event
->mutex
);
29 /*===========================================================================*
30 * mthread_event_destroy *
31 *===========================================================================*/
32 int mthread_event_destroy(event
)
33 mthread_event_t
*event
; /* The event to be destroyed */
35 /* Destroy an event object.
42 r
= mthread_cond_destroy(&event
->cond
);
46 return mthread_mutex_destroy(&event
->mutex
);
49 /*===========================================================================*
50 * mthread_event_wait *
51 *===========================================================================*/
52 int mthread_event_wait(event
)
53 mthread_event_t
*event
; /* The event to be waited on */
55 /* Wait for an event, blocking the current thread in the process.
62 r
= mthread_mutex_lock(&event
->mutex
);
66 r
= mthread_cond_wait(&event
->cond
, &event
->mutex
);
68 mthread_mutex_unlock(&event
->mutex
);
72 return mthread_mutex_unlock(&event
->mutex
);
75 /*===========================================================================*
76 * mthread_event_fire *
77 *===========================================================================*/
78 int mthread_event_fire(event
)
79 mthread_event_t
*event
; /* The event to be fired */
81 /* Fire an event, waking up any thread blocked on it.
88 r
= mthread_mutex_lock(&event
->mutex
);
92 r
= mthread_cond_signal(&event
->cond
);
94 mthread_mutex_unlock(&event
->mutex
);
98 return mthread_mutex_unlock(&event
->mutex
);
102 /*===========================================================================*
103 * mthread_event_fire_all *
104 *===========================================================================*/
105 int mthread_event_fire_all(event
)
106 mthread_event_t
*event
; /* The event to be fired */
108 /* Fire an event, waking up any thread blocked on it.
115 r
= mthread_mutex_lock(&event
->mutex
);
119 r
= mthread_cond_broadcast(&event
->cond
);
121 mthread_mutex_unlock(&event
->mutex
);
125 return mthread_mutex_unlock(&event
->mutex
);