diff --git a/platform_all/4ed_coroutine.cpp b/platform_all/4ed_coroutine.cpp index f9012344..1932333b 100644 --- a/platform_all/4ed_coroutine.cpp +++ b/platform_all/4ed_coroutine.cpp @@ -80,6 +80,7 @@ PLAT_THREAD_SIG(coroutine_main){ Assert(me->yield_ctx != 0); Assert(me->function != 0); + DBG_POINT(); me->function(&me->head); // NOTE(allen): Wake up the caller and set this coroutine back to being dead. diff --git a/platform_linux/linux_4ed.cpp b/platform_linux/linux_4ed.cpp index 15d4bb2c..72c1be4c 100644 --- a/platform_linux/linux_4ed.cpp +++ b/platform_linux/linux_4ed.cpp @@ -76,6 +76,7 @@ #include "4ed_shared_thread_constants.h" #include "unix_threading_wrapper.h" +#include "linux_semaphore_wrapper.h" // // Linux macros @@ -1821,7 +1822,7 @@ main(int argc, char **argv){ // HACK(allen): THIS SHIT IS FUCKED (happens on mac too) b32 keep_running = linuxvars.keep_running; - + app.step(&sysfunc, &target, &memory_vars, &linuxvars.input, &result); if (result.perform_kill){ diff --git a/platform_linux/linux_semaphore_wrapper.h b/platform_linux/linux_semaphore_wrapper.h new file mode 100644 index 00000000..3fa71919 --- /dev/null +++ b/platform_linux/linux_semaphore_wrapper.h @@ -0,0 +1,34 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 07.11.2017 + * + * Linux semaphore wrapper + * + */ + +// TOP + +union Semaphore{ + sem_t s; + FixSize(SEMAPHORE_TYPE_SIZE); +}; + +internal void +system_init_semaphore(Semaphore *s, u32 count){ + sem_init(&s->s, 0, 0); +} + +internal void +system_wait_on_semaphore(Semaphore *s){ + sem_wait(&s->s); +} + +internal void +system_release_semaphore(Semaphore *s){ + sem_post(&s->s); +} + +// BOTTOM + + diff --git a/platform_mac/mac_4ed.cpp b/platform_mac/mac_4ed.cpp index 142db677..9aa11869 100644 --- a/platform_mac/mac_4ed.cpp +++ b/platform_mac/mac_4ed.cpp @@ -31,6 +31,8 @@ # include "4coder_default_bindings.cpp" #endif +#include "osx_objective_c_to_cpp_links.h" + #include "4ed_math.h" #include "4ed_system.h" @@ -48,6 +50,11 @@ #include #include +#undef external +#undef internal +#include +#define external extern "C" +#define internal static #include #include @@ -56,6 +63,7 @@ #include "4ed_shared_thread_constants.h" #include "unix_threading_wrapper.h" +#include "mac_semaphore_wrapper.h" // TODO(allen): Make an intrinsics header that uses the cracked OS to define a single set of intrinsic names. #define InterlockedCompareExchange(dest, ex, comp) \ @@ -86,7 +94,6 @@ struct OSX_Vars{ //////////////////////////////// -#include "osx_objective_c_to_cpp_links.h" OSX_Objective_C_Vars osx_objc; OSX_Vars osxvars; global Render_Target target; diff --git a/platform_mac/mac_4ed.m b/platform_mac/mac_4ed.m index fcde37ba..ce339f43 100644 --- a/platform_mac/mac_4ed.m +++ b/platform_mac/mac_4ed.m @@ -582,13 +582,13 @@ osx_get_file_change_event(char *buffer, i32 max, i32 *size){ struct kevent event_out; i32 count = kevent(file_change_queue.kq, 0, 0, &event_out, 1, &t); if (count < 0 || (count > 0 && event_out.flags == EV_ERROR)){ - fprintf(stdout, "count: %4d error: %s\n", count, strerror(errno)); + //fprintf(stdout, "count: %4d error: %s\n", count, strerror(errno)); } else if (count > 0){ if (event_out.udata != 0){ i32 len = *(i32*)event_out.udata; char *str = (char*)((i32*)event_out.udata + 1); - fprintf(stdout, "got an event for file: %.*s\n", len, str); + //fprintf(stdout, "got an event for file: %.*s\n", len, str); if (len <= max){ *size = len; memcpy(buffer, str, len); diff --git a/platform_mac/mac_semaphore_wrapper.h b/platform_mac/mac_semaphore_wrapper.h new file mode 100644 index 00000000..9404cda9 --- /dev/null +++ b/platform_mac/mac_semaphore_wrapper.h @@ -0,0 +1,35 @@ +/* + * Mr. 4th Dimention - Allen Webster + * + * 07.11.2017 + * + * Mac semaphore wrapper + * + */ + +// TOP + +union Semaphore{ + semaphore_t s; + FixSize(SEMAPHORE_TYPE_SIZE); +}; + +internal void +system_init_semaphore(Semaphore *s, u32 count){ + task_t task = mach_task_self(); + semaphore_create(task, &s->s, SYNC_POLICY_FIFO, 0); +} + +internal void +system_wait_on_semaphore(Semaphore *s){ + semaphore_wait(s->s); +} + +internal void +system_release_semaphore(Semaphore *s){ + semaphore_signal(s->s); +} + +// BOTTOM + + diff --git a/platform_mac/osx_objective_c_to_cpp_links.h b/platform_mac/osx_objective_c_to_cpp_links.h index aab5f0b0..e8ad9461 100644 --- a/platform_mac/osx_objective_c_to_cpp_links.h +++ b/platform_mac/osx_objective_c_to_cpp_links.h @@ -14,7 +14,7 @@ #include -#if 1 +#if 0 #define DBG_POINT() fprintf(stdout, "%s\n", __FILE__ ":" LINE_STR ":") #else #define DBG_POINT() diff --git a/platform_unix/unix_threading_wrapper.h b/platform_unix/unix_threading_wrapper.h index 9ea8562b..a8d1afd9 100644 --- a/platform_unix/unix_threading_wrapper.h +++ b/platform_unix/unix_threading_wrapper.h @@ -30,11 +30,6 @@ union Condition_Variable{ FixSize(CONDITION_VARIABLE_TYPE_SIZE); }; -union Semaphore{ - sem_t s; - FixSize(SEMAPHORE_TYPE_SIZE); -}; - internal void system_init_and_launch_thread(Thread *t, Thread_Function *proc, void *ptr){ pthread_create(&t->t, 0, proc, ptr); @@ -70,21 +65,6 @@ system_signal_cv(Condition_Variable *cv, Mutex *m){ pthread_cond_signal(&cv->cv); } -internal void -system_init_semaphore(Semaphore *s, u32 count){ - sem_init(&s->s, 0, 0); -} - -internal void -system_wait_on_semaphore(Semaphore *s){ - sem_wait(&s->s); -} - -internal void -system_release_semaphore(Semaphore *s){ - sem_post(&s->s); -} - #endif // BOTTOM