summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-06-10 10:17:54 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-06-10 10:17:54 +0000
commit604cce76cffcad3e890084f90b1199a0ce46e176 (patch)
tree7c325a731ed34b9b7219eecd9218d6e40a4fc9fe
parentb97f032464f654f9bd4c45a3b09a52e6a3693ca0 (diff)
downloadrockbox-604cce76cffcad3e890084f90b1199a0ce46e176.tar.gz
rockbox-604cce76cffcad3e890084f90b1199a0ce46e176.zip
add thread functionality, powered by pthreads
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@928 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/x11/Makefile4
-rw-r--r--uisimulator/x11/thread.c69
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
49INCLUDES = -I. -I$(DRIVERS) -I$(COMMON) -I$(FIRMWAREDIR) -I$(APPDIR) -I$(RECDIR) 49INCLUDES = -I. -I$(DRIVERS) -I$(COMMON) -I$(FIRMWAREDIR) -I$(APPDIR) -I$(RECDIR)
50 50
51LIBS = 51LIBS = -lpthread
52 52
53UNAME := $(shell uname) 53UNAME := $(shell uname)
54ifeq ($(UNAME),Linux) 54ifeq ($(UNAME),Linux)
@@ -77,7 +77,7 @@ ifeq ($(DISPLAY),-DHAVE_LCD_BITMAP)
77endif 77endif
78 78
79SRCS = screenhack.c uibasic.c resources.c visual.c lcd-x11.c mpeg.c \ 79SRCS = 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
82ifdef MPEG_PLAY 82ifdef 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
29pthread_mutex_t mp;
30
31void 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
41void yield(void)
42{
43 pthread_mutex_unlock(&mp); /* return */
44 pthread_mutex_lock(&mp); /* get it again */
45}
46
47int 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}