Skip to content

Commit 5ed882c

Browse files
Merge branch '180-notify_all-notify_one-signature-issue' into 175-174-cond_var-and-mutex-testing
2 parents 2b029ca + 8082896 commit 5ed882c

File tree

2 files changed

+41
-29
lines changed

2 files changed

+41
-29
lines changed

include/pthread/condition_variable.hpp

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ namespace pthread {
6464
* @param mtx ralated mutex, which must be locked by the current thread.
6565
* @see notify_one
6666
* @see notify_all
67+
* @see pthread_cond_wait
6768
*/
6869
void wait(mutex &mtx);
6970

70-
/** @see wai
71+
/** Wait for condition to be signaled within given time frame.
72+
*
73+
* The method uses the lock_guard's mutex to execute.
74+
*
75+
* @see #wait(mutex &)
7176
*/
7277
void wait(lock_guard<pthread::mutex> lck);
7378

@@ -82,10 +87,11 @@ namespace pthread {
8287
* The signature of the predicate function should be equivalent to the following: bool pred();
8388
*
8489
* @param mtx ralated mutex, which must be locked by the current thread.
85-
* @param lambda run to check if condition was met.
90+
* @param lambda code that checks if the condition is met (MUST return a boolean).
8691
* @return true if lmabda returned true.
8792
* @see notify_one
8893
* @see notify_all
94+
* @see pthread_cond_wait
8995
*/
9096
template<class Lambda>
9197
bool wait(mutex &mtx, Lambda lambda);
@@ -101,10 +107,11 @@ namespace pthread {
101107
* The signature of the predicate function should be equivalent to the following: bool pred();
102108
*
103109
* @param lck ralated mutex lock_guard, which must be locked by the current thread.
104-
* @param lambda run to check if condition was met.
110+
* @param lambda code that checks if the condition is met (MUST return a boolean).
105111
* @return true if lmabda returned true.
106112
* @see notify_one
107113
* @see notify_all
114+
* @see pthread_cond_timedwait
108115
*/
109116
template<class Lambda>
110117
bool wait(lock_guard<pthread::mutex> &lck, Lambda lambda);
@@ -125,10 +132,15 @@ namespace pthread {
125132
* @throw condition_variable_exception is thrown either if timeout calculation failed or mutex ownership was wrong.
126133
* @see notify_one
127134
* @see notify_all
135+
* @see pthread_cond_timedwait
128136
*/
129137
cv_status wait_for(mutex &mtx, int millis);
130138

131-
/** @see #wait_for (mutex &, int)
139+
/** Wait for condition to be signaled within given time frame.
140+
*
141+
* The method uses the lock_guard's mutex to execute.
142+
*
143+
* @see #wait_for (mutex &, int)
132144
*/
133145
cv_status wait_for(lock_guard<pthread::mutex> &lck, int millis);
134146

@@ -144,10 +156,11 @@ namespace pthread {
144156
*
145157
* @param mtx ralated mutex, which must be locked by the current thread.
146158
* @param millis milli seconds to wait for condition to be signaled.
147-
* @param lambda run to check if condition was met.
159+
* @param lambda code that checks if the condition is met (MUST return a boolean).
148160
* @return true if lmabda returned true.
149161
* @see notify_one
150162
* @see notify_all
163+
* @see pthread_cond_timedwait
151164
*/
152165
template<class Lambda>
153166
bool wait_for(mutex &mtx, int millis, Lambda lambda);
@@ -168,42 +181,44 @@ namespace pthread {
168181
* @return true if lmabda returned true.
169182
* @see notify_one
170183
* @see notify_all
184+
* @see pthread_cond_timedwait
171185
*/
172186
template<class Lambda>
173187
bool wait_for(lock_guard<pthread::mutex> &lck, int millis, Lambda lambda);
174188

175-
/** Signal one waiting thread.
189+
/** signal a condition.
190+
*
191+
* unblocks at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond).
192+
* > *WARN* the signature of this methode should be the same as `std::condition_variable::notify_one`, we decided to
193+
* > throw an exception anyway, when the pthread function fails and not be strictly compliant.
176194
*
177-
* The call unblocks at least one of the threads that are blocked on the specified condition variable cond (if any threads are blocked on cond).
195+
* @throw condition_variable_exception if the call to pthread_cond_signal return value is different from 0 (zero)
196+
* @see pthread_cond_signal
178197
*/
179-
#if __cplusplus < 201103L
180-
void notify_one () throw() ;
181-
#else
198+
void notify_one() ;
182199

183-
void notify_one() noexcept;
184-
185-
#endif
186-
187-
/** Signal all waiting threads.
200+
/** broadcast a condition.
201+
*
202+
* unblocks all threads currently blocked on the specified condition variable cond.
203+
*
204+
* > *WARN* the signature of this methode should be the same as `std::condition_variable::notify_one`, we decided to
205+
* > throw an exception anyway, when the pthread function fails and not be strictly compliant.
188206
*
189-
* The call unblocks all threads currently blocked on the specified condition variable cond.
207+
* @throw condition_variable_exception if the call to pthread_cond_broadcast return value is different from 0 (zero)
208+
* @see pthread_cond_broadcast
190209
*/
191-
#if __cplusplus < 201103L
192-
void notify_all () throw() ;
193-
#else
194-
195210
void notify_all() noexcept;
196211

197-
#endif
198-
199212
/**
200213
* not copy-assignable
201214
*/
202215
void operator=(const condition_variable &) = delete;
203216

204217
// constructor/destructor ------------------------------------------------
205218

206-
/** construct a new condition_variable (pthread_cond_init).
219+
/** construct a new condition_variable.
220+
*
221+
* @see pthread_cond_init
207222
*/
208223
condition_variable();
209224

@@ -212,9 +227,10 @@ namespace pthread {
212227
*/
213228
condition_variable(const condition_variable &) = delete;
214229

215-
/** destroy a condition_variable (pthread_cond_destroy)
230+
/** destroy a condition_variable.
216231
*
217232
* @throw condition_variable_exception if conditional variable failed to be destroyed (pthread_cond_destroy != 0)
233+
* @see pthread_cond_destroy
218234
*/
219235
~condition_variable() ;
220236

src/condition_variable.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,7 @@ namespace pthread {
4545
return status;
4646
}
4747

48-
#if __cplusplus < 201103L
49-
void condition_variable::notify_one() throw() {
50-
#else
51-
void condition_variable::notify_one() noexcept {
52-
#endif
48+
void condition_variable::notify_one(){
5349
int rc = pthread_cond_signal ( &_condition );
5450
if ( rc != 0 ){
5551
throw condition_variable_exception{"notify_all failed.", rc};

0 commit comments

Comments
 (0)