The install window doesn't need to be wider than the other ones.
[Rockbox.git] / uisimulator / sdl / thread-sdl.c
blob90a4ecf4a7b1af2b0474492bdf82d5aa1f82c233
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
20 #include <time.h>
21 #include <SDL.h>
22 #include <SDL_thread.h>
23 #include <stdlib.h>
24 #include "thread-sdl.h"
25 #include "kernel.h"
26 #include "thread.h"
27 #include "debug.h"
29 SDL_Thread *threads[256];
30 int threadCount = 0;
31 volatile long current_tick = 0;
32 SDL_mutex *m;
34 void yield(void)
36 static int counter = 0;
38 SDL_mutexV(m);
39 if (counter++ >= 50)
41 SDL_Delay(1);
42 counter = 0;
44 SDL_mutexP(m);
47 void sim_sleep(int ticks)
49 SDL_mutexV(m);
50 SDL_Delay((1000/HZ) * ticks);
51 SDL_mutexP(m);
54 int runthread(void *data)
56 SDL_mutexP(m);
57 ((void(*)())data) ();
58 SDL_mutexV(m);
59 return 0;
62 struct thread_entry*
63 create_thread(void (*function)(void), void* stack, int stack_size,
64 const char *name)
66 /** Avoid compiler warnings */
67 (void)stack;
68 (void)stack_size;
69 (void)name;
70 SDL_Thread* t;
72 if (threadCount == 256) {
73 return NULL;
76 t = SDL_CreateThread(runthread, function);
77 threads[threadCount++] = t;
79 yield();
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");
93 exit(-1);
97 void remove_thread(struct thread_entry *thread)
99 SDL_KillThread((SDL_Thread*) thread);