Skip to content

Commit fb0e71f

Browse files
graphicsManfacebook-github-bot
authored andcommittedMar 6, 2024·
Fix Windows warnings
Summary: We want to ignore the CRT SECURE warnings for our test usage. Additionally, we had one more use of make_shared with a type that had strict alignment requirements. This is still a bug for C++14, so fix this. Reviewed By: RomanFedotovFB Differential Revision: D54215051 fbshipit-source-id: ab2e4e42441a57f012e68db7b17ebc1b021046a1
1 parent 0e193c3 commit fb0e71f

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed
 

‎dispenso/platform.h

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <algorithm>
1414
#include <atomic>
1515
#include <cstdlib>
16+
#include <memory>
1617
#include <thread>
1718
#include <type_traits>
1819

@@ -167,6 +168,13 @@ struct AlignedFreeDeleter<void> {
167168
}
168169
};
169170

171+
template <typename T, class... Args>
172+
std::shared_ptr<T> make_shared(Args&&... args) {
173+
void* tv = alignedMalloc(sizeof(T), alignof(T));
174+
T* t = new (tv) T(std::forward<Args>(args)...);
175+
return std::shared_ptr<T>(t, AlignedFreeDeleter<T>());
176+
}
177+
170178
inline constexpr uintptr_t alignToCacheLine(uintptr_t val) {
171179
constexpr uintptr_t kMask = kCacheLineSize - 1;
172180
val += kMask;

‎dispenso/timed_task.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class TimedTask {
104104
double period = 0.0,
105105
size_t timesToRun = 1,
106106
TimedTaskType type = TimedTaskType::kNormal)
107-
: impl_(std::make_shared<detail::TimedTaskImpl>(
107+
: impl_(detail::make_shared<detail::TimedTaskImpl>(
108108
timesToRun,
109109
nextRunAbs,
110110
period,

‎tests/timed_task_test.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8+
#if defined(_WIN32) && !defined(_CRT_SECURE_NO_WARNINGS)
9+
#define _CRT_SECURE_NO_WARNINGS // We don't want warnings regarding the getenv use in this test.
10+
#endif
11+
812
#include <dispenso/completion_event.h>
913
#include <dispenso/schedulable.h>
1014
#include <dispenso/task_set.h>

0 commit comments

Comments
 (0)
Please sign in to comment.