Skip to content

Commit

Permalink
Add NetBSD support.
Browse files Browse the repository at this point in the history
  • Loading branch information
msaitoh committed Sep 26, 2021
1 parent 807e78a commit 5f851da
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ CFLAGS += -pthread
LDFLAGS += -pthread
endif

ifeq ($(uname_S),NetBSD)
CFLAGS += -pthread
LDFLAGS += -pthread
endif

ifneq ($(findstring MINGW,$(uname_S))$(findstring MSYS,$(uname_S)),)
LDFLAGS += -lpthread -lwinmm
endif
Expand Down
26 changes: 26 additions & 0 deletions threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
#undef MAX_CPUS
#define MAX_CPUS CPU_MAXSIZE

#elif defined(TARGET_OS_NETBSD)

#include <pthread.h>
#include <sched.h>

#elif defined(TARGET_OS_SOLARIS)
#include <string.h>
#include <unistd.h>
Expand Down Expand Up @@ -237,6 +242,27 @@ int thread_bind_native(__unused_variable struct cpuid_state_t *state, uint32_t i

return (ret == 0) ? 0 : 1;

#elif defined (TARGET_OS_NETBSD)

cpuset_t *set;
int ret;

set = cpuset_create();
if (set == NULL)
return 1;

cpuset_zero(set);
ret = cpuset_set(id, set);
if (ret == -1)
return 1;
ret = pthread_setaffinity_np(pthread_self(), cpuset_size(set), set);
cpuset_destroy(set);

if (state && ret == 0)
state->cpu_bound_index = id;

return ret == 0 ? 0 : 1;

#elif defined(TARGET_OS_SOLARIS)

/*
Expand Down

0 comments on commit 5f851da

Please sign in to comment.