Chromium Code Reviews| Index: base/synchronization/rw_lock_posix.cc |
| diff --git a/base/synchronization/rw_lock_posix.cc b/base/synchronization/rw_lock_posix.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7003978aacc1aad99a2e6a9ea641f7d43346646b |
| --- /dev/null |
| +++ b/base/synchronization/rw_lock_posix.cc |
| @@ -0,0 +1,41 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/synchronization/rw_lock.h" |
| + |
| +#include "base/logging.h" |
| + |
| +namespace base { |
| + |
| +RWLock::RWLock() { |
|
danakj
2016/05/19 23:01:37
can you use PTHREAD_RWLOCK_INITIALIZER similar to
Anand Mistry (off Chromium)
2016/05/20 04:06:38
Done.
Oddly enough, the man on Linux doesn't say
|
| + int rv = pthread_rwlock_init(&native_handle_, nullptr); |
|
danakj
2016/05/19 23:01:37
nit: name "result" instead of rv. ditto elsewhere
Anand Mistry (off Chromium)
2016/05/20 04:06:38
Done.
|
| + DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| +} |
| + |
| +RWLock::~RWLock() { |
| + int rv = pthread_rwlock_destroy(&native_handle_); |
| + DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| +} |
| + |
| +void RWLock::ReadAcquire() { |
| + int rv = pthread_rwlock_rdlock(&native_handle_); |
| + DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| +} |
| + |
| +void RWLock::ReadRelease() { |
| + int rv = pthread_rwlock_unlock(&native_handle_); |
| + DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| +} |
| + |
| +void RWLock::WriteAcquire() { |
| + int rv = pthread_rwlock_wrlock(&native_handle_); |
| + DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| +} |
| + |
| +void RWLock::WriteRelease() { |
| + int rv = pthread_rwlock_unlock(&native_handle_); |
| + DCHECK_EQ(rv, 0) << ". " << strerror(rv); |
| +} |
| + |
| +} // namespace base |