Skip to content
This repository was archived by the owner on Jun 12, 2024. It is now read-only.

fix macos gcc build by removing unneeded obj-c deps #9

Merged
merged 5 commits into from
Apr 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -102,10 +102,6 @@ if (EMSCRIPTEN)
list(REMOVE_ITEM SOURCE_FILES include/sx/fiber.h)
endif()

if (APPLE)
list(APPEND SOURCE_FILES src/os.m)
endif()

####################################################################################################
# Assembly files for fcontext
if (APPLE)
@@ -134,7 +130,7 @@ elseif (UNIX)
else()
set(CPU_ARCH "i386")
endif()
set(ASM_EXT "sysv_elf_gas.S")
set(ASM_EXT "sysv_elf_gas.S")
elseif (WIN32)
# Windows (x86/64)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
@@ -180,11 +176,10 @@ if ((CMAKE_C_COMPILER_ID MATCHES "Clang") OR (CMAKE_C_COMPILER_ID MATCHES "GNU")
endif()
add_compile_options("$<$<CONFIG:Debug>:-D_DEBUG>")
add_compile_options("$<$<CONFIG:Release>:-DNDEBUG>")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-rtti -fno-exceptions")
sx_remove_compile_options(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "-fexceptions -frtti")
elseif (MSVC)
elseif (MSVC)
sx_remove_compile_options(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" "/EHsc /GR")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
endif()
@@ -215,8 +210,6 @@ if (ANDROID)
target_link_libraries(sx PUBLIC dl m PRIVATE cpufeatures)
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(sx PUBLIC dl pthread m)
elseif (APPLE)
target_link_libraries(sx PUBLIC "-framework Foundation")
elseif (WIN32)
target_link_libraries(sx PUBLIC psapi)
endif()
2 changes: 1 addition & 1 deletion include/sx/jobs.h
Original file line number Diff line number Diff line change
@@ -132,4 +132,4 @@ SX_API sx_job_t sx_job_dispatch(sx_job_context* ctx, const sx_job_desc* descs, i
SX_API void sx_job_wait_and_del(sx_job_context* ctx, sx_job_t job);
SX_API bool sx_job_test_and_del(sx_job_context* ctx, sx_job_t job);
SX_API int sx_job_num_worker_threads(sx_job_context* ctx);
SX_API void sx_job_set_current_thread_tags(sx_job_context* ctx, unsigned int tags);
SX_API void sx_job_set_current_thread_tags(sx_job_context* ctx, unsigned int tags);
16 changes: 12 additions & 4 deletions src/os.c
Original file line number Diff line number Diff line change
@@ -43,6 +43,8 @@
# include <copyfile.h>
# include <mach/mach.h>
# include <mach-o/dyld.h> // _NSGetExecutablePath
# include <sys/types.h>
# include <sys/sysctl.h>
# elif SX_PLATFORM_HURD
# include <pthread/pthread.h>
# elif SX_PLATFORM_BSD
@@ -598,9 +600,6 @@ char* sx_os_path_normpath(char* dst, int size, const char* path) {
#endif
}

// https://stackoverflow.com/questions/150355/programmatically-find-the-number-of-cores-on-a-machine
int apple__numcores(); // fwd: os.m

int sx_os_numcores() {
#if SX_PLATFORM_WINDOWS
SYSTEM_INFO sysinfo;
@@ -611,7 +610,16 @@ int sx_os_numcores() {
#elif SX_PLATFORM_ANDROID
return android_getCpuCount();
#elif SX_PLATFORM_APPLE
return apple__numcores();
int ncpu;
size_t ncpu_len = sizeof(ncpu);
// hw.physicalcpu - The number of physical processors available in the current power management mode.
// hw.physicalcpu_max - The maximum number of physical processors that could be available this boot.
// hw.logicalcpu - The number of logical processors available in the current power management mode.
// hw.logicalcpu_max - The maximum number of logical processors that could be available this boot.
if (sysctlbyname("hw.logicalcpu", &ncpu, &ncpu_len, NULL, 0) == 0)
return ncpu;
return 1;

#elif SX_PLATFORM_BSD
int ctlarg[2], ncpu;
size_t len;
7 changes: 0 additions & 7 deletions src/os.m

This file was deleted.

13 changes: 0 additions & 13 deletions src/sx.c
Original file line number Diff line number Diff line change
@@ -8,13 +8,6 @@
# include <android/log.h>
#elif SX_PLATFORM_WINDOWS
__declspec(dllimport) void __stdcall OutputDebugStringA(const char* _str);
#elif SX_PLATFORM_APPLE
# if defined(__OBJC__)
# import <Foundation/NSObjCRuntime.h>
# else
# include <CoreFoundation/CFString.h>
void NSLog(CFStringRef _format, ...);
# endif // defined(__OBJC__)
#else
# include <stdio.h> // fputs, fflush
#endif
@@ -31,12 +24,6 @@ void sx__break_program(const char* text) {
__android_log_write(ANDROID_LOG_DEBUG, "", text);
#elif SX_PLATFORM_WINDOWS
OutputDebugStringA(text);
#elif SX_PLATFORM_APPLE
# if defined(__OBJC__)
NSLog(@"%s", text);
# else
NSLog(__CFStringMakeConstantString("%s"), text);
# endif
#else
fputs(text, stderr);
fflush(stderr);
10 changes: 3 additions & 7 deletions tests/test-jobs.c
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
#define MAX_FIBERS 100
#define STACK_SIZE 128 * 1024

static sx_rng g_rng;
static sx_job_context* g_ctx = NULL;

static void thread_init(sx_job_context* ctx, int thread_index, uint32_t thread_id, void* user) {
@@ -37,18 +36,16 @@ static void job_fib_fn(int index, void* user) {
b = f;
}

const sx_job_desc jobs[] = { { job_wait_fn, NULL, SX_JOB_PRIORITY_HIGH },
{ job_wait_fn, NULL, SX_JOB_PRIORITY_HIGH } };
// if (sx_rng_gen_irange(&g_rng, 1, 100) < 50) {
const sx_job_desc jobs[] = { { job_wait_fn, user, SX_JOB_PRIORITY_HIGH },
{ job_wait_fn, user, SX_JOB_PRIORITY_HIGH } };

sx_job_t job = sx_job_dispatch(g_ctx, jobs, 1, 0);
sx_job_wait_and_del(g_ctx, job);
//}

*((uint32_t*)user) = b;
}

int main(int argc, char* argv[]) {
sx_rng_seed(&g_rng, (uint32_t)time(NULL));
const sx_alloc* alloc = sx_alloc_malloc();
sx_job_context* ctx = sx_job_create_context(
alloc, &(sx_job_context_desc){ .thread_init_cb = thread_init,
@@ -84,7 +81,6 @@ int main(int argc, char* argv[]) {

puts("Dispatching jobs ...");
sx_job_t jhandle = sx_job_dispatch(ctx, jobs, 3, 0);
// sx_os_sleep(1000);

puts("Waiting ...");
sx_job_wait_and_del(ctx, jhandle);