| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SHARED_QUEUE_H | 5 #ifndef SHARED_QUEUE_H |
| 6 #define SHARED_QUEUE_H | 6 #define SHARED_QUEUE_H |
| 7 | 7 |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 #include <cassert> | 9 #include <cassert> |
| 10 #include <deque> | 10 #include <deque> |
| 11 | 11 |
| 12 namespace event_queue { | |
| 13 | |
| 14 // This file provides a queue that uses a mutex and condition variable so that | 12 // This file provides a queue that uses a mutex and condition variable so that |
| 15 // one thread can put pointers into the queue and another thread can pull items | 13 // one thread can put pointers into the queue and another thread can pull items |
| 16 // out of the queue. | 14 // out of the queue. |
| 17 | 15 |
| 18 // Specifies whether we want to wait for the queue. | 16 // Specifies whether we want to wait for the queue. |
| 19 enum QueueWaitingFlag { | 17 enum QueueWaitingFlag { |
| 20 kWait = 0, | 18 kWait = 0, |
| 21 kDontWait | 19 kDontWait |
| 22 }; | 20 }; |
| 23 | 21 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 private: | 137 private: |
| 140 std::deque<T> the_queue_; | 138 std::deque<T> the_queue_; |
| 141 bool quit_; | 139 bool quit_; |
| 142 pthread_mutex_t queue_mutex_; | 140 pthread_mutex_t queue_mutex_; |
| 143 pthread_cond_t queue_condition_var_; | 141 pthread_cond_t queue_condition_var_; |
| 144 | 142 |
| 145 // This is used by methods that already have the lock. | 143 // This is used by methods that already have the lock. |
| 146 bool is_empty_no_locking() const { return the_queue_.empty(); } | 144 bool is_empty_no_locking() const { return the_queue_.empty(); } |
| 147 }; | 145 }; |
| 148 | 146 |
| 149 } // end of unnamed namespace | |
| 150 | |
| 151 #endif // SHARED_QUEUE_H | 147 #endif // SHARED_QUEUE_H |
| OLD | NEW |