win-pvdrivers

view liblfds.6/test/src/abstraction_thread_start.c @ 1025:aa2e51f67f7c

Fix hibernate under Win8. Change debugprints.
author James Harper <james.harper@bendigoit.com.au>
date Tue Feb 19 15:14:53 2013 +1100 (2013-02-19)
parents 6300617040e0
children
line source
1 #include "internal.h"
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
15 */
17 int abstraction_thread_start( thread_state_t *thread_state, unsigned int cpu, thread_function_t thread_function, void *thread_user_state )
18 {
19 int
20 rv = 0;
22 DWORD
23 thread_id;
25 DWORD_PTR
26 affinity_mask,
27 result;
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 )
41 rv = 1;
43 return( rv );
44 }
46 #endif
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
60 */
62 int abstraction_thread_start( thread_state_t *thread_state, unsigned int cpu, thread_function_t thread_function, void *thread_user_state )
63 {
64 int
65 rv = 0;
67 KAFFINITY
68 affinity_mask
70 NTSTATUS
71 nts_create,
72 nts_affinity;
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 )
86 rv = 1;
88 return( rv );
89 }
91 #endif
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
105 */
107 int abstraction_thread_start( thread_state_t *thread_state, unsigned int cpu, thread_function_t thread_function, void *thread_user_state )
108 {
109 int
110 rv = 0,
111 rv_create;
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 );
120 if( rv_create == 0 )
121 rv = 1;
123 return( rv );
124 }
126 #endif