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

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

Issue 18644009: [NaCl SDK] Upate atomic ops in nacl_io (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add declartions for newval and oldval Created 7 years, 5 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/thread_safe_queue.h
diff --git a/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h b/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h
index 545b7c4589f6eadcb90ea9238e134d4d717549ff..5dad02874774fd43b63939418130ba7fa7957df6 100644
--- a/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h
+++ b/native_client_sdk/src/libraries/sdk_util/thread_safe_queue.h
@@ -21,28 +21,26 @@
template<class T> class ThreadSafeQueue {
public:
ThreadSafeQueue() {
- pthread_mutex_init(&mutex_, NULL);
pthread_cond_init(&cond_, NULL);
}
~ThreadSafeQueue() {
- pthread_mutex_destroy(&mutex_);
pthread_cond_destroy(&cond_);
}
void Enqueue(T* item) {
- AutoLock lock(&mutex_);
+ AUTO_LOCK(lock_);
list_.push_back(item);
pthread_cond_signal(&cond_);
}
T* Dequeue(bool block) {
- AutoLock lock(&mutex_);
+ AUTO_LOCK(lock_);
// If blocking enabled, wait until we queue is non-empty
if (block) {
- while (list_.empty()) pthread_cond_wait(&cond_, &mutex_);
+ while (list_.empty()) pthread_cond_wait(&cond_, lock_.mutex());
}
if (list_.empty()) return NULL;
@@ -55,7 +53,7 @@ template<class T> class ThreadSafeQueue {
private:
std::list<T*> list_;
pthread_cond_t cond_;
- pthread_mutex_t mutex_;
+ SimpleLock lock_;
DISALLOW_COPY_AND_ASSIGN(ThreadSafeQueue);
};

Powered by Google App Engine
This is Rietveld 408576698