fix temporary
This commit is contained in:
parent
15b3e4d549
commit
59df377fde
@ -33,7 +33,9 @@ namespace util {
|
|||||||
std::shared_ptr<T> create(Args&&... args) {
|
std::shared_ptr<T> create(Args&&... args) {
|
||||||
std::lock_guard lock(mutex);
|
std::lock_guard lock(mutex);
|
||||||
if (freeObjects.empty()) {
|
if (freeObjects.empty()) {
|
||||||
allocateNew();
|
if (!allocateNew()) {
|
||||||
|
return std::make_shared<T>(std::forward<Args>(args)...);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
auto ptr = freeObjects.front();
|
auto ptr = freeObjects.front();
|
||||||
freeObjects.pop();
|
freeObjects.pop();
|
||||||
@ -49,7 +51,7 @@ namespace util {
|
|||||||
std::queue<void*> freeObjects;
|
std::queue<void*> freeObjects;
|
||||||
std::mutex mutex;
|
std::mutex mutex;
|
||||||
|
|
||||||
void allocateNew() {
|
bool allocateNew() {
|
||||||
std::unique_ptr<void, AlignedDeleter> ptr(
|
std::unique_ptr<void, AlignedDeleter> ptr(
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
_aligned_malloc(sizeof(T), alignof(T))
|
_aligned_malloc(sizeof(T), alignof(T))
|
||||||
@ -57,8 +59,12 @@ namespace util {
|
|||||||
std::aligned_alloc(alignof(T), sizeof(T))
|
std::aligned_alloc(alignof(T), sizeof(T))
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
if (ptr == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
freeObjects.push(ptr.get());
|
freeObjects.push(ptr.get());
|
||||||
objects.push_back(std::move(ptr));
|
objects.push_back(std::move(ptr));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user