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