summaryrefslogtreecommitdiff
path: root/src/glut/beos/glutBlocker.h
blob: e6d1f4e049f166da289f220e130c6873039b91ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/***********************************************************
 *	Copyright (C) 1997, Be Inc.  All rights reserved.
 *
 *  FILE:	glutBlocker.h
 *
 *	DESCRIPTION:	helper class for GLUT event loop.
 *		if a window receives an event, wake up the event loop.
 ***********************************************************/

/***********************************************************
 *	Headers
 ***********************************************************/
#include <kernel/OS.h>

/***********************************************************
 *	CLASS:	GlutBlocker
 *
 *	DESCRIPTION:  Fairly naive, but safe implementation.
 *		global semaphore controls access to state
 *		event semaphore blocks WaitEvent() call if necessary
 *		(this is basically a condition variable class)
 ***********************************************************/
class GlutBlocker {
public:
	GlutBlocker();
	~GlutBlocker();
	void WaitEvent();		// wait for new event
	void WaitEvent(bigtime_t usecs);	// wait with timeout
	void NewEvent();		// new event from a window (may need to wakeup main thread)
	void QuickNewEvent() { events = true; }	// new event from main thread
	void ClearEvents() { events = false; }		// clear counter at beginning of event loop
	bool PendingEvent() { return events; }		// XPending() equivalent
private:
	sem_id gSem;
	sem_id eSem;
	bool events;	// are there any new events?
	bool sleeping;	// is someone sleeping on eSem?
};

/***********************************************************
 *	Global variable
 ***********************************************************/
extern GlutBlocker gBlock;