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
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
@@ -1 +1 @@
BasedOnStyle: LLVM
BasedOnStyle: LLVM
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,12 @@ jobs:
enable-windows: true
enable-macos: true
warnings-as-errors: true

pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: pre-commit/action@v3.0.1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ cmake-build-*
.idea/
.project
*~
CMakeUserPresets.json
CMakeUserPresets.json
16 changes: 16 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-json
- id: pretty-format-json
args: [--autofix, --no-sort-keys]
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v19.1.7
hooks:
- id: clang-format
types_or: [c++, c]
52 changes: 43 additions & 9 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,54 @@
"name": "base",
"hidden": true
},
{ "name": "debug", "inherits": "base", "configurePreset": "debug" },
{ "name": "release", "inherits": "base", "configurePreset": "release" },
{ "name": "asan", "inherits": "base", "configurePreset": "asan" },
{ "name": "tsan", "inherits": "base", "configurePreset": "tsan" }
{
"name": "debug",
"inherits": "base",
"configurePreset": "debug"
},
{
"name": "release",
"inherits": "base",
"configurePreset": "release"
},
{
"name": "asan",
"inherits": "base",
"configurePreset": "asan"
},
{
"name": "tsan",
"inherits": "base",
"configurePreset": "tsan"
}
],
"testPresets": [
{
"name": "base",
"hidden": true,
"output": { "outputOnFailure": true }
"output": {
"outputOnFailure": true
}
},
{ "name": "debug", "inherits": "base", "configurePreset": "debug" },
{ "name": "release", "inherits": "base", "configurePreset": "release" },
{ "name": "asan", "inherits": "base", "configurePreset": "asan" },
{ "name": "tsan", "inherits": "base", "configurePreset": "tsan" }
{
"name": "debug",
"inherits": "base",
"configurePreset": "debug"
},
{
"name": "release",
"inherits": "base",
"configurePreset": "release"
},
{
"name": "asan",
"inherits": "base",
"configurePreset": "asan"
},
{
"name": "tsan",
"inherits": "base",
"configurePreset": "tsan"
}
]
}
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It's battle hardened and used daily in production:
It's been cited by the following papers:
- Peizhao Ou and Brian Demsky. 2018. Towards understanding the costs of avoiding
out-of-thin-air results. Proc. ACM Program. Lang. 2, OOPSLA, Article 136
(October 2018), 29 pages. DOI: https://doi.org/10.1145/3276506
(October 2018), 29 pages. DOI: https://doi.org/10.1145/3276506

## Example

Expand Down Expand Up @@ -59,7 +59,7 @@ t2.join();
- `void emplace(Args &&... args);`

Enqueue an item using inplace construction. Blocks if queue is full.

- `bool try_emplace(Args &&... args);`

Try to enqueue an item using inplace construction. Returns `true` on
Expand Down Expand Up @@ -89,7 +89,7 @@ t2.join();

Dequeue an item by copying or moving the item into `v`. Blocks if
queue is empty.

- `bool try_pop(T &v);`

Try to dequeue an item by copying or moving the item into
Expand Down
10 changes: 7 additions & 3 deletions include/rigtorp/MPMCQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class MPMCQueue {
[[nodiscard]] std::ptrdiff_t size() const noexcept {
// TODO: How can we deal with wrapped queue on 32bit?
return static_cast<std::ptrdiff_t>(head_.load(std::memory_order_relaxed) -
tail_.load(std::memory_order_relaxed));
tail_.load(std::memory_order_relaxed));
}

/// Returns true if the queue is empty.
Expand All @@ -237,9 +237,13 @@ class MPMCQueue {
}
}

constexpr std::size_t idx(std::size_t i) const noexcept { return i % capacity_; }
constexpr std::size_t idx(std::size_t i) const noexcept {
return i % capacity_;
}

constexpr std::size_t turn(std::size_t i) const noexcept { return i / capacity_; }
constexpr std::size_t turn(std::size_t i) const noexcept {
return i / capacity_;
}

private:
void deallocate_slots() noexcept {
Expand Down
4 changes: 2 additions & 2 deletions src/MPMCQueueTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ int main(int argc, char *argv[]) {
assert(v && *v == 1);
assert(q.try_pop(v) && *v == 2);
assert(q.try_consume([&v](std::unique_ptr<int> &&w) noexcept {
v = std::move(w);
}) == true);
v = std::move(w);
}) == true);
assert(*v == 3);
}

Expand Down
Loading