Skip to content

Commit

Permalink
Windows compatibility fix (#368)
Browse files Browse the repository at this point in the history
* Windows compatibility fix

* Missing header

* Define NOMINMAX to avoid polluting std::max
  • Loading branch information
hcho3 authored Feb 17, 2022
1 parent 60b732a commit 9b416be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 10 additions & 0 deletions include/treelite/predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
#include <mutex>
#include <cstdint>

#ifdef _WIN32
#define NOMINMAX
#include <windows.h>
#endif // _WIN32

namespace treelite {
namespace predictor {

Expand Down Expand Up @@ -71,8 +76,13 @@ union Entry {

class SharedLibrary {
public:
#ifdef _WIN32
using LibraryHandle = HMODULE;
using FunctionHandle = FARPROC;
#else // _WIN32
using LibraryHandle = void*;
using FunctionHandle = void*;
#endif // _WIN32
SharedLibrary();
~SharedLibrary();
void Load(const char* libpath);
Expand Down
7 changes: 1 addition & 6 deletions src/predictor/thread_pool/thread_pool.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,7 @@ class ThreadPool {

inline void SetAffinity() {
#ifdef _WIN32
/* Windows */
SetThreadAffinityMask(GetCurrentThread(), 0x1);
for (int i = 0; i < num_worker_; ++i) {
const int core_id = i + 1;
SetThreadAffinityMask(thread_[i].native_handle(), (1ULL << core_id));
}
/* Do not set thread affinity on Windows */
#elif defined(__APPLE__) && defined(__MACH__)
#include <TargetConditionals.h>
#if TARGET_OS_MAC == 1
Expand Down

0 comments on commit 9b416be

Please sign in to comment.