6 #define WIN32_LEAN_AND_MEAN
10 #include <sys/signal.h>
16 #if !defined(__WIN32__)
20 public enum ThreadPriority
31 public int GetCurrentThreadID()
33 #if defined(__WIN32__)
34 return (int)GetCurrentThreadId();
36 return pthread_self();
44 #if defined(__WIN32__)
50 #if defined(__WIN32__)
64 uint returnCode = this.returnCode = Main();
66 #if defined(__WIN32__)
80 virtual uint Main(void);
87 #if !defined(__WIN32__)
91 // printf("Creating %s thread\n", _class.name);
92 #if defined(__WIN32__)
94 handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadCallBack, this, 0, &id);
98 /*pthread_attr_t attr;
99 pthread_attr_init(&attr);
100 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);*/ // Default attribute ???
101 error = pthread_create(&id, null /*&attr*/, (void *)ThreadCallBack, this);
103 printf("Error %d creating a thread\n", error);
111 #if defined(__WIN32__)
114 TerminateThread(handle, 0);
119 pthread_kill(id, SIGQUIT);
130 #if defined(__WIN32__)
131 if(WaitForSingleObject(handle, INFINITE /*2000*/) == WAIT_TIMEOUT)
132 PrintLn("Thread not returning?\n");
137 pthread_join(id, NULL);*/
144 void SetPriority(ThreadPriority priority)
146 #if defined(__WIN32__)
147 SetThreadPriority(handle, priority);
150 struct sched_param param;
151 int policy = (priority > 0) ? SCHED_RR : SCHED_OTHER;
152 param.sched_priority = (priority > 0) ? (priority * 99 / 15) : 0;
153 pthread_setschedparam(id, policy, ¶m);
158 property bool created { get { return started; } };