1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 Dan Everton
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #include <SDL_thread.h>
24 #include "thread-sdl.h"
29 SDL_Thread
*threads
[256];
31 long current_tick
= 0;
36 static int counter
= 0;
47 void sim_sleep(int ticks
)
50 SDL_Delay((1000/HZ
) * ticks
);
54 int runthread(void *data
)
63 create_thread(void (*function
)(void), void* stack
, int stack_size
,
66 /** Avoid compiler warnings */
72 if (threadCount
== 256) {
76 t
= SDL_CreateThread(runthread
, function
);
77 threads
[threadCount
++] = t
;
81 /* The return value is never de-referenced outside thread.c so this
82 nastiness should be fine. However, a better solution would be nice.
84 return (struct thread_entry
*)t
;
87 void init_threads(void)
89 m
= SDL_CreateMutex();
91 if (SDL_mutexP(m
) == -1) {
92 fprintf(stderr
, "Couldn't lock mutex\n");
97 void remove_thread(struct thread_entry
*thread
)
99 SDL_KillThread((SDL_Thread
*) thread
);