[go: up one dir, main page]

Menu

[r377]: / trunk / tools / oogtk / oomutex.h  Maximize  Restore  History

Download this file

75 lines (63 with data), 1.5 kB

 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
70
71
72
73
#ifndef OOCRIT_H__
#define OOCRIT_H__
/**
* GG
* Small package around gtk Mutex
*/
#include <glib.h>
namespace gtk {
class Mutex
{
private:
GStaticMutex mutex;
public:
Mutex() {
g_static_mutex_init(&mutex);
}
~Mutex() {
g_static_mutex_free(&mutex);
}
void Lock() {
g_static_mutex_lock(&mutex);
}
void Unlock() {
g_static_mutex_unlock(&mutex);
}
// old CriticalSection api emulation
void Enter() { Lock(); }
void Leave() { Unlock(); }
};
class AutoMutex
{
public:
AutoMutex(Mutex & cs) : cs_(cs) { cs_.Lock(); };
~AutoMutex() { cs_.Unlock(); };
private:
Mutex & cs_;
};
class Sync
{
private:
GCond *cv;
GMutex *mutex;
public:
Sync() { mutex = g_mutex_new(); cv = g_cond_new(); }
~Sync() { g_cond_free(cv); g_mutex_free(mutex); }
void Wait(void) { g_cond_wait(cv, mutex); };
void Lock(void) { g_mutex_lock(mutex); };
void Unlock(void) { g_mutex_unlock(mutex); };
int Wait(long msecs) {
GTimeVal now;
g_get_current_time(&now);
g_time_val_add(&now, msecs * 1000L);
return g_cond_timed_wait(cv, mutex, &now);
}
void Signal(void) { g_cond_signal(cv); };
void SignalAll(void) { g_cond_broadcast(cv); };
};
}
#ifndef NO_CRITSECTION_EMUL
typedef gtk::Mutex CritSection;
typedef gtk::AutoMutex AutoCS;
#endif
#endif