Skip to content
This repository has been archived by the owner on Jan 26, 2024. It is now read-only.

Commit

Permalink
Fixes for musl support
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsamaroo committed Jan 4, 2021
1 parent 90af834 commit d9f8976
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions os/os.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,17 @@

#if defined(__linux__)
#include <sched.h>
#include <libgen.h>
#endif

#ifdef _WIN32
#include <Basetsd.h> // For KAFFINITY
#endif // _WIN32

#ifndef __cpu_mask
typedef unsigned long __cpu_mask;
#endif

// Smallest supported VM page size.
#define MIN_PAGE_SHIFT 12
#define MIN_PAGE_SIZE (1UL << MIN_PAGE_SHIFT)
Expand Down
7 changes: 7 additions & 0 deletions os/os_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,22 @@ const void* Os::createOsThread(amd::Thread* thread) {
for (int i = 0; i < processorCount_; i++) {
CPU_SET(i, &cpuset);
}
#ifdef pthread_attr_setaffinity_np
if (0 != pthread_attr_setaffinity_np(&threadAttr, sizeof(cpu_set_t), &cpuset)) {
fatal("pthread_attr_setaffinity_np failed to set affinity");
}
#endif
}

pthread_t handle = 0;
if (0 != ::pthread_create(&handle, &threadAttr, (void* (*)(void*)) & Thread::entry, thread)) {
thread->setState(Thread::FAILED);
}
#ifndef pthread_attr_setaffinity_np
if (0 != pthread_setaffinity_np(handle, sizeof(cpu_set_t), &cpuset)) {
fatal("pthread_attr_setaffinity_np failed to set affinity");
}
#endif

::pthread_attr_destroy(&threadAttr);
return reinterpret_cast<const void*>(handle);
Expand Down

0 comments on commit d9f8976

Please sign in to comment.