[vlc-commits] [Git][videolan/vlc][master] 4 commits: os2: remove unused super_variable

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Oct 14 06:21:11 UTC 2021



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
3a51d0d1 by Steve Lhomme at 2021-10-14T06:08:04+00:00
os2: remove unused super_variable

orphaned since 72acfccd5311e8f051843bbd947fd321c7916766

- - - - -
df04c16c by Steve Lhomme at 2021-10-14T06:08:04+00:00
win32: thread: use a global thread local storage for the thread cancellation data

This is supported even in MSVC with __declspec(thread).

- - - - -
7d608fc1 by Steve Lhomme at 2021-10-14T06:08:04+00:00
os2: thread: use a global thread local storage for the thread cancellation data

This is already used in many places in the core so it has to be supported.

- - - - -
231338e4 by Steve Lhomme at 2021-10-14T06:08:04+00:00
os2: thread: initialize the static super_mutex from the static initializer

This reduces _DLL_InitTerm() to the bare minimum.

- - - - -


2 changed files:

- src/os2/thread.c
- src/win32/thread.c


Changes:

=====================================
src/os2/thread.c
=====================================
@@ -57,11 +57,10 @@
 #include <vlc_atomic.h>
 
 /* Static mutex and condition variable */
-static vlc_mutex_t super_mutex;
-static vlc_cond_t  super_variable;
+static vlc_mutex_t super_mutex = VLC_STATIC_MUTEX;
 
 /* Threads */
-static vlc_threadvar_t thread_key;
+static thread_local struct vlc_thread *current_thread_ctx = NULL;
 
 struct vlc_thread
 {
@@ -88,7 +87,7 @@ static ULONG vlc_DosWaitEventSemEx( HEV hev, ULONG ulTimeout )
     int       n;
     ULONG     rc;
 
-    struct vlc_thread *th = vlc_threadvar_get(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if( th == NULL || !th->killable )
     {
         /* Main thread - cannot be cancelled anyway
@@ -431,7 +430,7 @@ static void vlc_entry( void *p )
 {
     struct vlc_thread *th = p;
 
-    vlc_threadvar_set (thread_key, th);
+    current_thread_ctx = th;
     th->killable = true;
     th->data = th->entry (th->data);
     DosPostEventSem( th->done_event );
@@ -546,7 +545,7 @@ int vlc_savecancel (void)
 {
     int state;
 
-    struct vlc_thread *th = vlc_threadvar_get(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if (th == NULL)
         return false; /* Main thread - cannot be cancelled anyway */
 
@@ -557,7 +556,7 @@ int vlc_savecancel (void)
 
 void vlc_restorecancel (int state)
 {
-    struct vlc_thread *th = vlc_threadvar_get(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     assert (state == false || state == true);
 
     if (th == NULL)
@@ -569,7 +568,7 @@ void vlc_restorecancel (int state)
 
 void vlc_testcancel (void)
 {
-    struct vlc_thread *th = vlc_threadvar_get(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if (th == NULL)
         return; /* Main thread - cannot be cancelled anyway */
 
@@ -600,7 +599,7 @@ void vlc_control_cancel (vlc_cleanup_t *cleaner)
     /* NOTE: This function only modifies thread-specific data, so there is no
      * need to lock anything. */
 
-    struct vlc_thread *th = vlc_threadvar_get(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if (th == NULL)
         return; /* Main thread - cannot be cancelled anyway */
 
@@ -620,7 +619,7 @@ void vlc_control_cancel (vlc_cleanup_t *cleaner)
 static int vlc_select( int nfds, fd_set *rdset, fd_set *wrset, fd_set *exset,
                        struct timeval *timeout )
 {
-    struct vlc_thread *th = vlc_threadvar_get(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
 
     int rc;
 
@@ -901,15 +900,9 @@ unsigned long _System _DLL_InitTerm(unsigned long hmod, unsigned long flag)
 
             wait_bucket_init();
 
-            vlc_mutex_init (&super_mutex);
-            vlc_cond_init (&super_variable);
-            vlc_threadvar_create (&thread_key, NULL);
-
             return 1;
 
         case 1 :    /* Termination */
-            vlc_threadvar_delete (&thread_key);
-
             wait_bucket_destroy();
 
             _CRT_term();


=====================================
src/win32/thread.c
=====================================
@@ -55,7 +55,7 @@ static SRWLOCK super_lock = SRWLOCK_INIT;
 #endif
 
 /*** Threads ***/
-static DWORD thread_key;
+static thread_local struct vlc_thread *current_thread_ctx = NULL;
 
 struct vlc_thread
 {
@@ -341,10 +341,10 @@ __stdcall vlc_entry (void *p)
 {
     struct vlc_thread *th = p;
 
-    TlsSetValue(thread_key, th);
+    current_thread_ctx = th;
     th->killable = true;
     th->data = th->entry (th->data);
-    TlsSetValue(thread_key, NULL);
+    current_thread_ctx = NULL;
 
     return 0;
 }
@@ -440,7 +440,7 @@ void vlc_cancel (vlc_thread_t th)
 
 int vlc_savecancel (void)
 {
-    struct vlc_thread *th = TlsGetValue(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if (th == NULL)
         return false; /* Main thread - cannot be cancelled anyway */
 
@@ -451,7 +451,7 @@ int vlc_savecancel (void)
 
 void vlc_restorecancel (int state)
 {
-    struct vlc_thread *th = TlsGetValue(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     assert (state == false || state == true);
 
     if (th == NULL)
@@ -478,7 +478,7 @@ noreturn static void vlc_docancel(struct vlc_thread *th)
 
 void vlc_testcancel (void)
 {
-    struct vlc_thread *th = TlsGetValue(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if (th == NULL)
         return; /* Main thread - cannot be cancelled anyway */
     if (!th->killable)
@@ -494,7 +494,7 @@ void vlc_control_cancel (vlc_cleanup_t *cleaner)
     /* NOTE: This function only modifies thread-specific data, so there is no
      * need to lock anything. */
 
-    struct vlc_thread *th = TlsGetValue(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
     if (th == NULL)
         return; /* Main thread - cannot be cancelled anyway */
 
@@ -606,7 +606,7 @@ void (vlc_tick_wait)(vlc_tick_t deadline)
 {
     vlc_tick_t delay;
 #if (_WIN32_WINNT >= _WIN32_WINNT_WIN8)
-    struct vlc_thread *th = TlsGetValue(thread_key);
+    struct vlc_thread *th = current_thread_ctx;
 
     if (th != NULL && th->killable)
     {
@@ -783,16 +783,9 @@ BOOL WINAPI DllMain (HANDLE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
                 vlc_wait_addr_init();
             }
 #endif
-            thread_key = TlsAlloc();
-            if (unlikely(thread_key == TLS_OUT_OF_INDEXES))
-                return FALSE;
             break;
         }
 
-        case DLL_PROCESS_DETACH:
-            TlsFree(thread_key);
-            break;
-
         case DLL_THREAD_DETACH:
             vlc_threadvars_cleanup();
             break;



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ef33903e55c2814c2b48083a5d748df4f7cb1a18...231338e4a98f164c12e9665bd60a50c37de562a1

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ef33903e55c2814c2b48083a5d748df4f7cb1a18...231338e4a98f164c12e9665bd60a50c37de562a1
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list