43 Deinitializer(pthread_mutexattr_t& attributes):
47 const int result = pthread_mutexattr_destroy(&
attributes_);
60 pthread_mutexattr_t attributes;
61 int result = pthread_mutexattr_init(&attributes);
66 throw std::bad_alloc();
70 Deinitializer deinitializer(attributes);
77 result = pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_ERRORCHECK);
79 result = pthread_mutexattr_settype(&attributes, PTHREAD_MUTEX_NORMAL);
85 unique_ptr<Impl> impl(
new Impl);
86 result = pthread_mutex_init(&impl->mutex, &attributes);
89 impl_ = impl.release();
93 throw std::bad_alloc();
101 const int result = pthread_mutex_destroy(&impl_->
mutex);
104 const bool locked = impl_->locked_count != 0;
127Mutex::postLockAction() {
128 assert(impl_->locked_count == 0);
129 ++impl_->locked_count;
133Mutex::preUnlockAction(
bool throw_ok) {
134 if (impl_->locked_count == 0) {
137 "Unlock attempt for unlocked mutex");
142 --impl_->locked_count;
147 return (impl_->locked_count != 0);
154 assert(impl_ != NULL);
155 const int result = pthread_mutex_lock(&impl_->
mutex);
166 assert(impl_ != NULL);
167 const int result = pthread_mutex_trylock(&impl_->
mutex);
173 if (result == EBUSY || result == EDEADLK) {
175 }
else if (result != 0) {
186 assert(impl_ != NULL);
188 preUnlockAction(
false);
190 const int result = pthread_mutex_unlock(&impl_->
mutex);
197 const int result = pthread_cond_init(&
cond_, NULL);
200 << std::strerror(result));
204 const int result = pthread_cond_destroy(&
cond_);
227 mutex.preUnlockAction(
true);
228 const int result = pthread_cond_wait(&impl_->
cond_, &mutex.impl_->mutex);
229 mutex.postLockAction();
231 const int result = pthread_cond_wait(&impl_->
cond_, &mutex.impl_->mutex);
237 std::strerror(result));
243 const int result = pthread_cond_signal(&impl_->
cond_);
A generic exception that is thrown if a parameter given to a method is considered invalid in that con...
A generic exception that is thrown if a function is called in a prohibited way.
A generic exception that is thrown when an unexpected error condition occurs.
void wait(Mutex &mutex)
Wait on the condition variable.
void signal()
Unblock a thread waiting for the condition variable.
Mutex with very simple interface.
bool locked() const
If the mutex is currently locked.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
Defines the logger used by the top-level component of kea-dhcp-ddns.
pthread_mutexattr_t & attributes_