forked from cameron314/concurrentqueue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbbqueue.h
39 lines (32 loc) · 1.05 KB
/
tbbqueue.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#pragma once
#include <utility>
#include "tbb/concurrent_queue.h"
#include "wrappers.h"
template<typename T>
struct TbbQueueWrapper
{
public:
typedef DummyToken producer_token_t;
typedef DummyToken consumer_token_t;
public:
template<typename U>
inline bool enqueue(U&& item)
{
q.push(std::forward<U>(item));
return true; // assume successful allocation for the sake of the benchmarks
}
inline bool try_dequeue(T& item)
{
return q.try_pop(item);
}
// Dummy token methods (not used)
bool enqueue(producer_token_t const&, T const&) { return false; }
bool try_enqueue(producer_token_t, T const&) { return false; }
bool try_dequeue(consumer_token_t, T& item) { return false; }
template<typename It> bool enqueue_bulk(It, size_t) { return false; }
template<typename It> bool enqueue_bulk(producer_token_t const&, It, size_t) { return false; }
template<typename It> size_t try_dequeue_bulk(It, size_t) { return 0; }
template<typename It> size_t try_dequeue_bulk(consumer_token_t, It, size_t) { return 0; }
private:
tbb::concurrent_queue<T> q;
};