Skip to content

scottjr632/resizable-semaphores

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RezSem - Resizable Semaphores

CI license version

Highlights

A fast adaptive semaphore lock implementation for cpp!

  • Single header file
  • MIT License
  • Require C++17

Quick Start

All you need to do is to include rezsemaphores.hpp and you're good to go

#include <rezsem/rezsemaphores.hpp>

You can either grab the latest version or clone the repository and include the include directory.

Example

$ wget https://raw.githubusercontent.com/scottjr632/resizable-semaphores/v1.0.0/include/rezsem/rezsemaphores.hpp -P rezsem

Usage

Semaphores can be initialized

rezsem::Semaphore s(<initial count>, <limit>);

You can acquire a semaphore by using the Acquire method. Acquire will block until the requested number of locks are acquired.

rezsem::Semaphore s(<initial count>, <limit>);

s.Acquire(); // will be default increment count by one
s.Acquire(n); // will increment the count by `n`

If you do not want to block waiting on a lock to become free, you can use the TryAcquire(n) or TryAcquire() methods.

rezsem::Semaphore s(<initial count>, <limit>);

s.TryAcquire(); // will not block. Will return true if lock is acquired or false if not

To release the lock you can use

s.Release(); // Releases one by default
s.Release(n); // Releases N

Resizing the limit of the semaphore can be done using

s.SetLimit(n); // s.GetLimit() == n

Examples

For examples please see the tests/test_*.cpp files.

About

A fast resizable semaphore implementation for CPP!

Resources

License

Stars

Watchers

Forks

Packages

No packages published