3 |
* LinuxSampler - modular, streaming capable sampler * |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2007 Christian Schoenebeck * |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
* 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 * |
* it under the terms of the GNU General Public License as published by * |
25 |
#define __CONDITIONSERVER_H__ |
#define __CONDITIONSERVER_H__ |
26 |
|
|
27 |
#include "Mutex.h" |
#include "Mutex.h" |
28 |
#include "Condition.h" |
#include "SynchronizedConfig.h" |
29 |
|
|
30 |
namespace LinuxSampler { |
namespace LinuxSampler { |
31 |
|
|
41 |
* method will immediately return if the current condition already equals |
* method will immediately return if the current condition already equals |
42 |
* the desired condition given with Push(), if it's not equal then Push() |
* the desired condition given with Push(), if it's not equal then Push() |
43 |
* will cause a request to change the condition and will block until the |
* will cause a request to change the condition and will block until the |
44 |
* condition actually changed, which happens when the RTT calls the Pop() |
* condition actually changed, which happens when the RTT is outside its |
45 |
* method, which will also return the new condition to the RTT. |
* critical region, or has called the Pop() method, which will also return |
46 |
|
* the new condition to the RTT. |
47 |
* |
* |
48 |
* Advantage of this technique is that the RTT doesn't has to execute system |
* Advantage of this technique is that the RTT doesn't has to execute system |
49 |
* calls whenever it wants to check for a condition change, the RTT only has |
* calls whenever it wants to check for a condition change. Disadvantage on |
50 |
* to execute one system call when the condition changed. Disadvantage on |
* the other hand is that the NRTTs might be blocked for some time, but this |
51 |
* the other hand is that the NRTTs might be blocked for a long time, but |
* is usually unproblematic for NRTTs. |
|
* this is usually unproblematic for NRTTs. |
|
52 |
*/ |
*/ |
53 |
class ConditionServer { |
class ConditionServer { |
54 |
public: |
public: |
62 |
* equals \a bCondition, then this method will immediately return, |
* equals \a bCondition, then this method will immediately return, |
63 |
* if not it will block the calling thread until the condition |
* if not it will block the calling thread until the condition |
64 |
* actually changed to the requested condition (which happens when |
* actually changed to the requested condition (which happens when |
65 |
* Pop() is called by the real time thread). If there are multiple |
* Pop() has been called by the real time thread, or when the real |
66 |
|
* time thread is outside its critical region). If there are multiple |
67 |
* non real time threads calling Push() only one by one will be |
* non real time threads calling Push() only one by one will be |
68 |
* served, all others blocked meanwhile. When the calling thread |
* served, all others blocked meanwhile. When the calling thread |
69 |
* returns from Push() the Push() method will still be blocked |
* returns from Push() the Push() method will still be blocked |
120 |
// method for real time thread (1 RTT) |
// method for real time thread (1 RTT) |
121 |
|
|
122 |
/** |
/** |
123 |
* Should frequently be called by the real time thread (RTT) to |
* Should be called by the real time thread (RTT) at the |
124 |
* check for a condition change. If a NRTT requested a condition |
* beginning of the critical region to check for a condition |
125 |
* change by calling Push() ot PushAndUnlock() the NRTT wil be |
* change. If an NRTT requested a condition change by calling |
126 |
* blocked until the RTT calls Pop(), means until the RTT actually |
* Push() or PushAndUnlock() the NRTT will be blocked until |
127 |
* knows about the condition change. |
* it knows that the RTT will not go into its critical region |
128 |
|
* without being notified about the condition change. |
129 |
* |
* |
130 |
* @returns current condition |
* @returns current condition |
131 |
*/ |
*/ |
132 |
bool Pop(); |
bool Pop() { |
133 |
|
return Reader.Lock(); |
134 |
|
} |
135 |
|
|
136 |
|
/** |
137 |
|
* Should be called by the real time thread (RTT) at the end of |
138 |
|
* the critical region. |
139 |
|
*/ |
140 |
|
void RttDone() { |
141 |
|
Reader.Unlock(); |
142 |
|
} |
143 |
|
|
144 |
protected: |
protected: |
145 |
bool bConditionQuick; |
SynchronizedConfig<bool> Condition; |
146 |
bool bChangeRequest; |
SynchronizedConfig<bool>::Reader Reader; |
147 |
bool bOldCondition; |
bool bOldCondition; |
|
Condition SyncCondition; |
|
148 |
Mutex PushMutex; |
Mutex PushMutex; |
149 |
}; |
}; |
150 |
|
|