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

Side by Side Diff: native_client_sdk/src/libraries/sdk_util/simple_lock.h

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 7 years, 3 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
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ 5 #ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
6 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ 6 #define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
7 7
8 #include "pthread.h" 8 #include "pthread.h"
9 #include "sdk_util/macros.h" 9 #include "sdk_util/macros.h"
10 10
11 namespace sdk_util { 11 namespace sdk_util {
12 12
13 /* 13 /*
14 * SimpleLock 14 * SimpleLock
15 * 15 *
16 * A pthread mutex object, with automatic initialization and destruction. 16 * A pthread mutex object, with automatic initialization and destruction.
17 * Should be used with AutoLock where possible. 17 * Should be used with AutoLock where possible.
18 */ 18 */
19 class SimpleLock { 19 class SimpleLock {
20 public: 20 public:
21 SimpleLock() { 21 SimpleLock() {
22 pthread_mutex_init(&lock_, NULL); 22 pthread_mutex_init(&lock_, NULL);
23 } 23 }
24 24
25 ~SimpleLock() { 25 ~SimpleLock() {
26 pthread_mutex_destroy(&lock_); 26 pthread_mutex_destroy(&lock_);
27 } 27 }
28 28
29 void Lock() const { pthread_mutex_lock(&lock_); }
30 void Unlock() const { pthread_mutex_unlock(&lock_); }
31
29 pthread_mutex_t* mutex() const { return &lock_; } 32 pthread_mutex_t* mutex() const { return &lock_; }
30 33
31 private: 34 private:
32 mutable pthread_mutex_t lock_; 35 mutable pthread_mutex_t lock_;
33 36
34 DISALLOW_COPY_AND_ASSIGN(SimpleLock); 37 DISALLOW_COPY_AND_ASSIGN(SimpleLock);
35 }; 38 };
36 39
37 } // namespace sdk_util 40 } // namespace sdk_util
38 41
39 #endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ 42 #endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_
OLDNEW
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/syscalls/pipe.c ('k') | native_client_sdk/src/tests/nacl_io_socket_test/event_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698