summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--meson.build2
-rw-r--r--src/common.c7
-rw-r--r--src/ev_embed_compat.c1
-rw-r--r--src/evwrap.h2
-rw-r--r--src/util/error.h8
-rw-r--r--src/winwrap.c7
-rw-r--r--src/winwrap.h2
-rw-r--r--subprojects/libev.wrap2
-rw-r--r--subprojects/packagefiles/libev/libev_aki_sleep.diff37
-rw-r--r--subprojects/packagefiles/libev/libev_aki_sleep_no_monotonic.diff60
10 files changed, 76 insertions, 52 deletions
diff --git a/meson.build b/meson.build
index 6e60976..2f2e51b 100644
--- a/meson.build
+++ b/meson.build
@@ -9,7 +9,6 @@ is_windows = host_machine.system() == 'windows'
akiyo_src = [
'src/common.c',
- 'src/winwrap.c',
'src/util/error.c',
'src/util/buffer.c',
'src/util/packet.c',
@@ -108,6 +107,7 @@ if not is_windows
akiyo_has_mmap = true
else
akiyo_src += [
+ 'src/winwrap.c',
'src/util/timer/timer_windows.c',
'src/util/thread/thread_windows.c',
'src/util/file/file_stdio.c',
diff --git a/src/common.c b/src/common.c
index 3c76cbd..803ce97 100644
--- a/src/common.c
+++ b/src/common.c
@@ -9,7 +9,6 @@
#endif
#include "common.h"
-#include "winwrap.h"
bool aki_common_init(void)
{
@@ -17,8 +16,9 @@ bool aki_common_init(void)
al_malloc_init();
al_rand_init();
-
+#ifdef _WIN32
aki_windows_init();
+#endif
#ifndef _WIN32
al_set_page_size(sysconf(_SC_PAGESIZE));
@@ -33,7 +33,8 @@ bool aki_common_init(void)
void aki_common_close(void)
{
+#ifdef _WIN32
aki_windows_close();
-
+#endif
al_malloc_close();
}
diff --git a/src/ev_embed_compat.c b/src/ev_embed_compat.c
index 7fb39fb..8e36572 100644
--- a/src/ev_embed_compat.c
+++ b/src/ev_embed_compat.c
@@ -1,6 +1,7 @@
#define EV_STANDALONE 1
#define EV_USE_NANOSLEEP 1
#define EV_USE_REALTIME 1
+#define EV_USE_MONOTONIC 1
#ifdef _WIN32
#define FD_SETSIZE 2048
#define EV_SELECT_IS_WINSOCKET 1
diff --git a/src/evwrap.h b/src/evwrap.h
index 331da06..02ad980 100644
--- a/src/evwrap.h
+++ b/src/evwrap.h
@@ -5,7 +5,7 @@
#define EV_MULTIPLICITY 1
#define EV_STAT_ENABLE 0
-//#define EV_PERIODIC_ENABLE 0
+#define EV_PERIODIC_ENABLE 0
#define EV_SIGNAL_ENABLE 0
#define EV_CHILD_ENABLE 0
#define EV_IDLE_ENABLE 0
diff --git a/src/util/error.h b/src/util/error.h
index 0849ddb..c45f0f0 100644
--- a/src/util/error.h
+++ b/src/util/error.h
@@ -1,3 +1,5 @@
+#pragma once
+
#include <al/lib.h>
#include <errno.h>
@@ -9,7 +11,11 @@ extern __al_thread char errorbuf[AKI_ERROR_STR_MAXLEN];
static inline char *aki_strerror(s32 errnum)
{
#ifndef _WIN32
- (void)!strerror_r(errnum, errorbuf, AKI_ERROR_STR_MAXLEN);
+#if (_POSIX_C_SOURCE >= 200112L) && ! _GNU_SOURCE
+ if (strerror_r(errnum, errorbuf, AKI_ERROR_STR_MAXLEN) != 0) errorbuf[0] = '\0';
+#else
+ return strerror_r(errnum, errorbuf, AKI_ERROR_STR_MAXLEN);
+#endif
#else
strerror_s(errorbuf, AKI_ERROR_STR_MAXLEN, errnum);
#endif
diff --git a/src/winwrap.c b/src/winwrap.c
index b1ab115..dcfdef9 100644
--- a/src/winwrap.c
+++ b/src/winwrap.c
@@ -2,7 +2,7 @@
void aki_windows_init(void)
{
-#ifdef _WIN32
+ // https://learn.microsoft.com/en-us/windows/win32/api/objbase/ne-objbase-coinit
CoInitialize(NULL);
WSADATA data;
@@ -16,17 +16,12 @@ void aki_windows_init(void)
NtDelayExecution = (NTSTATUS(__stdcall *)(BOOL, PLARGE_INTEGER))GetProcAddress(GetModuleHandleW(L"ntdll"), "NtDelayExecution");
QueryPerformanceFrequency(&performance_frequency);
-#endif
}
void aki_windows_close(void)
{
-#ifdef _WIN32
WSACleanup();
CoUninitialize();
-#endif
}
-#ifdef _WIN32
LARGE_INTEGER performance_frequency;
-#endif
diff --git a/src/winwrap.h b/src/winwrap.h
index 8a6b90d..2c71dc0 100644
--- a/src/winwrap.h
+++ b/src/winwrap.h
@@ -2,7 +2,6 @@
#include <al/lib.h>
-#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>
@@ -13,7 +12,6 @@
#include <ntstatus.h>
extern NTSTATUS(__stdcall *NtDelayExecution)(BOOL Alertable, PLARGE_INTEGER DelayInterval);
extern LARGE_INTEGER performance_frequency;
-#endif
void aki_windows_init(void);
void aki_windows_close(void);
diff --git a/subprojects/libev.wrap b/subprojects/libev.wrap
index 22fed20..0cde03e 100644
--- a/subprojects/libev.wrap
+++ b/subprojects/libev.wrap
@@ -6,7 +6,7 @@ source_filename = libev-4.33.tar.gz
source_hash = 507eb7b8d1015fbec5b935f34ebed15bf346bed04a11ab82b8eee848c4205aea
patch_directory = libev
-diff_files = libev/libev_aki_sleep.diff
+diff_files = libev/libev_aki_sleep_no_monotonic.diff
[provide]
dependency_names = libev
diff --git a/subprojects/packagefiles/libev/libev_aki_sleep.diff b/subprojects/packagefiles/libev/libev_aki_sleep.diff
deleted file mode 100644
index f41b96d..0000000
--- a/subprojects/packagefiles/libev/libev_aki_sleep.diff
+++ /dev/null
@@ -1,37 +0,0 @@
---- ev.c 2020-03-18 08:27:32.000000000 -0400
-+++ ../ev.c 2023-09-21 16:15:10.219097499 -0400
-@@ -216,6 +216,8 @@
-
- #include <signal.h>
-
-+#include <aki/thread.h>
-+
- #ifdef EV_H
- # include EV_H
- #else
-@@ -2216,24 +2218,7 @@
- {
- if (delay > EV_TS_CONST (0.))
- {
--#if EV_USE_NANOSLEEP
-- struct timespec ts;
--
-- EV_TS_SET (ts, delay);
-- nanosleep (&ts, 0);
--#elif defined _WIN32
-- /* maybe this should round up, as ms is very low resolution */
-- /* compared to select (µs) or nanosleep (ns) */
-- Sleep ((unsigned long)(EV_TS_TO_MSEC (delay)));
--#else
-- struct timeval tv;
--
-- /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
-- /* something not guaranteed by newer posix versions, but guaranteed */
-- /* by older ones */
-- EV_TV_SET (tv, delay);
-- select (0, 0, 0, 0, &tv);
--#endif
-+ aki_thread_sleep (delay);
- }
- }
-
diff --git a/subprojects/packagefiles/libev/libev_aki_sleep_no_monotonic.diff b/subprojects/packagefiles/libev/libev_aki_sleep_no_monotonic.diff
new file mode 100644
index 0000000..2080116
--- /dev/null
+++ b/subprojects/packagefiles/libev/libev_aki_sleep_no_monotonic.diff
@@ -0,0 +1,60 @@
+--- a/ev.c 2020-03-18 08:27:32.000000000 -0400
++++ b/ev.c 2024-01-16 15:42:39.360703755 -0400
+@@ -216,6 +216,8 @@
+
+ #include <signal.h>
+
++#include <aki/thread.h>
++
+ #ifdef EV_H
+ # include EV_H
+ #else
+@@ -437,7 +439,7 @@
+ /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
+ /* which makes programs even slower. might work on other unices, too. */
+ #if EV_USE_CLOCK_SYSCALL
+-# include <sys/syscall.h>
++# include <unistd.h>
+ # ifdef SYS_clock_gettime
+ # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
+ # undef EV_USE_MONOTONIC
+@@ -2216,24 +2218,7 @@
+ {
+ if (delay > EV_TS_CONST (0.))
+ {
+-#if EV_USE_NANOSLEEP
+- struct timespec ts;
+-
+- EV_TS_SET (ts, delay);
+- nanosleep (&ts, 0);
+-#elif defined _WIN32
+- /* maybe this should round up, as ms is very low resolution */
+- /* compared to select (µs) or nanosleep (ns) */
+- Sleep ((unsigned long)(EV_TS_TO_MSEC (delay)));
+-#else
+- struct timeval tv;
+-
+- /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
+- /* something not guaranteed by newer posix versions, but guaranteed */
+- /* by older ones */
+- EV_TV_SET (tv, delay);
+- select (0, 0, 0, 0, &tv);
+-#endif
++ aki_thread_sleep (delay);
+ }
+ }
+
+@@ -4100,11 +4085,13 @@
+ waittime = EV_TS_CONST (MAX_BLOCKTIME2);
+ #endif
+ #if !EV_PERIODIC_ENABLE
++#if EV_USE_MONOTONIC
+ /* without periodics but with monotonic clock there is no need */
+ /* for any time jump detection, so sleep longer */
+ if (ecb_expect_true (have_monotonic))
+ waittime = EV_TS_CONST (MAX_BLOCKTIME2);
+ #endif
++#endif
+
+ if (timercnt)
+ {