Assorted whitespace cleanup and typo fixes.
[haiku.git] / src / libs / glut / glutBlocker.cpp
blobaa948522b9b8a5d92c31052a4ff6b8117aa14f46
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 /***********************************************************
15 * Headers
16 ***********************************************************/
17 #include "glutBlocker.h"
19 /***********************************************************
20 * Global variable
21 ***********************************************************/
22 GlutBlocker gBlock;
24 /***********************************************************
25 * Member functions
26 ***********************************************************/
27 GlutBlocker::GlutBlocker() {
28 gSem = create_sem(1, "gSem");
29 eSem = create_sem(0, "eSem");
30 events = false;
31 sleeping = false;
34 GlutBlocker::~GlutBlocker() {
35 delete_sem(eSem);
36 delete_sem(gSem);
39 void GlutBlocker::WaitEvent() {
40 acquire_sem(gSem);
41 if(!events) { // wait for new event
42 sleeping = true;
43 release_sem(gSem);
44 acquire_sem(eSem); // next event will release eSem
45 } else {
46 release_sem(gSem);
50 void GlutBlocker::WaitEvent(bigtime_t usecs) {
51 acquire_sem(gSem);
52 if(!events) { // wait for new event
53 sleeping = true;
54 release_sem(gSem);
55 acquire_sem_etc(eSem, 1, B_TIMEOUT, usecs); // wait for next event or timeout
56 } else {
57 release_sem(gSem);
61 void GlutBlocker::NewEvent() {
62 acquire_sem(gSem);
63 events = true; // next call to WaitEvent returns immediately
64 if(sleeping) {
65 sleeping = false;
66 release_sem(eSem); // if event loop is blocking, wake it up
68 release_sem(gSem);