diff --git a/GNUmakefile b/GNUmakefile index 5e502c7..19f5a04 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -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 diff --git a/threads.c b/threads.c index 0c04daf..d3996c5 100644 --- a/threads.c +++ b/threads.c @@ -44,6 +44,11 @@ #undef MAX_CPUS #define MAX_CPUS CPU_MAXSIZE +#elif defined(TARGET_OS_NETBSD) + +#include +#include + #elif defined(TARGET_OS_SOLARIS) #include #include @@ -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) /*