/[svn]/linuxsampler/trunk/src/common/Condition.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/common/Condition.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 880 - (show annotations) (download) (as text)
Tue Jun 27 22:57:37 2006 UTC (17 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 4546 byte(s)
just some refactoring work:
- renamed class LinuxSamplerException -> Exception
- encapsulated LS API relevant files into LS namespace
- removed unnecessary header inclusions

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005, 2006 Christian Schoenebeck *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #ifndef __CONDITION_H__
25 #define __CONDITION_H__
26
27 #include "Mutex.h"
28
29 namespace LinuxSampler {
30
31 /**
32 * Thread safe boolean condition.
33 *
34 * This is not meant to be used for real time operation!
35 */
36 class Condition : public Mutex {
37 public:
38 /**
39 * Constructor
40 *
41 * @param bInitialCondition - optional: starting condition
42 * (default = false)
43 */
44 Condition(bool bInitialCondition = false);
45
46 /**
47 * Destructor
48 */
49 virtual ~Condition();
50
51 /**
52 * Blocks the calling thread if current condition equals
53 * \a bCondition, in this case the calling thread will be blocked
54 * until condition turns. Upon successful return the Condition
55 * object is locked, so the calling thread can safely run it's
56 * critical section and has to explicitly call Unlock() right after
57 * it left it's critcal section.
58 *
59 * @param bCondition - block in case of this condition
60 * @param TimeoutSeconds - optional: max. wait time in seconds
61 * (default: 0s)
62 * @param TimeoutNanoSeconds - optional: max wait time in nano
63 * seconds (default: 0ns)
64 * @returns 0 on success, a value less than 0 if timeout exceeded
65 */
66 int WaitIf(bool bCondition, long TimeoutSeconds = 0L, long TimeoutNanoSeconds = 0L);
67
68 /**
69 * Same as WaitIf(), except that WaitAndUnlockIf() will unlock the
70 * Condition object, so only use this call if you don't need to
71 * enter a thread critical section, otherwise use WaitIf() instead!
72 *
73 * @param bCondition - block in case of this condition
74 * @param TimeoutSeconds - optional: max. wait time in seconds
75 * (default: 0s)
76 * @param TimeoutNanoSeconds - optional: max wait time in nano
77 * seconds (default: 0ns)
78 * @returns 0 on success, a value less than 0 if timeout exceeded
79 * @see WaitIf()
80 */
81 int WaitAndUnlockIf(bool bCondition, long TimeoutSeconds = 0L, long TimeoutNanoSeconds = 0L);
82
83 /**
84 * Set Condition object to \a bCondition. Upon change of the
85 * condition, other threads waiting for \a bCondition will be
86 * awakened. (Note the condition will not be locked for the calling
87 * thread after this method returns!)
88 *
89 * @param bCondition - new condition
90 */
91 void Set(bool bCondition);
92
93 protected:
94 pthread_cond_t __posix_true_condition;
95 pthread_cond_t __posix_false_condition;
96 bool bCondition;
97 };
98
99 } // namespace LinuxSampler
100
101 #endif // __CONDITION_H__

  ViewVC Help
Powered by ViewVC