[vlc-devel] [PATCH 2/3] thread: use the generic one-time initializer

RĂ©mi Denis-Courmont remi at remlab.net
Thu Apr 2 16:28:37 CEST 2020


---
 include/vlc_threads.h | 27 ---------------------------
 src/android/thread.c  |  6 ------
 src/darwin/thread.c   |  6 ------
 src/misc/threads.c    |  2 --
 src/os2/thread.c      | 28 ----------------------------
 src/posix/thread.c    |  6 ------
 src/win32/thread.c    | 16 ----------------
 7 files changed, 91 deletions(-)

diff --git a/include/vlc_threads.h b/include/vlc_threads.h
index b04a3305c1..87d0691402 100644
--- a/include/vlc_threads.h
+++ b/include/vlc_threads.h
@@ -61,8 +61,6 @@ typedef struct vlc_thread *vlc_thread_t;
 
 # define LIBVLC_NEED_SLEEP
 #define LIBVLC_NEED_RWLOCK
-typedef INIT_ONCE vlc_once_t;
-#define VLC_STATIC_ONCE INIT_ONCE_STATIC_INIT
 typedef struct vlc_threadvar *vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
@@ -92,12 +90,6 @@ typedef struct vlc_thread *vlc_thread_t;
 #define VLC_THREAD_CANCELED NULL
 
 #define LIBVLC_NEED_RWLOCK
-typedef struct
-{
-    unsigned done;
-    vlc_mutex_t mutex;
-} vlc_once_t;
-#define VLC_STATIC_ONCE { 0, VLC_STATIC_MUTEX }
 typedef struct vlc_threadvar *vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
@@ -142,8 +134,6 @@ static inline int vlc_poll (struct pollfd *fds, unsigned nfds, int timeout)
 
 typedef struct vlc_thread *vlc_thread_t;
 #define VLC_THREAD_CANCELED NULL
-typedef pthread_once_t  vlc_once_t;
-#define VLC_STATIC_ONCE   PTHREAD_ONCE_INIT
 typedef pthread_key_t   vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
@@ -187,8 +177,6 @@ typedef pthread_t       vlc_thread_t;
 #define VLC_THREAD_CANCELED PTHREAD_CANCELED
 typedef pthread_rwlock_t vlc_rwlock_t;
 #define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
-typedef pthread_once_t  vlc_once_t;
-#define VLC_STATIC_ONCE   PTHREAD_ONCE_INIT
 typedef pthread_key_t   vlc_threadvar_t;
 typedef struct vlc_timer *vlc_timer_t;
 
@@ -242,19 +230,6 @@ typedef pthread_rwlock_t vlc_rwlock_t;
  */
 #define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER
 
-/**
- * One-time initialization.
- *
- * A one-time initialization object must always be initialized assigned to
- * \ref VLC_STATIC_ONCE before use.
- */
-typedef pthread_once_t  vlc_once_t;
-
-/**
- * Static initializer for one-time initialization.
- */
-#define VLC_STATIC_ONCE   PTHREAD_ONCE_INIT
-
 /**
  * Thread-local key handle.
  *
@@ -634,7 +609,6 @@ VLC_API void vlc_rwlock_unlock(vlc_rwlock_t *);
 /** @} */
 
 #ifndef __cplusplus
-#if 0
 /**
  * One-time initialization.
  *
@@ -650,7 +624,6 @@ typedef struct
  * Static initializer for one-time initialization.
  */
 #define VLC_STATIC_ONCE { ATOMIC_VAR_INIT(0) }
-#endif
 
 /**
  * Executes a function one time.
diff --git a/src/android/thread.c b/src/android/thread.c
index f831f5b5c1..79132be2e4 100644
--- a/src/android/thread.c
+++ b/src/android/thread.c
@@ -67,12 +67,6 @@ vlc_thread_fatal_print (const char *action, int error,
 # define VLC_THREAD_ASSERT( action ) ((void)val)
 #endif
 
-void vlc_once(vlc_once_t *once, void (*cb)(void))
-{
-    int val = pthread_once(once, cb);
-    VLC_THREAD_ASSERT("initializing once");
-}
-
 struct vlc_thread
 {
     pthread_t      thread;
diff --git a/src/darwin/thread.c b/src/darwin/thread.c
index 13ccbeed2d..d808543a08 100644
--- a/src/darwin/thread.c
+++ b/src/darwin/thread.c
@@ -145,12 +145,6 @@ void vlc_rwlock_unlock (vlc_rwlock_t *lock)
     VLC_THREAD_ASSERT ("releasing R/W lock");
 }
 
-void vlc_once(vlc_once_t *once, void (*cb)(void))
-{
-    int val = pthread_once(once, cb);
-    VLC_THREAD_ASSERT("initializing once");
-}
-
 int vlc_threadvar_create (vlc_threadvar_t *key, void (*destr) (void *))
 {
     return pthread_key_create (key, destr);
diff --git a/src/misc/threads.c b/src/misc/threads.c
index 11c46fa730..945b9568f6 100644
--- a/src/misc/threads.c
+++ b/src/misc/threads.c
@@ -534,7 +534,6 @@ int vlc_sem_timedwait(vlc_sem_t *sem, vlc_tick_t deadline)
     return 0;
 }
 
-#if 0
 enum { VLC_ONCE_UNDONE, VLC_ONCE_DOING, VLC_ONCE_CONTEND, VLC_ONCE_DONE };
 
 void vlc_once(vlc_once_t *restrict once, void (*cb)(void))
@@ -572,4 +571,3 @@ void vlc_once(vlc_once_t *restrict once, void (*cb)(void))
         value = atomic_load_explicit(&once->value, memory_order_acquire);
     }
 }
-#endif
diff --git a/src/os2/thread.c b/src/os2/thread.c
index 531bdd101b..a5fa6c8bda 100644
--- a/src/os2/thread.c
+++ b/src/os2/thread.c
@@ -168,34 +168,6 @@ unsigned long _System _DLL_InitTerm(unsigned long hmod, unsigned long flag)
     return 0;   /* Failed */
 }
 
-void vlc_once(vlc_once_t *once, void (*cb)(void))
-{
-    unsigned done;
-
-    /* load once->done */
-    __atomic_xchg( &done, once->done );
-
-    /* not initialized ? */
-    if( done == 0 )
-    {
-        vlc_mutex_lock( &once->mutex );
-
-        /* load once->done */
-        __atomic_xchg( &done, once->done );
-
-        /* still not initialized ? */
-        if( done == 0 )
-        {
-            cb();
-
-            /* set once->done to 1 */
-            __atomic_xchg( &once->done, 1 );
-        }
-
-        vlc_mutex_unlock( &once->mutex );
-    }
-}
-
 /*** Thread-specific variables (TLS) ***/
 struct vlc_threadvar
 {
diff --git a/src/posix/thread.c b/src/posix/thread.c
index b755f97282..d8edc13d53 100644
--- a/src/posix/thread.c
+++ b/src/posix/thread.c
@@ -133,12 +133,6 @@ void vlc_rwlock_unlock (vlc_rwlock_t *lock)
     VLC_THREAD_ASSERT ("releasing R/W lock");
 }
 
-void vlc_once(vlc_once_t *once, void (*cb)(void))
-{
-    int val = pthread_once(once, cb);
-    VLC_THREAD_ASSERT("initializing once");
-}
-
 int vlc_threadvar_create (vlc_threadvar_t *key, void (*destr) (void *))
 {
     return pthread_key_create (key, destr);
diff --git a/src/win32/thread.c b/src/win32/thread.c
index 18fa754ea8..61cd62ed35 100644
--- a/src/win32/thread.c
+++ b/src/win32/thread.c
@@ -70,22 +70,6 @@ struct vlc_thread
     } wait;
 };
 
-/*** One-time initialization ***/
-static BOOL CALLBACK vlc_once_callback(INIT_ONCE *once, void *parm, void **ctx)
-{
-    void (*cb)(void) = parm;
-
-    cb();
-    (void) once;
-    (void) ctx;
-    return TRUE;
-}
-
-void vlc_once(vlc_once_t *once, void (*cb)(void))
-{
-    InitOnceExecuteOnce(once, vlc_once_callback, cb, NULL);
-}
-
 /*** Thread-specific variables (TLS) ***/
 struct vlc_threadvar
 {
-- 
2.26.0



More information about the vlc-devel mailing list