TTF Prog
This commit is contained in:
27
src/dawnshared/util/UsageLock.cpp
Normal file
27
src/dawnshared/util/UsageLock.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "util/UsageLock.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
UsageLock::UsageLock() {
|
||||
this->onEmpty = []() {};
|
||||
this->onFirstLock = []() {};
|
||||
}
|
||||
|
||||
usagelockid_t UsageLock::createLock() {
|
||||
usagelockid_t lock = this->nextLock++;
|
||||
this->locks.push_back(lock);
|
||||
if(this->locks.size() == 1) this->onFirstLock();
|
||||
return lock;
|
||||
}
|
||||
|
||||
void UsageLock::removeLock(usagelockid_t lock) {
|
||||
auto it = std::find(this->locks.begin(), this->locks.end(), lock);
|
||||
if(it == this->locks.end()) return;
|
||||
this->locks.erase(it);
|
||||
if(this->locks.size() == 0) this->onEmpty();
|
||||
}
|
39
src/dawnshared/util/UsageLock.hpp
Normal file
39
src/dawnshared/util/UsageLock.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "assert/assert.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
typedef uint32_t usagelockid_t;
|
||||
|
||||
class UsageLock {
|
||||
protected:
|
||||
usagelockid_t nextLock = 0;
|
||||
std::vector<usagelockid_t> locks;
|
||||
|
||||
public:
|
||||
std::function<void()> onEmpty;
|
||||
std::function<void()> onFirstLock;
|
||||
|
||||
/**
|
||||
* Construct a new usage lock object.
|
||||
*/
|
||||
UsageLock();
|
||||
|
||||
/**
|
||||
* Creates a new lock.
|
||||
*
|
||||
* @return Lock created for this specific instance.
|
||||
*/
|
||||
usagelockid_t createLock();
|
||||
|
||||
/**
|
||||
* Removes a lock.
|
||||
*
|
||||
* @param lock Lck to remove.
|
||||
*/
|
||||
void removeLock(usagelockid_t lock);
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user