2022-04-14 22:41:41 +02:00
|
|
|
#pragma once
|
|
|
|
|
2022-04-29 13:34:04 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-04-29 13:34:04 +02:00
|
|
|
template<class T, class... Args>
|
|
|
|
std::unique_ptr<T> make_unique_nothrow(Args &&...args) noexcept(noexcept(T(std::forward<Args>(args)...))) {
|
|
|
|
return std::unique_ptr<T>(new (std::nothrow) T(std::forward<Args>(args)...));
|
|
|
|
}
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-04-29 13:34:04 +02:00
|
|
|
template<class T, class... Args>
|
|
|
|
std::shared_ptr<T> make_shared_nothrow(Args &&...args) noexcept(noexcept(T(std::forward<Args>(args)...))) {
|
|
|
|
return std::shared_ptr<T>(new (std::nothrow) T(std::forward<Args>(args)...));
|
|
|
|
}
|
2022-04-14 22:41:41 +02:00
|
|
|
|
2022-04-29 13:34:04 +02:00
|
|
|
template<typename T, class Allocator, class Predicate>
|
|
|
|
bool remove_locked_first_if(std::mutex &mutex, std::vector<T, Allocator> &list, Predicate pred) {
|
|
|
|
std::lock_guard<std::mutex> lock(mutex);
|
|
|
|
auto it = list.begin();
|
|
|
|
while (it != list.end()) {
|
|
|
|
if (pred(*it)) {
|
|
|
|
list.erase(it);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-14 22:41:41 +02:00
|
|
|
|
|
|
|
// those work only in powers of 2
|
|
|
|
#define ROUNDDOWN(val, align) ((val) & ~(align - 1))
|
2022-08-08 10:12:35 +02:00
|
|
|
#define ROUNDUP(val, align) ROUNDDOWN(((val) + (align - 1)), align)
|
|
|
|
|
|
|
|
void translate_stat(struct stat *posStat, FSStat *fsStat);
|