summaryrefslogtreecommitdiff
path: root/sync.c
diff options
context:
space:
mode:
authorbje <bje>1998-07-10 14:25:41 +0000
committerbje <bje>1998-07-10 14:25:41 +0000
commit2dc64542b634a71f1cb40b381feeacb75cc192dd (patch)
tree16efb6912b9cf4161255424b7ae7d67981c6a53c /sync.c
parent0851aa8a26f428eec19b4efa42b7249fdf599d37 (diff)
1998-07-11 Ben Elliston <bje@cygnus.com>
* sync.c (pthread_join): Implement.
Diffstat (limited to 'sync.c')
-rw-r--r--sync.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/sync.c b/sync.c
new file mode 100644
index 0000000..5321da0
--- /dev/null
+++ b/sync.c
@@ -0,0 +1,48 @@
+/*
+ * sync.c
+ *
+ * Description:
+ * This translation unit implements functions related to thread
+ * synchronisation.
+ */
+
+#include "pthread.h"
+
+int
+pthread_join(pthread_t thread, void ** valueptr)
+{
+ LPDWORD exitcode;
+ pthread_t us = pthread_self();
+
+ /* First check if we are trying to join to ourselves. */
+ if (pthread_equal(thread, us) == 0)
+ {
+ return EDEADLK;
+ }
+
+ /* Wait on the kernel thread object. */
+ switch (WaitForSingleObject(thread, INFINITE))
+ {
+ case WAIT_FAILED:
+ /* The thread does not exist. */
+ return ESRCH;
+ case WAIT_OBJECT_0:
+ /* The thread has finished. */
+ break;
+ default:
+ /* This should never happen. */
+ break;
+ }
+
+ /* We don't get the exit code as a result of the last operation,
+ so we do it now. */
+
+ if (GetExitCodeThread(thread, exitcode) != TRUE)
+ {
+ return ESRCH;
+ }
+
+ /* FIXME: this is wrong. */
+ return &exitcode;
+}
+