A platform for high-performance distributed tool and library development written in C++. It can be deployed in two different cluster modes: standalone or distributed. API for v0.5.0, released on June 13, 2018.
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
PDBBuzzer.cc
Go to the documentation of this file.
1
/*****************************************************************************
2
* *
3
* Copyright 2018 Rice University *
4
* *
5
* Licensed under the Apache License, Version 2.0 (the "License"); *
6
* you may not use this file except in compliance with the License. *
7
* You may obtain a copy of the License at *
8
* *
9
* http://www.apache.org/licenses/LICENSE-2.0 *
10
* *
11
* Unless required by applicable law or agreed to in writing, software *
12
* distributed under the License is distributed on an "AS IS" BASIS, *
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
14
* See the License for the specific language governing permissions and *
15
* limitations under the License. *
16
* *
17
*****************************************************************************/
18
19
#ifndef PDB_BUZZ_C
20
#define PDB_BUZZ_C
21
22
#include "
PDBBuzzer.h
"
23
#include <iostream>
24
25
26
PDBBuzzer::PDBBuzzer
() {
27
28
pthread_cond_init(&
waitingSignal
,
nullptr
);
29
pthread_mutex_init(&
waitingMutex
,
nullptr
);
30
stringFunc
=
nullptr
;
31
signalSent
=
false
;
32
}
33
34
PDBBuzzer::PDBBuzzer
(std::nullptr_t) {
35
pthread_cond_init(&
waitingSignal
,
nullptr
);
36
pthread_mutex_init(&
waitingMutex
,
nullptr
);
37
stringFunc
=
nullptr
;
38
signalSent
=
false
;
39
}
40
41
42
void
PDBBuzzer::buzz
(
PDBAlarm
withMe) {
43
pthread_mutex_lock(&
waitingMutex
);
44
if
(
noStringFunc
!=
nullptr
)
45
noStringFunc
(withMe);
46
pthread_cond_signal(&
waitingSignal
);
47
signalSent
=
true
;
48
pthread_mutex_unlock(&
waitingMutex
);
49
}
50
51
void
PDBBuzzer::buzz
(
PDBAlarm
withMe,
string
message) {
52
pthread_mutex_lock(&
waitingMutex
);
53
if
(
stringFunc
!=
nullptr
)
54
stringFunc
(withMe, message);
55
pthread_cond_signal(&
waitingSignal
);
56
signalSent
=
true
;
57
pthread_mutex_unlock(&
waitingMutex
);
58
}
59
60
void
PDBBuzzer::buzz
(
PDBAlarm
withMe,
int
& counter) {
61
pthread_mutex_lock(&
waitingMutex
);
62
if
(
intFunc
!=
nullptr
)
63
intFunc
(withMe, counter);
64
pthread_cond_signal(&
waitingSignal
);
65
signalSent
=
true
;
66
pthread_mutex_unlock(&
waitingMutex
);
67
}
68
69
void
PDBBuzzer::wait
() {
70
71
// wait until there is a buzz
72
pthread_mutex_lock(&
waitingMutex
);
73
if
(
signalSent
==
true
) {
74
pthread_mutex_unlock(&
waitingMutex
);
75
return
;
76
}
77
pthread_cond_wait(&
waitingSignal
, &
waitingMutex
);
78
pthread_mutex_unlock(&
waitingMutex
);
79
}
80
81
PDBBuzzer::PDBBuzzer
(std::function<
void
(
PDBAlarm
)> noStringFuncIn) {
82
pthread_cond_init(&
waitingSignal
,
nullptr
);
83
pthread_mutex_init(&
waitingMutex
,
nullptr
);
84
noStringFunc
= noStringFuncIn;
85
signalSent
=
false
;
86
}
87
88
PDBBuzzer::PDBBuzzer
(std::function<
void
(
PDBAlarm
, std::string)> stringFuncIn) {
89
pthread_cond_init(&
waitingSignal
,
nullptr
);
90
pthread_mutex_init(&
waitingMutex
,
nullptr
);
91
stringFunc
= stringFuncIn;
92
signalSent
=
false
;
93
}
94
95
PDBBuzzer::PDBBuzzer
(std::function<
void
(
PDBAlarm
,
int
&)> intFuncIn) {
96
pthread_cond_init(&
waitingSignal
,
nullptr
);
97
pthread_mutex_init(&
waitingMutex
,
nullptr
);
98
intFunc
= intFuncIn;
99
signalSent
=
false
;
100
}
101
102
103
PDBBuzzer::~PDBBuzzer
() {
104
pthread_cond_destroy(&
waitingSignal
);
105
pthread_mutex_destroy(&
waitingMutex
);
106
}
107
108
109
#endif
PDBBuzzer::waitingMutex
pthread_mutex_t waitingMutex
Definition:
PDBBuzzer.h:78
PDBBuzzer::~PDBBuzzer
~PDBBuzzer()
Definition:
PDBBuzzer.cc:103
PDBBuzzer::PDBBuzzer
PDBBuzzer()
Definition:
PDBBuzzer.cc:26
PDBBuzzer::intFunc
std::function< void(PDBAlarm, int &)> intFunc
Definition:
PDBBuzzer.h:83
PDBBuzzer::signalSent
bool signalSent
Definition:
PDBBuzzer.h:80
PDBBuzzer.h
PDBBuzzer::buzz
void buzz(PDBAlarm withMe)
Definition:
PDBBuzzer.cc:42
PDBAlarm
PDBAlarm
Definition:
PDBAlarm.h:28
PDBBuzzer::stringFunc
std::function< void(PDBAlarm, std::string)> stringFunc
Definition:
PDBBuzzer.h:82
PDBBuzzer::noStringFunc
std::function< void(PDBAlarm)> noStringFunc
Definition:
PDBBuzzer.h:81
PDBBuzzer::wait
void wait()
Definition:
PDBBuzzer.cc:69
PDBBuzzer::waitingSignal
pthread_cond_t waitingSignal
Definition:
PDBBuzzer.h:79
plinycompute
pdb
src
work
source
PDBBuzzer.cc
Generated on Mon Jun 18 2018 18:10:37 by
1.8.6