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