summaryrefslogtreecommitdiff
path: root/tests/threads/basic.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2016-11-18 07:19:22 -0500
committerEdward Thomson <ethomson@github.com>2016-11-18 07:34:09 -0500
commit82f15896deb06d396d76d706f6c0146197d14b2c (patch)
tree8e0bc15feb02cb9a197ddc8db62d174515d94bf7 /tests/threads/basic.c
parenta6763ff93aed9a1486c4f84d77151ff57dd4795e (diff)
downloadlibgit2-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 'tests/threads/basic.c')
-rw-r--r--tests/threads/basic.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/threads/basic.c b/tests/threads/basic.c
index 9c342bc42..685452d44 100644
--- a/tests/threads/basic.c
+++ b/tests/threads/basic.c
@@ -48,3 +48,30 @@ void test_threads_basic__set_error(void)
{
run_in_parallel(1, 4, set_error, NULL, NULL);
}
+
+static void *return_normally(void *param)
+{
+ return param;
+}
+
+static void *exit_abruptly(void *param)
+{
+ git_thread_exit(param);
+ return NULL;
+}
+
+void test_threads_basic__exit(void)
+{
+ git_thread thread;
+ void *result;
+
+ /* Ensure that the return value of the threadproc is returned. */
+ cl_git_pass(git_thread_create(&thread, return_normally, (void *)424242));
+ cl_git_pass(git_thread_join(&thread, &result));
+ cl_assert_equal_sz(424242, (size_t)result);
+
+ /* Ensure that the return value of `git_thread_exit` is returned. */
+ cl_git_pass(git_thread_create(&thread, return_normally, (void *)232323));
+ cl_git_pass(git_thread_join(&thread, &result));
+ cl_assert_equal_sz(232323, (size_t)result);
+} \ No newline at end of file