Commit 39013b4d authored by Kenton Varda's avatar Kenton Varda

Cleanup: Use static initializers for pthread objects.

Once upon a time, POSIX specified that these static initializers could only be used for global variables, but apparently essentially all implementations have always supported these initializers for local variables as well, and POSIX recently enshrined this as a requirement.
parent 4a768c2f
......@@ -374,9 +374,7 @@ void Once::reset() {
} \
}
Mutex::Mutex() {
KJ_PTHREAD_CALL(pthread_rwlock_init(&mutex, nullptr));
}
Mutex::Mutex(): mutex(PTHREAD_RWLOCK_INITIALIZER) {}
Mutex::~Mutex() {
KJ_PTHREAD_CLEANUP(pthread_rwlock_destroy(&mutex));
}
......@@ -488,9 +486,9 @@ void Mutex::lockWhen(Predicate& predicate) {
}
}
Once::Once(bool startInitialized): state(startInitialized ? INITIALIZED : UNINITIALIZED) {
KJ_PTHREAD_CALL(pthread_mutex_init(&mutex, nullptr));
}
Once::Once(bool startInitialized)
: state(startInitialized ? INITIALIZED : UNINITIALIZED),
mutex(PTHREAD_MUTEX_INITIALIZER) {}
Once::~Once() {
KJ_PTHREAD_CLEANUP(pthread_mutex_destroy(&mutex));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment