diff --git a/ev.c b/ev.c index 3478cf38..5df3aefb 100644 --- a/ev.c +++ b/ev.c @@ -766,8 +766,8 @@ EV_LOCAL int ev__fs_remove(const char* path, int recursive); // #line 13 "ev.c" //////////////////////////////////////////////////////////////////////////////// // FILE: ev/misc_internal.h -// SIZE: 724 -// SHA-256: a81194a7b3f7a4ce2b6251095a548c0b082a28e8e1de7916d822f7c5335bfb9d +// SIZE: 767 +// SHA-256: d868e98713600d57cf502123aaffa79eb35ea0d27edc2b49be60d238602e0e49 //////////////////////////////////////////////////////////////////////////////// // #line 1 "ev/misc_internal.h" #ifndef __EV_MISC_INTERNAL_H__ @@ -798,6 +798,8 @@ EV_LOCAL int ev__translate_posix_sys_error(int syserr); */ EV_LOCAL int ev__random(void* buf, size_t len); +EV_LOCAL void ev__backend_shutdown(void); + #ifdef __cplusplus } #endif @@ -2250,14 +2252,14 @@ extern "C" { // #line 32 "ev.c" //////////////////////////////////////////////////////////////////////////////// // FILE: ev/win/misc_win.h -// SIZE: 1393 -// SHA-256: 9c0371bad1f19fbae9e3aa87f56381a57a80dcf783abe9555f7276703c27345e +// SIZE: 1419 +// SHA-256: ade18c2c9e8c05f2cee92967830bb3b89b57052cd1924d1353ab1de62f6bfe7f //////////////////////////////////////////////////////////////////////////////// // #line 1 "ev/win/misc_win.h" #ifndef __EV_MISC_WIN_INTERNAL_H__ #define __EV_MISC_WIN_INTERNAL_H__ -#define EV_FATAL_SYSCALL(errcode, syscall) \ +#define EV_FATAL_SYSCALL(errcode, syscall) \ ev__fatal_syscall(__FILE__, __LINE__, errcode, syscall) #ifdef __cplusplus @@ -2268,17 +2270,19 @@ extern "C" { * @brief Maps a character string to a UTF-16 (wide character) string. * @param[out] dst Pointer to store wide string. Use #ev_free() to release it. * @param[in] src Source string. - * @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error. + * @return The number of characters (not bytes) of \p dst, or + * #ev_errno_t if error. */ -EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR** dst, const char* src); +EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR **dst, const char *src); /** * @brief Maps a UTF-16 (wide character) string to a character string. * @param[out] dst Pointer to store wide string. Use #ev_free() to release it. * @param[in] src Source string. - * @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error. + * @return The number of characters (not bytes) of \p dst, or + * #ev_errno_t if error. */ -EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src); +EV_LOCAL ssize_t ev__wide_to_utf8(char **dst, const WCHAR *src); /** * @brief Show fatal information about syscall and abort(). @@ -2288,10 +2292,8 @@ EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src); * @param[in] errcode Error code from GetLastError(). * @param[in] syscall The name of syscall. */ -EV_LOCAL void ev__fatal_syscall(const char* file, int line, - DWORD errcode, const char* syscall); - -EV_LOCAL void ev__backend_shutdown(void); +EV_LOCAL void ev__fatal_syscall(const char *file, int line, DWORD errcode, + const char *syscall); #ifdef __cplusplus } @@ -3870,40 +3872,49 @@ EV_LOCAL void ev__backend_shutdown(void) // #line 41 "ev.c" //////////////////////////////////////////////////////////////////////////////// // FILE: ev/win/mutex_win.c -// SIZE: 596 -// SHA-256: 632743a2ae28e1891ab133d38739a792140699923aac149471a5c9d5af3f9a3c +// SIZE: 746 +// SHA-256: bc8cb146ca579cc8031f31da769da05062f2cdfec1c32a1af706c5b22710e99a //////////////////////////////////////////////////////////////////////////////// // #line 1 "ev/win/mutex_win.c" struct ev_mutex { - ev_os_mutex_t r; /**< Real mutex */ + ev_os_mutex_t r; /**< Real mutex */ }; -void ev_mutex_init(ev_mutex_t* handle, int recursive) +void ev_mutex_init(ev_mutex_t **handle, int recursive) { (void)recursive; - InitializeCriticalSection(&handle->u.r); + ev_mutex_t *new_mutex = ev_malloc(sizeof(ev_mutex_t)); + if (new_mutex == NULL) + { + abort(); + } + + InitializeCriticalSection(&new_mutex->r); + + *handle = new_mutex; } -void ev_mutex_exit(ev_mutex_t* handle) +void ev_mutex_exit(ev_mutex_t *handle) { - DeleteCriticalSection(&handle->u.r); + DeleteCriticalSection(&handle->r); + ev_free(handle); } -void ev_mutex_enter(ev_mutex_t* handle) +void ev_mutex_enter(ev_mutex_t *handle) { - EnterCriticalSection(&handle->u.r); + EnterCriticalSection(&handle->r); } -void ev_mutex_leave(ev_mutex_t* handle) +void ev_mutex_leave(ev_mutex_t *handle) { - LeaveCriticalSection(&handle->u.r); + LeaveCriticalSection(&handle->r); } -int ev_mutex_try_enter(ev_mutex_t* handle) +int ev_mutex_try_enter(ev_mutex_t *handle) { - if (TryEnterCriticalSection(&handle->u.r)) + if (TryEnterCriticalSection(&handle->r)) { return 0; } diff --git a/src/ev/misc_internal.h b/src/ev/misc_internal.h index f6a074a1..09f7bdbe 100644 --- a/src/ev/misc_internal.h +++ b/src/ev/misc_internal.h @@ -26,6 +26,8 @@ EV_LOCAL int ev__translate_posix_sys_error(int syserr); */ EV_LOCAL int ev__random(void* buf, size_t len); +EV_LOCAL void ev__backend_shutdown(void); + #ifdef __cplusplus } #endif diff --git a/src/ev/unix/misc_unix.h b/src/ev/unix/misc_unix.h deleted file mode 100644 index 16e944c6..00000000 --- a/src/ev/unix/misc_unix.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef EV_MISC_UNIX_INTERNAL_H -#define EV_MISC_UNIX_INTERNAL_H -#ifdef __cplusplus -extern "C" { -#endif - -EV_LOCAL void ev__backend_shutdown(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/ev/win/misc_win.h b/src/ev/win/misc_win.h index 929e6863..ba66b659 100644 --- a/src/ev/win/misc_win.h +++ b/src/ev/win/misc_win.h @@ -1,7 +1,7 @@ #ifndef __EV_MISC_WIN_INTERNAL_H__ #define __EV_MISC_WIN_INTERNAL_H__ -#define EV_FATAL_SYSCALL(errcode, syscall) \ +#define EV_FATAL_SYSCALL(errcode, syscall) \ ev__fatal_syscall(__FILE__, __LINE__, errcode, syscall) #ifdef __cplusplus @@ -12,17 +12,19 @@ extern "C" { * @brief Maps a character string to a UTF-16 (wide character) string. * @param[out] dst Pointer to store wide string. Use #ev_free() to release it. * @param[in] src Source string. - * @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error. + * @return The number of characters (not bytes) of \p dst, or + * #ev_errno_t if error. */ -EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR** dst, const char* src); +EV_LOCAL ssize_t ev__utf8_to_wide(WCHAR **dst, const char *src); /** * @brief Maps a UTF-16 (wide character) string to a character string. * @param[out] dst Pointer to store wide string. Use #ev_free() to release it. * @param[in] src Source string. - * @return The number of characters (not bytes) of \p dst, or #ev_errno_t if error. + * @return The number of characters (not bytes) of \p dst, or + * #ev_errno_t if error. */ -EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src); +EV_LOCAL ssize_t ev__wide_to_utf8(char **dst, const WCHAR *src); /** * @brief Show fatal information about syscall and abort(). @@ -32,10 +34,8 @@ EV_LOCAL ssize_t ev__wide_to_utf8(char** dst, const WCHAR* src); * @param[in] errcode Error code from GetLastError(). * @param[in] syscall The name of syscall. */ -EV_LOCAL void ev__fatal_syscall(const char* file, int line, - DWORD errcode, const char* syscall); - -EV_LOCAL void ev__backend_shutdown(void); +EV_LOCAL void ev__fatal_syscall(const char *file, int line, DWORD errcode, + const char *syscall); #ifdef __cplusplus } diff --git a/src/ev/win/mutex_win.c b/src/ev/win/mutex_win.c index fe907276..385648fe 100644 --- a/src/ev/win/mutex_win.c +++ b/src/ev/win/mutex_win.c @@ -1,33 +1,42 @@ struct ev_mutex { - ev_os_mutex_t r; /**< Real mutex */ + ev_os_mutex_t r; /**< Real mutex */ }; -void ev_mutex_init(ev_mutex_t* handle, int recursive) +void ev_mutex_init(ev_mutex_t **handle, int recursive) { (void)recursive; - InitializeCriticalSection(&handle->u.r); + ev_mutex_t *new_mutex = ev_malloc(sizeof(ev_mutex_t)); + if (new_mutex == NULL) + { + abort(); + } + + InitializeCriticalSection(&new_mutex->r); + + *handle = new_mutex; } -void ev_mutex_exit(ev_mutex_t* handle) +void ev_mutex_exit(ev_mutex_t *handle) { - DeleteCriticalSection(&handle->u.r); + DeleteCriticalSection(&handle->r); + ev_free(handle); } -void ev_mutex_enter(ev_mutex_t* handle) +void ev_mutex_enter(ev_mutex_t *handle) { - EnterCriticalSection(&handle->u.r); + EnterCriticalSection(&handle->r); } -void ev_mutex_leave(ev_mutex_t* handle) +void ev_mutex_leave(ev_mutex_t *handle) { - LeaveCriticalSection(&handle->u.r); + LeaveCriticalSection(&handle->r); } -int ev_mutex_try_enter(ev_mutex_t* handle) +int ev_mutex_try_enter(ev_mutex_t *handle) { - if (TryEnterCriticalSection(&handle->u.r)) + if (TryEnterCriticalSection(&handle->r)) { return 0; }