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