12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef _DNS_LOCKED_QUEUE_H
- #define _DNS_LOCKED_QUEUE_H
- #include <algorithm>
- #include <deque>
- #include <mutex>
- #include <android-base/thread_annotations.h>
- namespace android {
- namespace net {
- template <typename T>
- class LockedQueue {
- public:
-
- void push(T item) {
- std::lock_guard guard(mLock);
- mQueue.push_front(std::move(item));
- }
-
- void swap(std::deque<T>& other) {
- std::lock_guard guard(mLock);
- mQueue.swap(other);
- }
- private:
- std::mutex mLock;
- std::deque<T> mQueue GUARDED_BY(mLock);
- };
- }
- }
- #endif
|