https://github.com/marzer/spin_mutex
A C++11 mutex class implemented using atomic spin-waiting.
https://github.com/marzer/spin_mutex
Last synced: over 1 year ago
JSON representation
A C++11 mutex class implemented using atomic spin-waiting.
- Host: GitHub
- URL: https://github.com/marzer/spin_mutex
- Owner: marzer
- License: mit
- Created: 2023-06-07T14:51:54.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-14T16:44:51.000Z (about 3 years ago)
- Last Synced: 2025-01-28T11:18:24.275Z (over 1 year ago)
- Language: C++
- Size: 17.6 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# `mz::spin_mutex` [](./LICENSE) [][cpp_compilers] [][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
```cpp
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 `
There is also support for use as a `meson.build` subproject.
## License
MIT. See [LICENSE](LICENSE).
## Contributing
There are three ways you can contribute:
1. Reporting bug or making feature requests [here](https://github.com/marzer/spin_mutex/issues/new)
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](https://github.com/marzer/muu) and propose your changes there instead.
I will then propagate them to this satellite library when they are merged.
[spin_mutex.hpp]: include/mz/spin_mutex.hpp
[license]: ./LICENSE
[cpp_compilers]: https://en.cppreference.com/w/cpp/compiler_support
[gitter]: https://gitter.im/marzer/community
[sponsor]: https://github.com/sponsors/marzer
[Correctly implementing a spinlock in C++]: https://rigtorp.se/spinlock/
[Intel 64 and IA-32 Architectures Optimization Reference Manual]: https://software.intel.com/sites/default/files/managed/9e/bc/64-ia-32-architectures-optimization-manual.pdf