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

Unified Diff: native_client_sdk/src/libraries/sdk_util/auto_lock.h

Issue 23498015: [NaCl SDK] Support non blocking TCP/UDP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge emitter changes 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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/sdk_util/auto_lock.h
diff --git a/native_client_sdk/src/libraries/sdk_util/auto_lock.h b/native_client_sdk/src/libraries/sdk_util/auto_lock.h
index b969416ad78dee5ddf01f6a3730843cb974d2908..9342a21d624608ac557cdd3e1883f52112288bfb 100644
--- a/native_client_sdk/src/libraries/sdk_util/auto_lock.h
+++ b/native_client_sdk/src/libraries/sdk_util/auto_lock.h
@@ -16,6 +16,8 @@ namespace sdk_util {
#define AUTO_LOCK(lock) \
::sdk_util::AutoLock Lock##__LINE__(lock);
+class AutoUnlock;
+
class AutoLock {
public:
AutoLock(const SimpleLock& lock) {
@@ -35,9 +37,46 @@ class AutoLock {
private:
pthread_mutex_t* lock_;
+ friend class AutoUnlock;
DISALLOW_COPY_AND_ASSIGN(AutoLock);
};
+
+class AutoUnlock {
+ public:
+ AutoUnlock() {
+ simple_lock_ = NULL;
+ }
+
+ ~AutoUnlock() {
+ Unlock();
+ }
+
+ void Unlock() {
+ if (simple_lock_)
+ simple_lock_->Unlock();
+
+ simple_lock_ = NULL;
+ }
+
+ void Take(const SimpleLock& lock) {
+ if (simple_lock_ != &lock)
+ Unlock();
+
+ simple_lock_ = &lock;
+ }
+
+ const SimpleLock* Give() {
+ const SimpleLock* out = simple_lock_;
+ simple_lock_ = NULL;
+ return out;
+ }
+
+ private:
+ const SimpleLock* simple_lock_;
+ DISALLOW_COPY_AND_ASSIGN(AutoUnlock);
+};
+
} // namespace sdk_util
#endif // LIBRARIES_SDK_UTIL_AUTO_LOCK_H_

Powered by Google App Engine
This is Rietveld 408576698