forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlarge_bitset.cc
37 lines (30 loc) · 815 Bytes
/
large_bitset.cc
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
/*
* Copyright (C) 2015-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#include "utils/assert.hh"
#include "large_bitset.hh"
#include "stall_free.hh"
#include <seastar/core/align.hh>
#include <seastar/core/thread.hh>
using namespace seastar;
large_bitset::large_bitset(size_t nr_bits) : _nr_bits(nr_bits) {
SCYLLA_ASSERT(thread::running_in_thread());
size_t nr_ints = align_up(nr_bits, bits_per_int()) / bits_per_int();
utils::reserve_gently(_storage, nr_ints).get();
while (nr_ints) {
_storage.push_back(0);
--nr_ints;
thread::maybe_yield();
}
}
void
large_bitset::clear() {
SCYLLA_ASSERT(thread::running_in_thread());
for (auto&& pos: _storage) {
pos = 0;
thread::maybe_yield();
}
}