mirror of
https://github.com/XTXMarkets/ternfs.git
synced 2026-01-07 03:20:41 -06:00
Also, produce fully static binaries. This means that `gethostname` does not work (doesn't work with static glibc unless you build it with `--enable-static-nss`, which no distro builds glibc with).
40 lines
882 B
C++
40 lines
882 B
C++
#pragma once
|
|
|
|
#include <atomic>
|
|
|
|
#include "Common.hpp"
|
|
#include "Exception.hpp"
|
|
|
|
struct AssertiveLocked {
|
|
private:
|
|
std::atomic<bool>& _held;
|
|
public:
|
|
AssertiveLocked(std::atomic<bool>& held): _held(held) {
|
|
bool expected = false;
|
|
if (!_held.compare_exchange_strong(expected, true)) {
|
|
throw EGGS_EXCEPTION("could not aquire lock, are you using this function concurrently?");
|
|
}
|
|
}
|
|
|
|
AssertiveLocked() = delete;
|
|
AssertiveLocked& operator=(const AssertiveLocked&) = delete;
|
|
|
|
~AssertiveLocked() {
|
|
_held.store(false);
|
|
}
|
|
};
|
|
|
|
struct AssertiveLock {
|
|
private:
|
|
std::atomic<bool> _held;
|
|
public:
|
|
AssertiveLock(): _held(false) {}
|
|
|
|
AssertiveLock(const AssertiveLock&) = delete;
|
|
AssertiveLock& operator=(const AssertiveLock&) = delete;
|
|
|
|
AssertiveLocked lock() {
|
|
return AssertiveLocked(_held);
|
|
}
|
|
};
|