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 * |
21 |
* MA 02111-1307 USA * |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
***************************************************************************/ |
23 |
|
|
|
#include "ConditionServer.h" |
|
|
|
|
24 |
#include "global_private.h" |
#include "global_private.h" |
25 |
|
|
26 |
|
#include "ConditionServer.h" |
27 |
|
|
28 |
namespace LinuxSampler { |
namespace LinuxSampler { |
29 |
|
|
30 |
ConditionServer::ConditionServer() { |
ConditionServer::ConditionServer() : Reader(Condition) { |
31 |
bConditionQuick = false; |
Condition.GetConfigForUpdate() = false; |
32 |
bChangeRequest = false; |
Condition.SwitchConfig() = false; |
33 |
bOldCondition = false; |
bOldCondition = false; |
34 |
} |
} |
35 |
|
|
36 |
bool* ConditionServer::Push(bool bCondition, long TimeoutSeconds, long TimeoutNanoSeconds) { |
bool* ConditionServer::Push(bool bCondition, long TimeoutSeconds, long TimeoutNanoSeconds) { |
37 |
dmsg(3,("conditionserver:Push() requesting change to %d\n", bCondition)); |
dmsg(3,("conditionserver:Push() requesting change to %d\n", bCondition)); |
38 |
PushMutex.Lock(); |
PushMutex.Lock(); |
39 |
bOldCondition = bConditionQuick; |
bool& c = Condition.GetConfigForUpdate(); |
40 |
if (bConditionQuick != bCondition) { |
bOldCondition = c; |
41 |
bChangeRequest = bCondition; |
c = bCondition; |
42 |
int timeoutexceeded = SyncCondition.WaitAndUnlockIf(bOldCondition, TimeoutSeconds, TimeoutNanoSeconds); // wait until actually condition was changed on Pop() side |
Condition.SwitchConfig() = bCondition; |
|
if (timeoutexceeded) return NULL; |
|
|
} |
|
43 |
return &bOldCondition; |
return &bOldCondition; |
44 |
} |
} |
45 |
|
|
54 |
} |
} |
55 |
|
|
56 |
bool ConditionServer::GetUnsafe() { |
bool ConditionServer::GetUnsafe() { |
57 |
return bConditionQuick; |
return Condition.GetConfigForUpdate(); |
|
} |
|
|
|
|
|
bool ConditionServer::Pop() { |
|
|
if (bConditionQuick == bChangeRequest) return bConditionQuick; |
|
|
dmsg(3,("conditionserver:Pop() change requested\n")); |
|
|
bConditionQuick = bChangeRequest; |
|
|
SyncCondition.Set(bChangeRequest); |
|
|
dmsg(3,("conditionserver:Pop() condition now: %d\n", bConditionQuick)); |
|
|
return bConditionQuick; |
|
58 |
} |
} |
59 |
|
|
60 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |