FreeBASIC  0.91.0
thread_core.c
Go to the documentation of this file.
1 /* thread creation and destruction functions */
2 
3 #include "../fb.h"
4 #include "../fb_private_thread.h"
5 #include <xboxkrnl/xboxkrnl.h>
6 
7 static void NTAPI threadproc(void *param1, void *param2)
8 {
9 #if 0
10  FBTHREAD *thread = param1;
11 
12  /* call the user thread procedure */
13  thread->proc( thread->param );
14 
15  /* free mem */
16  fb_TlsFreeCtxTb( );
17 #endif
18 }
19 
20 FBCALL FBTHREAD *fb_ThreadCreate( FB_THREADPROC proc, void *param, ssize_t stack_size )
21 {
22  NTSTATUS status;
24 
25  thread = malloc( sizeof( FBTHREAD ) );
26 
27  if ( !thread )
28  return NULL;
29 
30  thread->proc = proc;
31  thread->param = param;
32 
33  status = PsCreateSystemThreadEx( &thread->id, /* ThreadHandle */
34  0, /* ThreadExtraSize */
35  /* stack_size??? */ 65536, /* KernelStackSize */
36  0, /* TlsDataSize */
37  NULL, /* ThreadId */
38  &thread, /* StartContext1 */
39  NULL, /* StartContext2 */
40  FALSE, /* CreateSuspended */
41  FALSE, /* DebugStack */
42  threadproc); /* StartRoutine */
43 
44  if( status != STATUS_SUCCESS ) {
45  free( thread );
46  return NULL;
47  }
48 
49  return NULL;
50 }
51 
53 {
54  if( !thread )
55  return;
56 
57  NTWaitForSingleObject( thread->id, FALSE, NULL );
58  NtClose( thread->id );
59  free( thread );
60 }