]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/QueueRing.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
7 #include "common/ceph_mutex.h"
16 ceph::mutex lock
= ceph::make_mutex("QueueRing::QueueBucket::lock");
17 ceph::condition_variable cond
;
18 typename
std::list
<T
> entries
;
21 QueueBucket(const QueueBucket
& rhs
) {
22 entries
= rhs
.entries
;
25 void enqueue(const T
& entry
) {
27 if (entries
.empty()) {
30 entries
.push_back(entry
);
34 void dequeue(T
*entry
) {
35 std::unique_lock
l(lock
);
36 while (entries
.empty()) {
39 ceph_assert(!entries
.empty());
40 *entry
= entries
.front();
45 std::vector
<QueueBucket
> buckets
;
48 std::atomic
<int64_t> cur_read_bucket
= { 0 };
49 std::atomic
<int64_t> cur_write_bucket
= { 0 };
52 QueueRing(int n
) : buckets(n
), num_buckets(n
) {
55 void enqueue(const T
& entry
) {
56 buckets
[++cur_write_bucket
% num_buckets
].enqueue(entry
);
59 void dequeue(T
*entry
) {
60 buckets
[++cur_read_bucket
% num_buckets
].dequeue(entry
);