diff options
Diffstat (limited to 'uisimulator/x11')
-rw-r--r-- | uisimulator/x11/Makefile | 4 | ||||
-rw-r--r-- | uisimulator/x11/thread.c | 69 |
2 files changed, 71 insertions, 2 deletions
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile index 2b2dab1960..0c40a0336a 100644 --- a/uisimulator/x11/Makefile +++ b/uisimulator/x11/Makefile | |||
@@ -48,7 +48,7 @@ LDFLAGS = -lX11 -lm -lXt -lXmu -lnsl | |||
48 | 48 | ||
49 | INCLUDES = -I. -I$(DRIVERS) -I$(COMMON) -I$(FIRMWAREDIR) -I$(APPDIR) -I$(RECDIR) | 49 | INCLUDES = -I. -I$(DRIVERS) -I$(COMMON) -I$(FIRMWAREDIR) -I$(APPDIR) -I$(RECDIR) |
50 | 50 | ||
51 | LIBS = | 51 | LIBS = -lpthread |
52 | 52 | ||
53 | UNAME := $(shell uname) | 53 | UNAME := $(shell uname) |
54 | ifeq ($(UNAME),Linux) | 54 | ifeq ($(UNAME),Linux) |
@@ -77,7 +77,7 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP) | |||
77 | endif | 77 | endif |
78 | 78 | ||
79 | SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c mpeg.c \ | 79 | SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c mpeg.c \ |
80 | button-x11.c io.c sleep.c $(APPS) $(FIRMSRCS) | 80 | button-x11.c io.c sleep.c thread.c $(APPS) $(FIRMSRCS) |
81 | 81 | ||
82 | ifdef MPEG_PLAY | 82 | ifdef MPEG_PLAY |
83 | SRCS += mpegplay.c oss_sound.c bit.c decoder.c fixed.c frame.c huffman.c layer12.c layer3.c stream.c synth.c timer.c version.c | 83 | SRCS += mpegplay.c oss_sound.c bit.c decoder.c fixed.c frame.c huffman.c layer12.c layer3.c stream.c synth.c timer.c version.c |
diff --git a/uisimulator/x11/thread.c b/uisimulator/x11/thread.c new file mode 100644 index 0000000000..769de5bef0 --- /dev/null +++ b/uisimulator/x11/thread.c | |||
@@ -0,0 +1,69 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Daniel Stenberg | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include <stdio.h> | ||
21 | #include <pthread.h> | ||
22 | |||
23 | /* | ||
24 | * We emulate the target threads by using pthreads. We have a mutex that only | ||
25 | * allows one thread at a time to execute. It forces each thread to yield() | ||
26 | * for the other(s) to run. | ||
27 | */ | ||
28 | |||
29 | pthread_mutex_t mp; | ||
30 | |||
31 | void init_threads(void) | ||
32 | { | ||
33 | pthread_mutex_init(&mp, NULL); | ||
34 | } | ||
35 | /* | ||
36 | int pthread_create(pthread_t *new_thread_ID, | ||
37 | const pthread_attr_t *attr, | ||
38 | void * (*start_func)(void *), void *arg); | ||
39 | */ | ||
40 | |||
41 | void yield(void) | ||
42 | { | ||
43 | pthread_mutex_unlock(&mp); /* return */ | ||
44 | pthread_mutex_lock(&mp); /* get it again */ | ||
45 | } | ||
46 | |||
47 | int create_thread(void* fp, void* sp, int stk_size) | ||
48 | { | ||
49 | pthread_t tid; | ||
50 | int i; | ||
51 | int error; | ||
52 | |||
53 | /* we really don't care about these arguments */ | ||
54 | (void)sp; | ||
55 | (void)stk_size; | ||
56 | error = pthread_create(&tid, | ||
57 | NULL, /* default attributes please */ | ||
58 | fp, /* function to start */ | ||
59 | NULL /* start argument */); | ||
60 | if(0 != error) | ||
61 | fprintf(stderr, "Couldn't run thread number %d, errno %d\n", i, error); | ||
62 | else | ||
63 | fprintf(stderr, "Thread %d is running\n", tid); | ||
64 | |||
65 | /* get mutex to only allow one thread running at a time */ | ||
66 | pthread_mutex_lock(&mp); | ||
67 | |||
68 | return error; | ||
69 | } | ||