1 #include "internal.h"
\r
7 /****************************************************************************/
\r
8 #if (defined _WIN32 && defined _MSC_VER && !defined WIN_KERNEL_BUILD)
\r
10 /* TRD : any Windows (user-mode) on any CPU with the Microsoft C compiler
\r
12 _WIN32 indicates 64-bit or 32-bit Windows
\r
13 _MSC_VER indicates Microsoft C compiler
\r
14 !WIN_KERNEL_BUILD indicates Windows user-mode
\r
17 int abstraction_thread_start( thread_state_t *thread_state, unsigned int cpu, thread_function_t thread_function, void *thread_user_state )
\r
29 assert( thread_state != NULL );
\r
30 // TRD : cpu can be any value in its range
\r
31 assert( thread_function != NULL );
\r
32 // TRD : thread_user_state can be NULL
\r
34 affinity_mask = (DWORD_PTR) (1 << cpu);
\r
36 *thread_state = CreateThread( NULL, 0, thread_function, thread_user_state, NO_FLAGS, &thread_id );
\r
38 result = SetThreadAffinityMask( *thread_state, affinity_mask );
\r
40 if( *thread_state != NULL and result != 0 )
\r
52 /****************************************************************************/
\r
53 #if (defined _WIN32 && defined _MSC_VER && defined WIN_KERNEL_BUILD)
\r
55 /* TRD : any Windows on any CPU with the Microsoft C compiler
\r
57 _WIN32 indicates 64-bit or 32-bit Windows
\r
58 _MSC_VER indicates Microsoft C compiler
\r
59 WIN_KERNEL_BUILD indicates Windows kernel
\r
62 int abstraction_thread_start( thread_state_t *thread_state, unsigned int cpu, thread_function_t thread_function, void *thread_user_state )
\r
74 assert( thread_state != NULL );
\r
75 // TRD : cpu can be any value in its range
\r
76 assert( thread_function != NULL );
\r
77 // TRD : thread_user_state can be NULL
\r
79 affinity_mask = 1 << cpu;
\r
81 nts_create = PsCreateSystemThread( thread_state, THREAD_ALL_ACCESS, NULL, NULL, NULL, thread_function, thread_user_state );
\r
83 nts_affinity = ZwSetInformationThread( thread_state, ThreadAffinityMask, &affinity_mask, sizeof(KAFFINITY) );
\r
85 if( nts_create == STATUS_SUCCESS and nts_affinity == STATUS_SUCCESS )
\r
97 /****************************************************************************/
\r
98 #if (defined __unix__)
\r
100 /* TRD : any UNIX on any CPU with any compiler
\r
102 I assumed pthreads is available on any UNIX.
\r
104 __unix__ indicates Solaris, Linux, HPUX, etc
\r
107 int abstraction_thread_start( thread_state_t *thread_state, unsigned int cpu, thread_function_t thread_function, void *thread_user_state )
\r
113 assert( thread_state != NULL );
\r
114 // TRD : cpu can be any value in its range
\r
115 assert( thread_function != NULL );
\r
116 // TRD : thread_user_state can be NULL
\r
118 rv_create = pthread_create( thread_state, NULL, thread_function, thread_user_state );
\r
120 if( rv_create == 0 )
\r