-
-
Save AmesianX/25ff985af232f9000a6462f8a574ca52 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <windows.h> | |
| #include <stdlib.h> | |
| struct m_thread_info { | |
| DWORD tid; | |
| }; | |
| typedef struct m_thread_info *pthread_t; | |
| static DWORD mpv_tls_index = FLS_OUT_OF_INDEXES; | |
| BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID reserved) | |
| { | |
| switch (reason) { | |
| case DLL_PROCESS_ATTACH: | |
| mpv_tls_index = FlsAlloc(NULL); | |
| if (mpv_tls_index == FLS_OUT_OF_INDEXES) | |
| return FALSE; | |
| break; | |
| case DLL_PROCESS_DETACH: | |
| if (mpv_tls_index != FLS_OUT_OF_INDEXES) | |
| FlsFree(mpv_tls_index); | |
| break; | |
| case DLL_THREAD_ATTACH: { | |
| struct m_thread_info *td = malloc(sizeof td); | |
| *td = (struct m_thread_info) { GetCurrentThreadId() }; | |
| FlsSetValue(mpv_tls_index, td); | |
| break; | |
| } | |
| case DLL_THREAD_DETACH: { | |
| struct m_thread_info *td = FlsGetValue(mpv_tls_index); | |
| free(td); | |
| break; | |
| } | |
| } | |
| return TRUE; | |
| } | |
| pthread_t pthread_self(void) | |
| { | |
| return FlsGetValue(mpv_tls_index); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment