Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: native_client_sdk/src/libraries/c_salt/threading/scoped_mutex_lock.h

Issue 10854137: [NaCl SDK] gtest_ppapi library. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove hacks Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef SCOPED_MUTEX_LOCK_H_
6 #define SCOPED_MUTEX_LOCK_H_
7
8 #include "c_salt/threading/pthread_ext.h"
9
10 namespace threading {
11 // A small helper RAII class that implements a scoped pthread_mutex lock.
12 class ScopedMutexLock {
13 public:
14 explicit ScopedMutexLock(pthread_mutex_t* mutex) : mutex_(mutex) {
15 if (pthread_mutex_lock(mutex_) != PTHREAD_MUTEX_SUCCESS) {
16 mutex_ = NULL;
17 }
18 }
19 ~ScopedMutexLock() {
20 if (mutex_)
21 pthread_mutex_unlock(mutex_);
22 }
23 bool is_valid() const {
24 return mutex_ != NULL;
25 }
26 private:
27 pthread_mutex_t* mutex_; // Weak reference.
28 };
29 } // namespace threading
30
31 #endif // SCOPED_MUTEX_LOCK_H_
32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698