Skip to content

Latest commit

 

History

History
71 lines (48 loc) · 2.34 KB

README.md

File metadata and controls

71 lines (48 loc) · 2.34 KB

mz::spin_mutex MIT license C++11 Sponsor Gitter

A std::mutex-compatible mutex class implemented using atomic spin-waiting.

Based on Erik Rigtorp's article Correctly implementing a spinlock in C++ and incorporating some advice from the Intel 64 and IA-32 Architectures Optimization Reference Manual.

Requires C++11.


Synopsis

namespace mz
{
    class spin_mutex
    {
        // acquires a lock on the mutex
        void lock() noexcept;

        // tries to acquire a lock on the mutex,
        // returning true if the lock was successfully acquired
        bool try_lock() noexcept;

        // releases the lock currently held on the mutex
        void unlock() noexcept;
    };
}

Usage

The library is a single header so the easiest way to use it is to drop spin_mutex.hpp somewhere in your project.

Alternatively you can add include to your include paths then #include <mz/spin_mutex.hpp>

There is also support for use as a meson.build subproject.


License

MIT. See LICENSE.


Contributing

There are three ways you can contribute:

  1. Reporting bug or making feature requests here
  2. Opening a pull request (⚠️ caveat - see below)
  3. Becoming a sponsor ❤️

Pull requests

spin_mutex.hpp is programmatically extracted from a much larger project so I won't accept pull requests made for this repository directly; if you wish to contribute a bugfix or a feature, please find the spin_mutex implementation in this project and propose your changes there instead. I will then propagate them to this satellite library when they are merged.