Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# For all builds, use C++17
build --cxxopt="-std=c++17"

# Strict diagnostics for this repository's C++ sources.
build:strict --per_file_copt=(co|http_client|http_server)/.*@-Wall,-Wextra,-Wpedantic,-Wconversion,-Wsign-conversion,-Wshadow,-Wnon-virtual-dtor,-Wold-style-cast,-Wcast-align,-Woverloaded-virtual,-Wnull-dereference,-Wdouble-promotion,-Wformat=2,-Wimplicit-fallthrough,-Wundef,-Wextra-semi,-Wcast-qual,-Wmissing-declarations,-Wheader-hygiene,-Wthread-safety,-Wcomma,-Wrange-loop-analysis,-Wdeprecated,-Werror,-Wno-nullability-extension,-Wno-gcc-compat,-Wno-unknown-warning-option

# For Apple Silicon
build:apple_silicon --cpu=darwin_arm64
build:apple_silicon --features=oso_prefix_is_pwd
Expand Down
12 changes: 9 additions & 3 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@ package(default_visibility = ["//visibility:public"])

config_setting(
name = "macos_arm64",
values = {"cpu": "darwin_arm64"},
constraint_values = [
"@platforms//cpu:arm64",
"@platforms//os:macos",
],
)

config_setting(
name = "macos_default",
values = {"cpu": "darwin"},
constraint_values = ["@platforms//os:macos"],
)

config_setting(
name = "macos_x86_64",
values = {"cpu": "darwin_x86_64"},
constraint_values = [
"@platforms//cpu:x86_64",
"@platforms//os:macos",
],
)

alias(
Expand Down
5 changes: 3 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module(
name = "coroutines",
version = "3.3.2",
version = "3.3.3",
)

bazel_dep(name = "bazel_skylib", version = "1.9.0")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "abseil-cpp", version = "20250814.1")
bazel_dep(name = "googletest", version = "1.17.0.bcr.2")
bazel_dep(name = "rules_cc", version = "0.2.16")
bazel_dep(name = "rules_cc", version = "0.2.17")
10 changes: 5 additions & 5 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions co/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ package(default_visibility = ["//visibility:public"])

load("@rules_cc//cc:defs.bzl", "cc_library", "cc_binary", "cc_test")

config_setting(
name = "macos_arm64",
values = {"cpu": "darwin_arm64"},
)

config_setting(
name = "macos_default",
values = {"cpu": "darwin"},
)

config_setting(
name = "macos_x86_64",
values = {"cpu": "darwin_x86_64"},
)

cc_library(
name = "co",
srcs = [
Expand Down
42 changes: 34 additions & 8 deletions co/bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <cstddef>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <stdexcept>
#include <vector>

namespace co {
Expand All @@ -23,7 +25,13 @@ class BitSet {
BitSet() = default;
BitSet(int num_bits) { Resize(num_bits); }

void Resize(int num_bits) { bits_.resize(BitsToWords(num_bits)); }
void Resize(int num_bits) {
if (num_bits <= 0) {
bits_.clear();
return;
}
bits_.resize(BitsToWords(static_cast<size_t>(num_bits)));
}

// Allocate the first free bit.
std::uint32_t Allocate();
Expand All @@ -46,7 +54,14 @@ class BitSet {
}
}

int SizeInBits() const { return bits_.size() * 64; }
int SizeInBits() const {
constexpr size_t kBitsPerWord = 64;
if (bits_.size() >
static_cast<size_t>(std::numeric_limits<int>::max()) / kBitsPerWord) {
return std::numeric_limits<int>::max();
}
return static_cast<int>(bits_.size() * kBitsPerWord);
}

private:
// Note the use of explicit long long type here because
Expand All @@ -58,18 +73,29 @@ class BitSet {
inline std::uint32_t BitSet::Allocate() {
size_t start = 0;
for (;;) {
for (std::uint32_t i = start; i < bits_.size(); i++) {
size_t bit = static_cast<std::uint32_t>(ffsll(~bits_[i]));
if (bit != 0) {
bits_[i] |= (1LL << (bit - 1));
return i * 64 + (bit - 1);
for (size_t i = start; i < bits_.size(); i++) {
const int bit_index = ffsll(~bits_[i]);
if (bit_index == 0) {
continue;
}
const size_t bit = static_cast<size_t>(bit_index);
const size_t allocated = i * 64 + (bit - 1);
if (allocated > std::numeric_limits<std::uint32_t>::max()) {
throw std::overflow_error("BitSet index exceeds uint32_t");
}
bits_[i] |= (1ULL << (bit - 1));
return static_cast<std::uint32_t>(allocated);
}
// Expand bit set and allocate again. There's no point in
// searching the whole bitset again because we know it won't
// have any zero bits in it, so start at the newly added
// word of zeroes.
start = static_cast<std::uint32_t>(bits_.size());
constexpr size_t kMaxWords =
static_cast<size_t>(std::numeric_limits<std::uint32_t>::max()) / 64 + 1;
if (bits_.size() >= kMaxWords) {
throw std::overflow_error("BitSet exhausted uint32_t index space");
}
start = bits_.size();
bits_.push_back(0);
}
}
Expand Down
Loading
Loading