ref: 8062596d23e32787296f2eca24e51ca7e1291f4a
parent: a239637be5aa448ad311bbe0eb2345f8c668ff7b
author: Martin Storsjö <martin@martin.st>
date: Sun Jan 26 05:22:37 EST 2014
Fix building threading for freebsd FreeBSD (and at least NetBSD as well) still use hw.ncpu without deprecating it, contrary to apple.
--- a/build/platform-freebsd.mk
+++ b/build/platform-freebsd.mk
@@ -1,5 +1,5 @@
ASM = nasm
-CFLAGS += -fPIC
+CFLAGS += -fPIC -DMT_ENABLED
LDFLAGS += -lpthread
ASMFLAGS += -DNOPREFIX
ifeq ($(ENABLE64BIT), Yes)
--- a/codec/common/WelsThreadLib.cpp
+++ b/codec/common/WelsThreadLib.cpp
@@ -44,7 +44,17 @@
#define _GNU_SOURCE
#endif
#include <sched.h>
+#elif !defined(_WIN32)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <sys/param.h>
+#include <unistd.h>
+#ifdef __APPLE__
+#define HW_NCPU_NAME "hw.logicalcpu"
+#else
+#define HW_NCPU_NAME "hw.ncpu"
#endif
+#endif
#include "WelsThreadLib.h"
#include <stdio.h>
@@ -182,12 +192,6 @@
#elif defined(__GNUC__)
-#ifdef __APPLE__
-#include <sys/sysctl.h>
-#include <sys/param.h>
-#include <unistd.h>
-#endif//__APPLE__
-
void WelsSleep (uint32_t dwMilliseconds) {
usleep (dwMilliseconds * 1000); // microseconds
}
@@ -465,7 +469,7 @@
size_t len = sizeof (pInfo->ProcessorCount);
- if (sysctlbyname ("hw.logicalcpu", &pInfo->ProcessorCount, &len, NULL, 0) == -1)
+ if (sysctlbyname (HW_NCPU_NAME, &pInfo->ProcessorCount, &len, NULL, 0) == -1)
pInfo->ProcessorCount = 1;
return WELS_THREAD_ERROR_OK;