1 /*********************************************************** 2 * Copyright (C) 1997, Be Inc. Copyright (C) 1999, Jake Hamby. 3 * 4 * This program is freely distributable without licensing fees 5 * and is provided without guarantee or warrantee expressed or 6 * implied. This program is -not- in the public domain. 7 * 8 * FILE: glutBlocker.h 9 * 10 * DESCRIPTION: helper class for GLUT event loop. 11 * if a window receives an event, wake up the event loop. 12 ***********************************************************/ 13 14 /*********************************************************** 15 * Headers 16 ***********************************************************/ 17 #include <kernel/OS.h> 18 19 /*********************************************************** 20 * CLASS: GlutBlocker 21 * 22 * DESCRIPTION: Fairly naive, but safe implementation. 23 * global semaphore controls access to state 24 * event semaphore blocks WaitEvent() call if necessary 25 * (this is basically a condition variable class) 26 ***********************************************************/ 27 class GlutBlocker { 28 public: 29 GlutBlocker(); 30 ~GlutBlocker(); 31 void WaitEvent(); // wait for new event 32 void WaitEvent(bigtime_t usecs); // wait with timeout 33 void NewEvent(); // new event from a window (may need to wakeup main thread) 34 void QuickNewEvent() { events = true; } // new event from main thread 35 void ClearEvents() { events = false; } // clear counter at beginning of event loop 36 bool PendingEvent() { return events; } // XPending() equivalent 37 private: 38 sem_id gSem; 39 sem_id eSem; 40 bool events; // are there any new events? 41 bool sleeping; // is someone sleeping on eSem? 42 }; 43 44 /*********************************************************** 45 * Global variable 46 ***********************************************************/ 47 extern GlutBlocker gBlock; 48