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 9283705682f2925f2d2742b7a444fabf4c400700..3803cfee430abe230ac629a1da667c775695e799 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[(size_t)a_arg].callback(s_timers[(size_t)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,7 +861,17 @@ void *dap_interval_timer_create(unsigned int a_msec, dap_timer_callback_t a_call return NULL; } EnterCriticalSection(&s_timers_lock); -#elif DAP_OS_UNIX +#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); } @@ -926,8 +941,13 @@ 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); #else //DARWIN #endif +#endif } diff --git a/dap-sdk/crypto/src/GOST/block_cipher.c b/dap-sdk/crypto/src/GOST/block_cipher.c index e1f9685be24889e15c1213cf9be4ab6bc8734076..93175427f0e22cb99207cc8cf1fec9060090b65b 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"