diff options
Diffstat (limited to 'src/glut/beos/glutBlocker.cpp')
-rw-r--r-- | src/glut/beos/glutBlocker.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/glut/beos/glutBlocker.cpp b/src/glut/beos/glutBlocker.cpp new file mode 100644 index 00000000000..e2cfcf7b393 --- /dev/null +++ b/src/glut/beos/glutBlocker.cpp @@ -0,0 +1,65 @@ +/*********************************************************** + * Copyright (C) 1997, Be Inc. All rights reserved. + * + * FILE: glutBlocker.cpp + * + * DESCRIPTION: helper class for GLUT event loop. + * if a window receives an event, wake up the event loop. + ***********************************************************/ + +/*********************************************************** + * Headers + ***********************************************************/ +#include "glutBlocker.h" + +/*********************************************************** + * Global variable + ***********************************************************/ +GlutBlocker gBlock; + +/*********************************************************** + * Member functions + ***********************************************************/ +GlutBlocker::GlutBlocker() { + gSem = create_sem(1, "gSem"); + eSem = create_sem(0, "eSem"); + events = false; + sleeping = false; +} + +GlutBlocker::~GlutBlocker() { + delete_sem(eSem); + delete_sem(gSem); +} + +void GlutBlocker::WaitEvent() { + acquire_sem(gSem); + if(!events) { // wait for new event + sleeping = true; + release_sem(gSem); + acquire_sem(eSem); // next event will release eSem + } else { + release_sem(gSem); + } +} + +void GlutBlocker::WaitEvent(bigtime_t usecs) { + acquire_sem(gSem); + if(!events) { // wait for new event + sleeping = true; + release_sem(gSem); + acquire_sem_etc(eSem, 1, B_TIMEOUT, usecs); // wait for next event or timeout + } else { + release_sem(gSem); + } +} + +void GlutBlocker::NewEvent() { + acquire_sem(gSem); + events = true; // next call to WaitEvent returns immediately + if(sleeping) { + sleeping = false; + release_sem(eSem); // if event loop is blocking, wake it up + } + release_sem(gSem); +} |