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 
17 public:
18 
20  ThreadContext ();
21 
23  ~ThreadContext ();
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 
43 protected:
44 
45  void* cond;
46  void* mutex;
47 
48 };
49 
51 
57 
58 public:
59 
61  Lock (ThreadContext* t) { if (t) t->lock(); context = t; }
62 
64  ~Lock () { if (context) context->unlock(); }
65 
66 protected:
67 
70 
71 };
72 
73 #endif // !defined(__ThreadContext_h)
Locks the mutex on construction and unlocks on deletion.
Definition: ThreadContext.h:56
A convenient exception handling class.
Definition: Error.h:54
void unlock()
Release the mutual exclusion lock.
Definition: ThreadContext.C:51
ThreadContext()
Default constructor.
Definition: ThreadContext.C:16
Lock(ThreadContext *t)
The constructor obtains the mutual exclusion lock ...
Definition: ThreadContext.h:61
void lock()
Obtain the mutual exclusion lock.
Definition: ThreadContext.C:41
~ThreadContext()
Destructor.
Definition: ThreadContext.C:33
~Lock()
And the destructor releases it.
Definition: ThreadContext.h:64
ThreadContext class.
Definition: ThreadContext.h:15
ThreadContext * context
The context in which the lock is held.
Definition: ThreadContext.h:69
void wait()
Wait for a condition.
Definition: ThreadContext.C:61
void signal()
Signal a condition to a single waiting thread.
Definition: ThreadContext.C:74
void broadcast()
Signal a condition to all waiting threads.
Definition: ThreadContext.C:84

Generated using doxygen 1.8.17