https://github.com/siddiqsoft/daemonlockfile
Trivial implementation of a lockfile class for simple singletons
https://github.com/siddiqsoft/daemonlockfile
daemon nuget-package singleton-pattern windows
Last synced: 4 months ago
JSON representation
Trivial implementation of a lockfile class for simple singletons
- Host: GitHub
- URL: https://github.com/siddiqsoft/daemonlockfile
- Owner: SiddiqSoft
- License: bsd-3-clause
- Created: 2021-07-15T06:56:55.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-07-22T21:32:38.000Z (over 4 years ago)
- Last Synced: 2025-06-17T00:43:22.099Z (5 months ago)
- Topics: daemon, nuget-package, singleton-pattern, windows
- Language: C++
- Homepage:
- Size: 58.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DaemonLockfile : A simple lockfile implementation for modern C++
-------------------------------------------
[](https://github.com/SiddiqSoft/DaemonLockfile/actions/workflows/codeql-analysis.yml)
[](https://dev.azure.com/siddiqsoft/siddiqsoft/_build/latest?definitionId=6&branchName=main)




# Objective
Provide for daemons (applications running as services under docker as an example) to limit themselves to a single instance per "name".
# Requirements
- C++20
- Useful for running "daemons" under docker where you may not always have or wish for a true service under the operating system.
# Usage
- Use the nuget [SiddiqSoft.DaemonLockfile](https://www.nuget.org/packages/SiddiqSoft.DaemonLockfile/)
- You can also git submodule: `git submodule add https://github.com/SiddiqSoft/DaemonLockfile.git`
- Copy paste..whatever works.
Example (when using nuget to add the header in the solution)
```cpp
#include "siddiqsoft/DaemonLockfile.hpp"
// Example daemon host structure
struct MyDaemonType
{
siddiqsoft::DaemonLockfile myLockfile{"MyDaemonType", true}; //force acquire
..
..
};
// The "daemon" will hold the lock and when the application exits the lock will be released.
static MyDaemonType daemon;
int main(int argc, char *argv[])
{
// Bailout immediately if we do not have a lock--this implies some other instance is running
if(!daemon.myLockfile.isLocked) return 1;
..
..
// We have the exclusice lock
}
```
# Roadmap
- [ ] [Lock the underlying lockfile](https://github.com/SiddiqSoft/DaemonLockfile/issues/2)
- [ ] [Crash recovery logic](https://github.com/SiddiqSoft/DaemonLockfile/issues/1)
© 2021 Siddiq Software LLC. All rights reserved.