| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_ | 5 #ifndef LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_ |
| 6 #define LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_ | 6 #define LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_ |
| 7 | 7 |
| 8 #include <pthread.h> | 8 #include <pthread.h> |
| 9 | 9 |
| 10 #include <list> | 10 #include <list> |
| 11 | 11 |
| 12 #include "sdk_util/auto_lock.h" | 12 #include "sdk_util/auto_lock.h" |
| 13 #include "sdk_util/macros.h" | 13 #include "sdk_util/macros.h" |
| 14 | 14 |
| 15 namespace sdk_util { |
| 15 | 16 |
| 16 // ThreadSafeQueue | 17 // ThreadSafeQueue |
| 17 // | 18 // |
| 18 // A simple template to support multithreaded and optionally blocking access | 19 // A simple template to support multithreaded and optionally blocking access |
| 19 // to a Queue of object pointers. | 20 // to a Queue of object pointers. |
| 20 // | 21 // |
| 21 template<class T> class ThreadSafeQueue { | 22 template<class T> class ThreadSafeQueue { |
| 22 public: | 23 public: |
| 23 ThreadSafeQueue() { | 24 ThreadSafeQueue() { |
| 24 pthread_cond_init(&cond_, NULL); | 25 pthread_cond_init(&cond_, NULL); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 50 return item; | 51 return item; |
| 51 } | 52 } |
| 52 | 53 |
| 53 private: | 54 private: |
| 54 std::list<T*> list_; | 55 std::list<T*> list_; |
| 55 pthread_cond_t cond_; | 56 pthread_cond_t cond_; |
| 56 SimpleLock lock_; | 57 SimpleLock lock_; |
| 57 DISALLOW_COPY_AND_ASSIGN(ThreadSafeQueue); | 58 DISALLOW_COPY_AND_ASSIGN(ThreadSafeQueue); |
| 58 }; | 59 }; |
| 59 | 60 |
| 61 } // namespace sdk_util |
| 62 |
| 60 #endif // LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_ | 63 #endif // LIBRARIES_SDK_UTIL_THREAD_SAFE_QUEUE_H_ |
| 61 | 64 |
| OLD | NEW |