source: s10k/CommonLibs/ConditionalSemaphore/conditionalsemaphore.cpp@ 1131

Last change on this file since 1131 was 1110, checked in by s10k, 6 years ago

slightly modifications to allow subclassing, added Q_OBJECT macro, since usually all classes derived from QObject should use it

File size: 1.9 KB
Line 
1/**
2 * Copyright (C) 2017 - 2018 Fábio Bento (fabiobento512)
3 *
4 * This library is distributed under the MIT License. See notice at the end
5 * of this file.
6 *
7 */
8
9#include "conditionalsemaphore.h"
10
11 namespace Cosemaphore{
12
13ConditionalSemaphore::ConditionalSemaphore():
14 internalCounter(0)
15{
16
17}
18
19void ConditionalSemaphore::SetCondition()
20{
21 this->internalCounter++;
22}
23
24void ConditionalSemaphore::UnsetCondition()
25{
26 this->internalCounter--;
27
28 if(this->internalCounter < 0){
29 throw std::runtime_error("ConditionalSemaphore UnsetCondition called more times than SetCondition.");
30 }
31}
32
33bool ConditionalSemaphore::ConditionIsSet()
34{
35 return this->internalCounter > 0;
36}
37
38 }
39
40/**
41 * Copyright (C) 2017 - 2018 Fábio Bento (fabiobento512)
42 *
43 * Permission is hereby granted, free of charge, to any person
44 * obtaining a copy of this software and associated documentation
45 * files (the "Software"), to deal in the Software without
46 * restriction, including without limitation the rights to use,
47 * copy, modify, merge, publish, distribute, sublicense, and/or sell
48 * copies of the Software, and to permit persons to whom the
49 * Software is furnished to do so, subject to the following
50 * conditions:
51 *
52 * The above copyright notice and this permission notice shall be
53 * included in all copies or substantial portions of the Software.
54 *
55 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
57 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
58 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
59 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
60 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
61 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
62 * OTHER DEALINGS IN THE SOFTWARE.
63 */
Note: See TracBrowser for help on using the repository browser.