diff --git a/dap-sdk/core/include/dap_common.h b/dap-sdk/core/include/dap_common.h index ee1b595c5b0bf212ba7503b81f80452645c06995..39bca787cda8f9239fdc1a78dd1519eb58c6c763 100755 --- a/dap-sdk/core/include/dap_common.h +++ b/dap-sdk/core/include/dap_common.h @@ -33,7 +33,9 @@ #include <stdlib.h> #include <stdio.h> #include <time.h> - +#ifdef __MACH__ +#include <dispatch/dispatch.h> +#endif #include "portable_endian.h" typedef uint8_t byte_t; diff --git a/dap-sdk/core/libdap.pri b/dap-sdk/core/libdap.pri index 3556d8828e0c29a59f3fc03751f2140501bfd503..118eb93d3432898879883b8b6a68940e5987556e 100755 --- a/dap-sdk/core/libdap.pri +++ b/dap-sdk/core/libdap.pri @@ -6,6 +6,7 @@ unix { } darwin { include(src/darwin/darwin.pri) + LIBS -= -lrt } win32 { diff --git a/dap-sdk/core/src/dap_common.c b/dap-sdk/core/src/dap_common.c index 78b63ee843138428d81c0942e56645f498e1eeb0..c2c8cf55f7108cf6e177d04c244346745897f06a 100755 --- a/dap-sdk/core/src/dap_common.c +++ b/dap-sdk/core/src/dap_common.c @@ -829,6 +829,11 @@ static void CALLBACK s_win_callback(PVOID a_arg, BOOLEAN a_always_true) UNUSED(a_always_true); s_timers[(int)a_arg].callback(s_timers[(int)a_arg].param); } +#elif defined __MACH__ +static void s_bsd_callback(int a_arg) +{ + s_timers[a_arg].callback(s_timers[a_arg].param); +} #else static void s_posix_callback(union sigval a_arg) { @@ -856,6 +861,16 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call return NULL; } EnterCriticalSection(&s_timers_lock); +#elif defined __MACH__ + if (s_timers_count == 0) { + pthread_mutex_init(&s_timers_lock, NULL); + } + dispatch_queue_t l_queue = dispatch_queue_create("tqueue", 0); + dispatch_source_t l_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, l_queue); + dispatch_source_set_event_handler(l_timer, ^(void){s_bsd_callback(s_timers_count);}); + dispatch_time_t start = dispatch_time(DISPATCH_TIME_NOW, a_msec * 1000000); + dispatch_source_set_timer(l_timer, start, a_msec * 1000000, 0); + dispatch_resume(l_timer); #else if (s_timers_count == 0) { pthread_mutex_init(&s_timers_lock, NULL); @@ -919,6 +934,11 @@ int dap_interval_timer_delete(void *a_timer) if (s_timers_count == 0) { pthread_mutex_destroy(&s_timers_lock); } +#ifdef __MACH__ + dispatch_source_cancel(a_timer); + return 0; +#else return timer_delete((timer_t)a_timer); #endif +#endif } diff --git a/dap-sdk/crypto/src/GOST/block_cipher.c b/dap-sdk/crypto/src/GOST/block_cipher.c index 80ad6231dc1223690e19b9c84ceac0eea9dafe12..e6b9d16fd0a2faed222b152a08edf7b559cf4db2 100644 --- a/dap-sdk/crypto/src/GOST/block_cipher.c +++ b/dap-sdk/crypto/src/GOST/block_cipher.c @@ -6,7 +6,11 @@ #include <stdio.h> #include <memory.h> +#ifdef __MACH__ +#include <sys/malloc.h> +#else #include <malloc.h> +#endif #include <stdlib.h> #include "28147_14.h"