1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. All rights reserved.
4 * FILE: glutBlocker.cpp
6 * DESCRIPTION: helper class for GLUT event loop.
7 * if a window receives an event, wake up the event loop.
8 ***********************************************************/
10 /***********************************************************
12 ***********************************************************/
13 #include "glutBlocker.h"
15 /***********************************************************
17 ***********************************************************/
20 /***********************************************************
22 ***********************************************************/
23 GlutBlocker::GlutBlocker() {
24 gSem
= create_sem(1, "gSem");
25 eSem
= create_sem(0, "eSem");
30 GlutBlocker::~GlutBlocker() {
35 void GlutBlocker::WaitEvent() {
37 if(!events
) { // wait for new event
40 acquire_sem(eSem
); // next event will release eSem
46 void GlutBlocker::WaitEvent(bigtime_t usecs
) {
48 if(!events
) { // wait for new event
51 acquire_sem_etc(eSem
, 1, B_TIMEOUT
, usecs
); // wait for next event or timeout
57 void GlutBlocker::NewEvent() {
59 events
= true; // next call to WaitEvent returns immediately
62 release_sem(eSem
); // if event loop is blocking, wake it up