3939
4040uint64_t zfs_threads = 0 ;
4141
42- kthread_t *
42+
43+ kthread_t *
44+ spl_thread_create (
45+ caddr_t stk ,
46+ size_t stksize ,
47+ void (* proc )(void * ),
48+ void * arg ,
49+ size_t len ,
50+ int state ,
51+ #ifdef SPL_DEBUG_THREAD
52+ char * filename ,
53+ int line ,
54+ #endif
55+ pri_t pri )
56+ {
57+ NTSTATUS status ;
58+ HANDLE hThread = NULL ;
59+ PETHREAD eThread = NULL ;
60+
61+ #ifdef SPL_DEBUG_THREAD
62+ dprintf ("Start thread pri %d\n" , pri );
63+ #endif
64+
65+ status = PsCreateSystemThread (
66+ & hThread ,
67+ THREAD_ALL_ACCESS ,
68+ NULL ,
69+ NULL ,
70+ NULL ,
71+ proc ,
72+ arg );
73+
74+ if (!NT_SUCCESS (status ))
75+ return NULL ;
76+
77+ /* Convert HANDLE ETHREAD */
78+ status = ObReferenceObjectByHandle (
79+ hThread ,
80+ THREAD_ALL_ACCESS ,
81+ * PsThreadType ,
82+ KernelMode ,
83+ (PVOID * )& eThread ,
84+ NULL );
85+
86+ /* We no longer need the handle */
87+ ZwClose (hThread );
88+
89+ if (!NT_SUCCESS (status ))
90+ return NULL ;
91+
92+ /* Clamp priority to safe Windows range */
93+ KPRIORITY newPri = (KPRIORITY )pri ;
94+
95+ if (newPri > maxclsyspri )
96+ newPri = maxclsyspri ;
97+
98+ if (newPri < minclsyspri )
99+ newPri = minclsyspri ;
100+
101+ /* Set absolute priority */
102+ KeSetPriorityThread ((PKTHREAD )eThread , newPri );
103+
104+ #ifdef SPL_DEBUG_THREAD
105+ dprintf ("Thread created with priority %d\n" , newPri );
106+ #endif
107+
108+ atomic_inc_64 (& zfs_threads );
109+
110+ return (kthread_t * )eThread ;
111+ }
112+
113+ /*kthread_t*
43114spl_thread_create(
44115 caddr_t stk,
45116 size_t stksize,
@@ -72,12 +143,7 @@ spl_thread_create(
72143 if (result != STATUS_SUCCESS)
73144 return (NULL);
74145
75- /*
76- * Improve the priority when asked to do so
77- * Thread priorities range from 0 to 31, where 0 is the lowest
78- * priority and 31 is the highest
79- */
80-
146+
81147 if (pri > minclsyspri) {
82148 // thread_precedence_policy_data_t policy;
83149 // policy.importance = pri - minclsyspri;
@@ -102,7 +168,7 @@ spl_thread_create(
102168 ObDereferenceObject(eThread);
103169 ZwClose(thread);
104170 return ((kthread_t *)eThread);
105- }
171+ }*/
106172
107173kthread_t *
108174spl_current_thread (void )
0 commit comments