2 * psychlops_app_init_Win32.h
3 * Psychlops Standard Library (Universal)
5 * Last Modified 2005/12/19 by Kenchi HOSOKAWA
6 * (C) 2005 Kenchi HOSOKAWA, Kazushi MARUYA, Takao SATO
9 #include "../../core/ApplicationInterfaces/psychlops_app_thread.h"
10 #include <ApplicationServices/ApplicationServices.h>
11 #include <CoreServices/CoreServices.h>
18 void* threadIDPtr(char *t) { return t; }
19 void* threadFuncPtr(char *t) { return (t+8); }
20 OSStatus beginThread(void *param) {
21 void (*func)() = (void(*)())param;
27 for(int i=0; i<32; i++) memory[i] = 0;
29 Thread::Thread(void (*func)()) {
30 for(int i=0; i<32; i++) memory[i] = 0;
34 //TerminateThread(()threadIDPtr(memory))
36 void Thread::create(void (*func)()) {
37 MPCreateTask((TaskProc)&beginThread, (void*)func, 4096, NULL, NULL, NULL, 0, (MPTaskID*)threadIDPtr(memory));
40 const unsigned int thread_state[5] = {
47 void Thread::sleep(int microsec) {
49 MPCreateSemaphore(0, 0, &delay);
50 MPWaitOnSemaphore(delay, kDurationMicrosecond*microsec);
51 MPDeleteSemaphore(delay);
53 void Thread::yield() {
56 void Thread::priority( Priority priority ) {
57 SetThreadState(kCurrentThreadID, thread_state[priority], kNoThreadID);
59 Thread::Priority Thread::priority() {
60 ThreadState threadState;
61 GetThreadState(kCurrentThreadID, &threadState);
63 case kStoppedThreadState:
65 case kReadyThreadState:
68 case kRunningThreadState:
69 return Thread::NORMAL;