1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. Copyright (C) 1999, Jake Hamby.
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.
8 * FILE: glutBlocker.cpp
10 * DESCRIPTION: helper class for GLUT event loop.
11 * if a window receives an event, wake up the event loop.
12 ***********************************************************/
14 /***********************************************************
16 ***********************************************************/
17 #include "glutBlocker.h"
19 /***********************************************************
21 ***********************************************************/
24 /***********************************************************
26 ***********************************************************/
27 GlutBlocker::GlutBlocker() {
28 gSem
= create_sem(1, "gSem");
29 eSem
= create_sem(0, "eSem");
34 GlutBlocker::~GlutBlocker() {
39 void GlutBlocker::WaitEvent() {
41 if(!events
) { // wait for new event
44 acquire_sem(eSem
); // next event will release eSem
50 void GlutBlocker::WaitEvent(bigtime_t usecs
) {
52 if(!events
) { // wait for new event
55 acquire_sem_etc(eSem
, 1, B_TIMEOUT
, usecs
); // wait for next event or timeout
61 void GlutBlocker::NewEvent() {
63 events
= true; // next call to WaitEvent returns immediately
66 release_sem(eSem
); // if event loop is blocking, wake it up