9 #define WIN32_LEAN_AND_MEAN
10 #define String String_
11 #define Thread Thread_
17 #if !defined(__ANDROID__)
26 #if !defined(__WIN32__)
30 public enum ThreadPriority
45 #if defined(__WIN32__)
51 #if defined(__WIN32__)
54 #elif !defined(__EMSCRIPTEN__)
65 #if !defined(__EMSCRIPTEN__)
66 #if defined(__WIN32__)
69 void * ThreadCallBack()
72 uint returnCode = this.returnCode = Main();
74 #if defined(__WIN32__)
84 #if defined(__WIN32__)
87 return (void *)(uintptr_t)returnCode;
93 virtual uint Main(void);
100 #if !defined(__WIN32__) && !defined(__EMSCRIPTEN__)
104 // printf("Creating %s thread\n", _class.name);
105 #if !defined(__EMSCRIPTEN__)
106 #if defined(__WIN32__)
110 handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadCallBack, this, 0, &tID);
116 /*pthread_attr_t attr;
117 pthread_attr_init(&attr);
118 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);*/ // Default attribute ???
119 error = pthread_create(&id, null /*&attr*/, ThreadCallBack, this);
121 printf("Error %d creating a thread\n", error);
130 #if !defined(__EMSCRIPTEN__)
131 #if defined(__WIN32__)
134 TerminateThread(handle, 0);
139 pthread_kill(id, SIGQUIT);
151 #if !defined(__EMSCRIPTEN__)
152 #if defined(__WIN32__)
153 if(WaitForSingleObject(handle, INFINITE /*2000*/) == WAIT_TIMEOUT)
154 PrintLn("Thread not returning?\n");
159 pthread_join(id, NULL);*/
167 void SetPriority(ThreadPriority priority)
169 #if !defined(__EMSCRIPTEN__)
170 #if defined(__WIN32__)
171 SetThreadPriority(handle, priority);
174 struct sched_param param;
175 int policy = (priority > 0) ? SCHED_RR : SCHED_OTHER;
176 param.sched_priority = (priority > 0) ? (priority * 99 / 15) : 0;
177 pthread_setschedparam(id, policy, ¶m);
183 property bool created { get { return started; } };