10 #if GFX_USE_GEVENT || defined(__DOXYGEN__)
12 #if GEVENT_ASSERT_NO_RESOURCE
13 #define GEVENT_ASSERT(x) assert(x)
15 #define GEVENT_ASSERT(x)
19 #define GLISTENER_WITHLISTENER 0x0001
20 #define GLISTENER_WITHSOURCE 0x0002
30 static void doExitEvent(GListener *pl) {
32 if (!(pl->flags & GLISTENER_WITHLISTENER)) {
33 pl->event.type = GEVENT_EXIT;
34 pl->flags = GLISTENER_WITHLISTENER;
42 static void deleteAssignments(GListener *pl, GSourceHandle gsh) {
46 if ((!pl || psl->pListener == pl) && (!gsh || psl->pSource == gsh)) {
47 doExitEvent(psl->pListener);
54 void _geventInit(
void)
59 void _geventDeinit(
void)
67 pl->event.type = GEVENT_NULL;
72 GSourceListener *psl, *pslfree;
76 GEVENT_ASSERT(gFalse);
86 if (pl == psl->pListener && gsh == psl->pSource) {
88 psl->listenflags = flags;
92 if (!pslfree && !psl->pListener)
98 pslfree->pListener = pl;
99 pslfree->pSource = gsh;
100 pslfree->listenflags = flags;
101 pslfree->srcflags = 0;
104 GEVENT_ASSERT(pslfree != 0);
111 deleteAssignments(pl, gsh);
137 pl->flags &= ~GLISTENER_WITHLISTENER;
148 pl->flags &= ~GLISTENER_WITHLISTENER;
151 void geventRegisterCallback(GListener *pl, GEventCallbackFn fn,
void *param) {
158 pl->flags &= ~GLISTENER_WITHLISTENER;
164 GSourceListener *psl;
173 if (lastlr && lastlr->pListener && (lastlr->pListener->flags & GLISTENER_WITHSOURCE))
174 lastlr->pListener->flags &= ~GLISTENER_WITHSOURCE;
178 if (gsh == psl->pSource) {
189 if ((psl->pListener->flags & (GLISTENER_WITHLISTENER|GLISTENER_WITHSOURCE))) {
195 psl->pListener->flags |= GLISTENER_WITHSOURCE;
197 return &psl->pListener->event;
202 if (psl->pListener->callback) {
206 psl->pListener->flags = 0;
210 psl->pListener->callback(psl->pListener->param, &psl->pListener->event);
214 psl->pListener->flags = GLISTENER_WITHLISTENER;
222 deleteAssignments(0, gsh);
void geventListenerInit(GListener *pl)
Create a Listener.
#define GEVENT_MAX_SOURCE_LISTENERS
Defines the maximum Source/Listener pairs in the system.
GEvent * geventGetEventBuffer(GSourceListener *psl)
Get the event buffer from the GSourceListener.
void geventDetachSource(GListener *pl, GSourceHandle gsh)
Detach a source from a listener.
void geventSendEvent(GSourceListener *psl)
Called by a source to indicate the listener's event buffer has been filled.
GEvent * geventEventWait(GListener *pl, gDelay timeout)
Wait for an event on a listener from an assigned source.
gBool geventAttachSource(GListener *pl, GSourceHandle gsh, gU32 flags)
Attach a source to a listener.
GSourceListener * geventGetSourceListener(GSourceHandle gsh, GSourceListener *lastlr)
Called by a source with a possible event to get a listener record.
void geventDetachSourceListeners(GSourceHandle gsh)
Detach any listener that has this source attached.
void geventEventComplete(GListener *pl)
Release the GEvent buffer associated with a listener.
void gfxSemSignal(gSem *psem)
Signal a semaphore.
void gfxMutexExit(gMutex *pmutex)
Exit the critical code region protected by the mutex.
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxMutexEnter(gMutex *pmutex)
Enter the critical code region protected by the mutex.
void gfxMutexInit(gMutex *pmutex)
Initialise a mutex to protect a region of code from other threads.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxMutexDestroy(gMutex *pmutex)
Destroy a Mutex.