summaryrefslogtreecommitdiff
path: root/uisimulator/x11/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/x11/thread.c')
-rw-r--r--uisimulator/x11/thread.c69
1 files changed, 69 insertions, 0 deletions
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}