annotate Isolated/SimpleThreadWindows.c @ 79:358b0bd5df43 tip

Added support for Apportable's alcSuspend()/alcResume() in BeginInterruption()/EndInterruption. You must define ALMIXER_USE_APPORTABLE_OPENAL_EXTENSIONS to compile in this support.
author Eric Wing <ewing@coronalabs.com>
date Tue, 30 Oct 2012 16:01:30 -0700
parents f7acef5a80fe
children
rev   line source
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
1 /* Copyright PlayControl Software LLC / Eric Wing.
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
2 */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
3 #include "SimpleThread.h"
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
4
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
5 #define WIN32_LEAN_AND_MEAN
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
6 #include <process.h>
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
7 #include <windows.h>
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
8 #include <stdlib.h>
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
9
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
10 #if defined(DEBUG)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
11 #include <stdio.h>
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
12 #define THRDDBG(x) printf x
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
13 #else
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
14 #define THRDDBG(x)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
15 #endif
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
16
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
17
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
18 struct SimpleThread
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
19 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
20 unsigned threadID;
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
21 HANDLE nativeThread;
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
22 unsigned threadStatus;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
23 };
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
24
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
25 typedef struct SimpleThreadArguments
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
26 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
27 int (*userFunction)(void*);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
28 void* userData;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
29 SimpleThread* simpleThread;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
30 } SimpleThreadArguments;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
31
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
32
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
33
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
34 static unsigned __stdcall Internal_RunThread(void* user_data)
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
35 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
36 int (*user_function)(void*);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
37 void* function_user_data;
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
38 unsigned* status_val;
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
39
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
40 #if 0
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
41 /* disable signals */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
42 sigset_t disable_set;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
43
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
44 /*
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
45 in the main thread, set up the desired signal mask, common to most threads
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
46 any newly created threads will inherit this signal mask
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
47 */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
48 sigemptyset(&disable_set);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
49 sigaddset(&disable_set, SIGHUP);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
50 sigaddset(&disable_set, SIGINT);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
51 sigaddset(&disable_set, SIGUSR1);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
52 sigaddset(&disable_set, SIGUSR2);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
53 sigaddset(&disable_set, SIGALRM);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
54 sigaddset(&disable_set, SIGQUIT);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
55 sigaddset(&disable_set, SIGPIPE);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
56 sigaddset(&disable_set, SIGTERM);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
57 sigaddset(&disable_set, SIGCHLD);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
58 sigaddset(&disable_set, SIGWINCH);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
59 sigaddset(&disable_set, SIGVTALRM);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
60 sigaddset(&disable_set, SIGPROF);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
61
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
62
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
63 /* block out these signals */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
64 sigprocmask(SIG_BLOCK, &disable_set, NULL);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
65 #endif
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
66
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
67 SimpleThreadArguments* simple_thread_arguments = (SimpleThreadArguments*)user_data;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
68 /* It looks like the last parameter of _beginthreadex sets the threadID for me */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
69 /* simple_thread_arguments->simpleThread->threadID = SimpleThread_GetCurrentThreadID(); */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
70
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
71 user_function = simple_thread_arguments->userFunction;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
72 function_user_data = simple_thread_arguments->userData;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
73 status_val = &simple_thread_arguments->simpleThread->threadStatus;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
74
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
75
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
76 /* I hope this is safe to delete on a different thread than it was created for. */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
77 free(simple_thread_arguments);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
78
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
79 *status_val = user_function(function_user_data);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
80
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
81 _endthreadex( 0 );
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
82
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
83 return 0;
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
84 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
85
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
86
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
87 SimpleThread* SimpleThread_CreateThread(int (*user_function)(void*), void* user_data)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
88 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
89 SimpleThread* new_thread;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
90 SimpleThreadArguments* simple_thread_arguments;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
91
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
92 new_thread = (SimpleThread*)malloc(sizeof(SimpleThread));
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
93 if(NULL == new_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
94 {
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
95 THRDDBG(("Out of memory.\n"));
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
96 return NULL;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
97 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
98
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
99 simple_thread_arguments = (SimpleThreadArguments*)malloc(sizeof(SimpleThreadArguments));
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
100 if(NULL == simple_thread_arguments)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
101 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
102 THRDDBG(("Out of memory.\n"));
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
103 free(new_thread);
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
104 return NULL;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
105 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
106 simple_thread_arguments->userFunction = user_function;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
107 simple_thread_arguments->userData = user_data;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
108 simple_thread_arguments->simpleThread = new_thread;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
109
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
110
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
111 new_thread->nativeThread = (HANDLE)_beginthreadex(NULL, 0, &Internal_RunThread, simple_thread_arguments, 0, &new_thread->threadID);
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
112 if(0 == new_thread->nativeThread)
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
113 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
114 THRDDBG(("_beginthreadex failed with: %d\n", errno));
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
115 free(simple_thread_arguments);
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
116 free(new_thread);
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
117 return NULL;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
118 }
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
119
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
120 return new_thread;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
121 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
122
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
123
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
124
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
125 size_t SimpleThread_GetCurrentThreadID()
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
126 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
127 return (size_t)GetCurrentThreadId();
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
128 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
129
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
130 void SimpleThread_WaitThread(SimpleThread* simple_thread, int* thread_status)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
131 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
132 if(NULL == simple_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
133 {
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
134 THRDDBG(("SimpleThread_WaitThread was passed NULL\n"));
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
135 return;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
136 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
137
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
138 WaitForSingleObject(simple_thread->nativeThread, INFINITE);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
139 CloseHandle(simple_thread->nativeThread);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
140
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
141 if(NULL != thread_status)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
142 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
143 *thread_status = (int)simple_thread->threadStatus;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
144 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
145 free(simple_thread);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
146 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
147
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
148 size_t SimpleThread_GetThreadID(SimpleThread* simple_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
149 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
150 if(NULL == simple_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
151 {
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
152 THRDDBG(("SimpleThread_GetThreadID was passed NULL\n"));
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
153 return 0;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
154 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
155 return (size_t)simple_thread->threadID;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
156 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
157
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
158 /* TODO: Figure out portable/normalized range for levels */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
159 int SimpleThread_GetThreadPriority(SimpleThread* simple_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
160 {
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
161 int ret_val = 0;
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
162
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
163 if(NULL == simple_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
164 {
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
165 THRDDBG(("SimpleThread_GetThreadPriority was passed NULL\n"));
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
166 return THREAD_PRIORITY_ERROR_RETURN; /* Windows ranges seem to go from -15 to +15 */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
167 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
168 ret_val = GetThreadPriority(simple_thread->nativeThread);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
169 if(THREAD_PRIORITY_ERROR_RETURN == ret_val)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
170 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
171 THRDDBG(("SimpleThread_GetThreadPriority GetThreadPriority failed with: %d\n", ret_val));
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
172 return THREAD_PRIORITY_ERROR_RETURN;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
173 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
174 return ret_val;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
175 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
176
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
177 /* TODO: Figure out portable/normalized range for levels */
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
178 void SimpleThread_SetThreadPriority(SimpleThread* simple_thread, int priority_level)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
179 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
180 BOOL ret_val;
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
181
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
182 if(NULL == simple_thread)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
183 {
60
f7acef5a80fe Bug and casting fixes to SimpleThreadWindows.c. Thanks to Johnson Lin for testing and reporting these issues!
Eric Wing <ewing . public |-at-| gmail . com>
parents: 59
diff changeset
184 THRDDBG(("SimpleThread_SetThreadPriority was passed NULL\n"));
59
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
185 return;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
186 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
187
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
188 ret_val = SetThreadPriority(simple_thread->nativeThread, priority_level);
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
189 if(0 == ret_val)
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
190 {
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
191 THRDDBG(("SimpleThread_SetThreadPriority SetThreadPriority failed"));
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
192 return;
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
193 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
194 }
7d508c8cd75a New implementation backend for SimpleThread using native Windows threading APIs.
Eric Wing <ewing . public |-at-| gmail . com>
parents:
diff changeset
195