Mostly for vendoring of future fluidsynth versions.
-- v2: libs/fluidsynth: Use InterlockedExchangeAdd() in g_atomic_int_add(). libs/fluidsynth: Return thread return value from g_thread_join(). libs/fluidsynth: Fix definition of g_atomic_int_dec_and_test(). libs/fluidsynth: Fix argument flag handling in g_file_test(). libs/fluidsynth: Round up sleep duration in g_usleep(). libs/fluidsynth: Use full memory barrier in g_atomic_int_get(). libs/fluidsynth: Fix double close of thread handle in g_thread_unref(). libs/fluidsynth: Fix g_mutex_init() and g_cond_init().
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libs/fluidsynth/glib.h b/libs/fluidsynth/glib.h index a2cfd2c743d..04b9fb82d54 100644 --- a/libs/fluidsynth/glib.h +++ b/libs/fluidsynth/glib.h @@ -81,7 +81,7 @@ extern int g_file_test( const char *path, int test ); static inline void g_free( void *ptr ) { free( ptr ); }
typedef SRWLOCK GMutex; -static inline void g_mutex_init( GMutex *mutex ) {} +static inline void g_mutex_init( GMutex *mutex ) { InitializeSRWLock( mutex ); } static inline void g_mutex_clear( GMutex *mutex ) {} static inline void g_mutex_lock( GMutex *mutex ) { AcquireSRWLockExclusive( mutex ); } static inline void g_mutex_unlock( GMutex *mutex ) { ReleaseSRWLockExclusive( mutex ); } @@ -93,7 +93,7 @@ static inline void g_rec_mutex_lock( GRecMutex *mutex ) { EnterCriticalSection( static inline void g_rec_mutex_unlock( GRecMutex *mutex ) { LeaveCriticalSection( mutex ); }
typedef CONDITION_VARIABLE GCond; -static inline void g_cond_init( GCond *cond ) {} +static inline void g_cond_init( GCond *cond ) { InitializeConditionVariable( cond ); } static inline void g_cond_clear( GCond *cond ) {} static inline void g_cond_signal( GCond *cond ) { WakeConditionVariable( cond ); } static inline void g_cond_broadcast( GCond *cond ) { WakeAllConditionVariable( cond ); }
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/libs/fluidsynth/glib.c b/libs/fluidsynth/glib.c index 4a6a5300a2c..e7add4652b2 100644 --- a/libs/fluidsynth/glib.c +++ b/libs/fluidsynth/glib.c @@ -57,7 +57,7 @@ static DWORD CALLBACK g_thread_wrapper( void *args ) { GThread *thread = args; gpointer ret = thread->func( thread->data ); - if (!InterlockedDecrement( &thread->ref )) free( thread ); + g_thread_unref( thread ); return (UINT_PTR)ret; }
@@ -81,8 +81,11 @@ GThread *g_thread_try_new( const char *name, GThreadFunc func, gpointer data, GE
void g_thread_unref( GThread *thread ) { - CloseHandle( thread->handle ); - if (!InterlockedDecrement( &thread->ref )) free( thread ); + if (!InterlockedDecrement( &thread->ref )) + { + CloseHandle( thread->handle ); + free( thread ); + } }
void g_thread_join( GThread *thread )
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/fluidsynth/glib.h b/libs/fluidsynth/glib.h index 04b9fb82d54..aeaaf097622 100644 --- a/libs/fluidsynth/glib.h +++ b/libs/fluidsynth/glib.h @@ -101,7 +101,7 @@ static inline void g_cond_wait( GCond *cond, GMutex *mutex ) { SleepConditionVar
static inline void g_atomic_int_inc( int *ptr ) { InterlockedIncrement( (LONG *)ptr ); } static inline int g_atomic_int_add( int *ptr, int val ) { return InterlockedAdd( (LONG *)ptr, val ) - val; } -static inline int g_atomic_int_get( int *ptr ) { return ReadAcquire( (LONG *)ptr ); } +static inline int g_atomic_int_get( int *ptr ) { int value = ReadNoFence( (LONG *)ptr ); MemoryBarrier(); return value; } static inline void g_atomic_int_set( int *ptr, int val ) { InterlockedExchange( (LONG *)ptr, val ); } static inline int g_atomic_int_dec_and_test( int *ptr, int val ) { return !InterlockedAdd( (LONG *)ptr, -val ); } static inline int g_atomic_int_compare_and_exchange( int *ptr, int cmp, int val ) { return InterlockedCompareExchange( (LONG *)ptr, val, cmp ) == cmp; }
From: Jinoh Kang jinoh.kang.kr@gmail.com
Returning early is never correct; returning late is.
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/fluidsynth/glib.c b/libs/fluidsynth/glib.c index e7add4652b2..3953392b86f 100644 --- a/libs/fluidsynth/glib.c +++ b/libs/fluidsynth/glib.c @@ -50,7 +50,7 @@ double g_get_monotonic_time(void)
void g_usleep( unsigned int micros ) { - Sleep( micros / 1000 ); + Sleep( (micros + 999) / 1000 ); }
static DWORD CALLBACK g_thread_wrapper( void *args )
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/libs/fluidsynth/glib.c b/libs/fluidsynth/glib.c index 3953392b86f..8266ac4bda1 100644 --- a/libs/fluidsynth/glib.c +++ b/libs/fluidsynth/glib.c @@ -102,7 +102,10 @@ void g_clear_error( GError **error ) int g_file_test( const char *path, int test ) { DWORD attrs = GetFileAttributesA( path ); - if (test == G_FILE_TEST_EXISTS) return attrs != INVALID_FILE_ATTRIBUTES; - if (test == G_FILE_TEST_IS_REGULAR) return attrs == FILE_ATTRIBUTE_NORMAL; + if (attrs != INVALID_FILE_ATTRIBUTES) + { + if (test & G_FILE_TEST_EXISTS) return 1; + if ((test & G_FILE_TEST_IS_REGULAR) && !(attrs & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE))) return 1; + } return 0; }
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/fluidsynth/glib.h b/libs/fluidsynth/glib.h index aeaaf097622..3ff3a962fab 100644 --- a/libs/fluidsynth/glib.h +++ b/libs/fluidsynth/glib.h @@ -103,5 +103,5 @@ static inline void g_atomic_int_inc( int *ptr ) { InterlockedIncrement( (LONG *) static inline int g_atomic_int_add( int *ptr, int val ) { return InterlockedAdd( (LONG *)ptr, val ) - val; } static inline int g_atomic_int_get( int *ptr ) { int value = ReadNoFence( (LONG *)ptr ); MemoryBarrier(); return value; } static inline void g_atomic_int_set( int *ptr, int val ) { InterlockedExchange( (LONG *)ptr, val ); } -static inline int g_atomic_int_dec_and_test( int *ptr, int val ) { return !InterlockedAdd( (LONG *)ptr, -val ); } +static inline int g_atomic_int_dec_and_test( int *ptr ) { return !InterlockedAdd( (LONG *)ptr, -1 ); } static inline int g_atomic_int_compare_and_exchange( int *ptr, int cmp, int val ) { return InterlockedCompareExchange( (LONG *)ptr, val, cmp ) == cmp; }
From: Jinoh Kang jinoh.kang.kr@gmail.com
Fixes: f768d6b31bebc35fbaf751d0cd57c8bd302a8d60 --- libs/fluidsynth/glib.c | 10 +++++++--- libs/fluidsynth/glib.h | 3 ++- 2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/libs/fluidsynth/glib.c b/libs/fluidsynth/glib.c index 8266ac4bda1..5756583111a 100644 --- a/libs/fluidsynth/glib.c +++ b/libs/fluidsynth/glib.c @@ -56,9 +56,9 @@ void g_usleep( unsigned int micros ) static DWORD CALLBACK g_thread_wrapper( void *args ) { GThread *thread = args; - gpointer ret = thread->func( thread->data ); + thread->result = thread->func( thread->data ); g_thread_unref( thread ); - return (UINT_PTR)ret; + return 0; }
GThread *g_thread_try_new( const char *name, GThreadFunc func, gpointer data, GError **err ) @@ -88,10 +88,14 @@ void g_thread_unref( GThread *thread ) } }
-void g_thread_join( GThread *thread ) +gpointer g_thread_join( GThread *thread ) { + gpointer result; + WaitForSingleObject( thread->handle, INFINITE ); + result = thread->result; g_thread_unref( thread ); + return result; }
void g_clear_error( GError **error ) diff --git a/libs/fluidsynth/glib.h b/libs/fluidsynth/glib.h index 3ff3a962fab..950ce684c19 100644 --- a/libs/fluidsynth/glib.h +++ b/libs/fluidsynth/glib.h @@ -59,6 +59,7 @@ typedef struct HANDLE handle; GThreadFunc func; gpointer data; + gpointer result; } GThread;
extern int g_vsnprintf( char *buffer, size_t size, const char *format, va_list args ) __WINE_CRT_PRINTF_ATTR(3, 0); @@ -69,7 +70,7 @@ extern void g_usleep( unsigned int micros );
extern GThread *g_thread_try_new( const char *name, GThreadFunc func, gpointer data, GError **err ); extern void g_thread_unref( GThread *thread ); -extern void g_thread_join( GThread *thread ); +extern gpointer g_thread_join( GThread *thread ); extern void g_clear_error( GError **error );
#define G_FILE_TEST_EXISTS 1
From: Jinoh Kang jinoh.kang.kr@gmail.com
--- libs/fluidsynth/glib.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libs/fluidsynth/glib.h b/libs/fluidsynth/glib.h index 950ce684c19..466a2644d98 100644 --- a/libs/fluidsynth/glib.h +++ b/libs/fluidsynth/glib.h @@ -101,7 +101,7 @@ static inline void g_cond_broadcast( GCond *cond ) { WakeAllConditionVariable( c static inline void g_cond_wait( GCond *cond, GMutex *mutex ) { SleepConditionVariableSRW( cond, mutex, INFINITE, 0 ); }
static inline void g_atomic_int_inc( int *ptr ) { InterlockedIncrement( (LONG *)ptr ); } -static inline int g_atomic_int_add( int *ptr, int val ) { return InterlockedAdd( (LONG *)ptr, val ) - val; } +static inline int g_atomic_int_add( int *ptr, int val ) { return InterlockedExchangeAdd( (LONG *)ptr, val ); } static inline int g_atomic_int_get( int *ptr ) { int value = ReadNoFence( (LONG *)ptr ); MemoryBarrier(); return value; } static inline void g_atomic_int_set( int *ptr, int val ) { InterlockedExchange( (LONG *)ptr, val ); } static inline int g_atomic_int_dec_and_test( int *ptr ) { return !InterlockedAdd( (LONG *)ptr, -1 ); }
v2: Rebase after !9048