diff --git a/.clang-format b/.clang-format index 468ceea..9b3aa8b 100644 --- a/.clang-format +++ b/.clang-format @@ -1 +1 @@ -BasedOnStyle: LLVM \ No newline at end of file +BasedOnStyle: LLVM diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 20f9faf..ad60b37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.gitignore b/.gitignore index 29f8640..601a2fb 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ cmake-build-* .idea/ .project *~ -CMakeUserPresets.json \ No newline at end of file +CMakeUserPresets.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..073eabc --- /dev/null +++ b/.pre-commit-config.yaml @@ -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] diff --git a/CMakePresets.json b/CMakePresets.json index 6f08a65..ead7bc8 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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" + } ] } diff --git a/LICENSE b/LICENSE index d49012f..77f303e 100644 --- a/LICENSE +++ b/LICENSE @@ -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. - diff --git a/README.md b/README.md index 1bac543..5b4101b 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 @@ -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 diff --git a/include/rigtorp/MPMCQueue.h b/include/rigtorp/MPMCQueue.h index 336e491..6c41519 100644 --- a/include/rigtorp/MPMCQueue.h +++ b/include/rigtorp/MPMCQueue.h @@ -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(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. @@ -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 { diff --git a/src/MPMCQueueTest.cpp b/src/MPMCQueueTest.cpp index 4fddca1..8f3cff0 100644 --- a/src/MPMCQueueTest.cpp +++ b/src/MPMCQueueTest.cpp @@ -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 &&w) noexcept { - v = std::move(w); - }) == true); + v = std::move(w); + }) == true); assert(*v == 3); }