ThreadContext.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2007 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// psrchive/Util/genutil/ThreadContext.h
10
11#ifndef __ThreadContext_h
12#define __ThreadContext_h
13
16
17public:
18
21
24
26 void lock ();
27
29 void unlock ();
30
32 void wait ();
33
35 void signal ();
36
38 void broadcast ();
39
41 class Lock;
42
43protected:
44
45 void* cond;
46 void* mutex;
47
48};
49
51
57
58public:
59
61 Lock (ThreadContext* t) { if (t) t->lock(); context = t; }
62
64 ~Lock () { if (context) context->unlock(); }
65
66protected:
67
70
71};
72
73#endif // !defined(__ThreadContext_h)
Locks the mutex on construction and unlocks on deletion.
Definition ThreadContext.h:56
Lock(ThreadContext *t)
The constructor obtains the mutual exclusion lock ...
Definition ThreadContext.h:61
ThreadContext * context
The context in which the lock is held.
Definition ThreadContext.h:69
~Lock()
And the destructor releases it.
Definition ThreadContext.h:64
void wait()
Wait for a condition.
Definition ThreadContext.C:61
void broadcast()
Signal a condition to all waiting threads.
Definition ThreadContext.C:84
void unlock()
Release the mutual exclusion lock.
Definition ThreadContext.C:51
ThreadContext()
Default constructor.
Definition ThreadContext.C:16
~ThreadContext()
Destructor.
Definition ThreadContext.C:33
void lock()
Obtain the mutual exclusion lock.
Definition ThreadContext.C:41
void signal()
Signal a condition to a single waiting thread.
Definition ThreadContext.C:74

Generated using doxygen 1.14.0