diff options
| author | Edward Thomson <ethomson@github.com> | 2016-11-18 07:19:22 -0500 |
|---|---|---|
| committer | Edward Thomson <ethomson@github.com> | 2016-11-18 07:34:09 -0500 |
| commit | 82f15896deb06d396d76d706f6c0146197d14b2c (patch) | |
| tree | 8e0bc15feb02cb9a197ddc8db62d174515d94bf7 /src/win32/thread.c | |
| parent | a6763ff93aed9a1486c4f84d77151ff57dd4795e (diff) | |
| download | libgit2-82f15896deb06d396d76d706f6c0146197d14b2c.tar.gz | |
threads: introduce `git_thread_exit`
Introduce `git_thread_exit`, which will allow threads to terminate at an
arbitrary time, returning a `void *`. On Windows, this means that we
need to store the current `git_thread` in TLS, so that we can set its
`return` value when terminating.
We cannot simply use `ExitThread`, since Win32 returns `DWORD`s from
threads; we return `void *`.
Diffstat (limited to 'src/win32/thread.c')
| -rw-r--r-- | src/win32/thread.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/win32/thread.c b/src/win32/thread.c index 80d56ce5d..87318c9d3 100644 --- a/src/win32/thread.c +++ b/src/win32/thread.c @@ -26,6 +26,9 @@ static DWORD WINAPI git_win32__threadproc(LPVOID lpParameter) { git_thread *thread = lpParameter; + /* Set the current thread for `git_thread_exit` */ + GIT_GLOBAL->current_thread = thread; + thread->result = thread->proc(thread->param); git__free_tls_data(); @@ -95,6 +98,21 @@ int git_thread_join( return 0; } +void git_thread_exit(void *value) +{ + assert(GIT_GLOBAL->current_thread); + GIT_GLOBAL->current_thread->result = value; + + git__free_tls_data(); + + ExitThread(CLEAN_THREAD_EXIT); +} + +size_t git_thread_currentid(void) +{ + return GetCurrentThreadId(); +} + int git_mutex_init(git_mutex *GIT_RESTRICT mutex) { InitializeCriticalSection(mutex); |
