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

Side by Side Diff: experimental/conways_life/threading/thread_condition.h

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 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
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Native Client Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef THREAD_CONDITION_H_
6 #define THREAD_CONDITION_H_
7
8 #include "experimental/conways_life/pthread_ext.h"
9
10 namespace threading {
11 // A wrapper class for condition signaling. Contains a mutex and condition
12 // pair.
13 class ThreadCondition {
14 public:
15 // Initialize the mutex and the condition.
16 ThreadCondition() {
17 pthread_mutex_init(&cond_mutex_, NULL);
18 pthread_cond_init(&condition_, NULL);
19 }
20
21 virtual ~ThreadCondition() {
22 pthread_cond_destroy(&condition_);
23 pthread_mutex_destroy(&cond_mutex_);
24 }
25
26 // Lock the mutex, do this before signalling the condition.
27 void Lock() {
28 pthread_mutex_lock(&cond_mutex_);
29 }
30
31 // Unlock the mutex, do this after raising a signal or after returning from
32 // Wait().
33 void Unlock() {
34 pthread_mutex_unlock(&cond_mutex_);
35 }
36
37 // Signal the condition. This will cause Wait() to return.
38 void Signal() {
39 pthread_cond_broadcast(&condition_);
40 }
41
42 // Wait for a Signal(). Note that this can spuriously return, so you should
43 // have a guard bool to see if the condtion is really true. E.g., in the
44 // calling thread:
45 // cond_lock->Lock();
46 // cond_true = true;
47 // cond_lock->Signal();
48 // cond_lock->Unlock();
49 // In the worker thread:
50 // cond_lock->Lock();
51 // while (!cond_true) {
52 // cond_lock->Wait();
53 // }
54 void Wait() {
55 pthread_cond_wait(&condition_, &cond_mutex_);
56 }
57
58 private:
59 pthread_mutex_t cond_mutex_;
60 pthread_cond_t condition_;
61 };
62 } // namespace threading
63
64 #endif // THREAD_CONDITION_H_
OLDNEW
« no previous file with comments | « experimental/conways_life/threading/scoped_mutex_lock.h ('k') | experimental/conways_life/web_resource_loader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698