From c287567888d42e619d6a1accf841301e5bba2556 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 14 Jan 2021 18:29:12 +0100
Subject: Haiku patch


diff --git a/CMakeLists.txt b/CMakeLists.txt
index d320f27..88108cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -320,7 +320,7 @@ else()
     endif()
     if(MINGW)
         check_both_flags_add(-mxsave -fno-asynchronous-unwind-tables)
-    else()
+    elseif(NOT HAIKU)
         check_both_flags_add(-fstack-protector-strong)
         check_both_flags_add(PREPEND -fno-stack-clash-protection)
     endif()
diff --git a/Source/Lib/Common/Codec/EbThreads.c b/Source/Lib/Common/Codec/EbThreads.c
index da2d950..f601aca 100644
--- a/Source/Lib/Common/Codec/EbThreads.c
+++ b/Source/Lib/Common/Codec/EbThreads.c
@@ -84,11 +84,15 @@ EbHandle svt_create_thread(void *thread_function(void *), void *thread_context)
 #if !defined(EB_THREAD_SANITIZER_ENABLED) && !DISABLE_REALTIME
     pthread_attr_t attr;
     pthread_attr_init(&attr);
+#if !defined(__HAIKU__)
     pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
     pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
 
     struct sched_param param = {.sched_priority = 99};
     pthread_attr_setschedparam(&attr, &param);
+#else
+    pthread_attr_setstacksize(&attr, 256 * PAGESIZE);
+#endif
 
     ret = pthread_create(th, &attr, thread_function, thread_context);
     pthread_attr_destroy(&attr);
diff --git a/third_party/cpuinfo/CMakeLists.txt b/third_party/cpuinfo/CMakeLists.txt
index 4f32f9c..3a3116c 100644
--- a/third_party/cpuinfo/CMakeLists.txt
+++ b/third_party/cpuinfo/CMakeLists.txt
@@ -72,7 +72,7 @@ IF(NOT CMAKE_SYSTEM_NAME)
       "Target operating system is not specified. "
       "cpuinfo will compile, but cpuinfo_initialize() will always fail.")
   SET(CPUINFO_SUPPORTED_PLATFORM FALSE)
-ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS|Darwin|Linux|Android|DragonFly|FreeBSD|NetBSD|OpenBSD)$")
+ELSEIF(NOT CMAKE_SYSTEM_NAME MATCHES "^(Windows|CYGWIN|MSYS|Darwin|Linux|Android|DragonFly|FreeBSD|NetBSD|OpenBSD|Haiku)$")
   IF(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.14" AND NOT CMAKE_SYSTEM_NAME STREQUAL "iOS")
     MESSAGE(WARNING
       "Target operating system \"${CMAKE_SYSTEM_NAME}\" is not supported in cpuinfo. "
@@ -92,7 +92,7 @@ IF(CPUINFO_SUPPORTED_PLATFORM)
       src/x86/x86_init.c
       src/x86/vendor.c
       src/x86/isa.c)
-    IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android")
+    IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Android" OR HAIKU)
       LIST(APPEND CPUINFO_SRCS
         src/x86/linux/init.c)
     ELSEIF(CMAKE_SYSTEM_NAME MATCHES "^(DragonFly|FreeBSD|NetBSD|OpenBSD)$")
diff --git a/third_party/cpuinfo/src/init.c b/third_party/cpuinfo/src/init.c
index e183d2e..2b6979c 100644
--- a/third_party/cpuinfo/src/init.c
+++ b/third_party/cpuinfo/src/init.c
@@ -25,7 +25,7 @@ bool CPUINFO_ABI cpuinfo_initialize(void) {
 #if CPUINFO_ARCH_X86 || CPUINFO_ARCH_X86_64
     #if defined(__MACH__) && defined(__APPLE__)
         pthread_once(&init_guard, &cpuinfo_x86_mach_init);
-    #elif defined(__linux__)
+    #elif defined(__linux__) || defined(__HAIKU__)
         pthread_once(&init_guard, &cpuinfo_x86_linux_init);
     #elif defined(_WIN32) || defined(__CYGWIN__)
         InitOnceExecuteOnce(&init_guard, &cpuinfo_x86_windows_init, NULL, NULL);
@@ -35,7 +35,7 @@ bool CPUINFO_ABI cpuinfo_initialize(void) {
         cpuinfo_log_error("operating system is not supported in cpuinfo");
     #endif
 #elif CPUINFO_ARCH_ARM || CPUINFO_ARCH_ARM64
-    #if defined(__linux__)
+    #if defined(__linux__) || defined(__HAIKU__)
         pthread_once(&init_guard, &cpuinfo_arm_linux_init);
     #elif defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
         pthread_once(&init_guard, &cpuinfo_arm_mach_init);
-- 
2.30.2

