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

Unified Diff: native_client_sdk/src/libraries/c_salt/threading/thread_condition.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 side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/c_salt/threading/thread_condition.h
diff --git a/native_client_sdk/src/libraries/c_salt/threading/thread_condition.h b/native_client_sdk/src/libraries/c_salt/threading/thread_condition.h
deleted file mode 100644
index 19c63999ce260e5fa4dd3390701b5ec92c747867..0000000000000000000000000000000000000000
--- a/native_client_sdk/src/libraries/c_salt/threading/thread_condition.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright (c) 2012 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 THREAD_CONDITION_H_
-#define THREAD_CONDITION_H_
-
-#include "c_salt/threading/pthread_ext.h"
-
-struct timespec;
-
-namespace c_salt {
-namespace threading {
-// A wrapper class for condition signaling. Contains a mutex and condition
-// pair.
-class ThreadCondition {
- public:
- // Initialize the mutex and the condition.
- ThreadCondition() {
- pthread_mutex_init(&cond_mutex_, NULL);
- pthread_cond_init(&condition_, NULL);
- }
-
- virtual ~ThreadCondition() {
- pthread_cond_destroy(&condition_);
- pthread_mutex_destroy(&cond_mutex_);
- }
-
- // Lock the mutex, do this before signalling the condition.
- void Lock() {
- pthread_mutex_lock(&cond_mutex_);
- }
-
- // Unlock the mutex, do this after raising a signal or after returning from
- // Wait().
- void Unlock() {
- pthread_mutex_unlock(&cond_mutex_);
- }
-
- // Signal the condition. This will cause Wait() to return.
- void Signal() {
- pthread_cond_broadcast(&condition_);
- }
-
- // Wait for a Signal(). Note that this can spuriously return, so you should
- // have a guard bool to see if the condtion is really true. E.g., in the
- // calling thread:
- // cond_lock->Lock();
- // cond_true = true;
- // cond_lock->Signal();
- // cond_lock->Unlock();
- // In the worker thread:
- // cond_lock->Lock();
- // while (!cond_true) {
- // cond_lock->Wait();
- // }
- // cond_lock->Unlock();
- void Wait() {
- pthread_cond_wait(&condition_, &cond_mutex_);
- }
-
- // Same as Wait, but wait at most until abs_time. Returns false if the system
- // time exceeds abs_time before the condition is signaled.
- bool TimedWait(struct timespec *abs_time) {
- return (pthread_cond_timedwait(&condition_, &cond_mutex_, abs_time) == 0);
- }
-
- private:
- pthread_mutex_t cond_mutex_;
- pthread_cond_t condition_;
-};
-} // namespace threading
-} // namespace c_salt
-
-#endif // THREAD_CONDITION_H_
-

Powered by Google App Engine
This is Rietveld 408576698