4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS system libraries
6 * FILE: subsys/psx/lib/psxdll/pthread/join.c
7 * PURPOSE: Wait for thread termination
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
13 #include <ddk/ntddk.h>
14 #include <ntdll/ldr.h>
16 #include <sys/types.h>
18 #include <psx/debug.h>
19 #include <psx/errno.h>
21 int pthread_join(pthread_t thread
, void **value_ptr
)
25 OBJECT_ATTRIBUTES oaThreadAttrs
;
27 THREAD_BASIC_INFORMATION tbiThreadInfo
;
29 /* "[EDEADLK] A deadlock was detected or the value of thread specifies
30 the calling thread" */
31 if(thread
== pthread_self())
35 ciId
.UniqueProcess
= (HANDLE
)-1;
36 ciId
.UniqueThread
= (HANDLE
)thread
;
38 /* initialize object attributes */
39 oaThreadAttrs
.Length
= sizeof(OBJECT_ATTRIBUTES
);
40 oaThreadAttrs
.RootDirectory
= NULL
;
41 oaThreadAttrs
.ObjectName
= NULL
;
42 oaThreadAttrs
.Attributes
= 0;
43 oaThreadAttrs
.SecurityDescriptor
= NULL
;
44 oaThreadAttrs
.SecurityQualityOfService
= NULL
;
47 nErrCode
= NtOpenThread
50 SYNCHRONIZE
| THREAD_QUERY_INFORMATION
,
56 if(!NT_SUCCESS(nErrCode
))
58 return (__status_to_errno(nErrCode
));
61 /* wait for thread termination */
62 nErrCode
= NtWaitForSingleObject
70 if(!NT_SUCCESS(nErrCode
))
73 return (__status_to_errno(nErrCode
));
76 /* get thread basic information (includes return code) */
77 nErrCode
= NtQueryInformationThread
80 ThreadBasicInformation
,
82 sizeof(THREAD_BASIC_INFORMATION
),
91 *value_ptr
= (void *)tbiThreadInfo
.ExitStatus
;