added tests for StretchBlt, PatBlt and BitBlt by Damon Chandler
[reactos.git] / posix / lib / psxdll / pthread / exit.c
1 /* $Id: exit.c,v 1.2 2002/02/20 09:17:57 hyperion Exp $
2 */
3 /*
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/pthread/exit.c
7 * PURPOSE: Thread termination
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
9 * UPDATE HISTORY:
10 * 19/12/2001: Created
11 */
12
13 #include <ddk/ntddk.h>
14 #include <ntdll/ldr.h>
15 #include <errno.h>
16 #include <stdlib.h>
17 #include <pthread.h>
18 #include <psx/debug.h>
19
20 void pthread_exit(void *value_ptr)
21 {
22 NTSTATUS nErrCode;
23 BOOLEAN fLastThread;
24
25 /* terminate process if this is the last thread of the current process */
26 nErrCode = NtQueryInformationThread
27 (
28 NtCurrentThread(),
29 ThreadAmILastThread,
30 &fLastThread,
31 sizeof(BOOLEAN),
32 NULL
33 );
34
35 if(NT_SUCCESS(nErrCode))
36 {
37 if(fLastThread)
38 {
39 INFO("this thread is the last in the current process - about to call exit(0)");
40 exit(0);
41 }
42 }
43 else
44 {
45 WARN
46 (
47 "NtQueryInformationThread(ThreadAmILastThread) failed with status %#x. \
48 Can't determine if the current thread is the last in the process. The process \
49 could hang",
50 nErrCode
51 );
52
53 }
54
55 TODO("Notify psxss of thread termination");
56
57 LdrShutdownThread(); /* detach DLLs */
58
59 /* kill this thread */
60
61 WARNIF(
62 sizeof(ULONG) < sizeof(typeof(value_ptr)),
63 "\
64 the value returned from the current thread will be truncated (pointers shorter \
65 than long integers on this architecture?) - expect trouble"
66 );
67
68 INFO("bye bye. Current thread about to die");
69
70 NtTerminateThread(NtCurrentThread(), (ULONG)value_ptr);
71
72 /* "The pthread_exit() function cannot return to its caller." */
73 NtDelayExecution(FALSE, NULL);
74
75 }
76
77 /* EOF */
78