diff options
author | Brian Paul <[email protected]> | 1999-09-16 22:45:24 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 1999-09-16 22:45:24 +0000 |
commit | 4811b7c7e02c0612975a8526f8ebba49ece0e72b (patch) | |
tree | d039cf9b6dd2a9d4fb47b856f1f89adec4ff81f8 /src/glut/beos/glutBlocker.cpp | |
parent | b9e8741c8f0e5d683df4be09a232aa722589645e (diff) |
initial check-in
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); +} |