Chromium Code Reviews| Index: native_client_sdk/src/libraries/sdk_util/simple_lock.h |
| diff --git a/native_client_sdk/src/libraries/sdk_util/simple_lock.h b/native_client_sdk/src/libraries/sdk_util/simple_lock.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8188ce8774779d04b54233849008bbfa13b28176 |
| --- /dev/null |
| +++ b/native_client_sdk/src/libraries/sdk_util/simple_lock.h |
| @@ -0,0 +1,38 @@ |
| +/* Copyright (c) 2013 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. |
| + */ |
| + |
| +#ifndef LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ |
| +#define LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ |
| + |
| +#include "pthread.h" |
| +#include "sdk_util/macros.h" |
| + |
| +/* |
| + * SimpleLock |
| + * |
| + * A pthread mutex object, with automatic initialization and destruction. |
| + * Should be used with AutoLock where possible. |
| + */ |
| +class SimpleLock { |
| + public: |
| + SimpleLock() { |
| + pthread_mutex_init(&lock_, NULL); |
| + } |
| + |
| + ~SimpleLock() { |
| + pthread_mutex_destroy(&lock_); |
| + } |
| + |
| + pthread_mutex_t* mutex() const { return &lock_; } |
| + |
| + private: |
| + mutable pthread_mutex_t lock_; |
| + friend class AutoLock; |
|
binji
2013/07/13 00:16:48
doesn't need to be a friend now, does it?
|
| + |
| + DISALLOW_COPY_AND_ASSIGN(SimpleLock); |
| +}; |
| + |
| +#endif // LIBRARIES_SDK_UTIL_SIMPLE_LOCK_H_ |
| + |