aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/extras/Mesa_6.4.2/src/glut/beos/glutBlocker.cpp
blob: aa948522b9b8a5d92c31052a4ff6b8117aa14f46 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/***********************************************************
 *	Copyright (C) 1997, Be Inc.  Copyright (C) 1999, Jake Hamby.
 *
 * This program is freely distributable without licensing fees
 * and is provided without guarantee or warrantee expressed or
 * implied. This program is -not- in the public domain.
 *
 *  FILE:	glutBlocker.cpp
 *
 *	DESCRIPTION:	helper class for GLUT event loop.
 *		if a window receives an event, wake up the event loop.
 ***********************************************************/

/***********************************************************
 *	Headers
 ***********************************************************/
#include "glutBlocker.h"

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

/***********************************************************
 *	Member functions
 ***********************************************************/
GlutBlocker::GlutBlocker() {
	gSem = create_sem(1, "gSem");
	eSem = create_sem(0, "eSem");
	events = false;
	sleeping = false;
}

GlutBlocker::~GlutBlocker() {
	delete_sem(eSem);
	delete_sem(gSem);
}

void GlutBlocker::WaitEvent() {
	acquire_sem(gSem);
	if(!events) {			// wait for new event
		sleeping = true;
		release_sem(gSem);
		acquire_sem(eSem);	// next event will release eSem
	} else {
		release_sem(gSem);
	}
}

void GlutBlocker::WaitEvent(bigtime_t usecs) {
	acquire_sem(gSem);
	if(!events) {			// wait for new event
		sleeping = true;
		release_sem(gSem);
		acquire_sem_etc(eSem, 1, B_TIMEOUT, usecs);	// wait for next event or timeout
	} else {
		release_sem(gSem);
	}
}

void GlutBlocker::NewEvent() {
	acquire_sem(gSem);
	events = true;		// next call to WaitEvent returns immediately
	if(sleeping) {
		sleeping = false;
		release_sem(eSem);	// if event loop is blocking, wake it up
	}
	release_sem(gSem);
}