summaryrefslogtreecommitdiff
path: root/apps/plugins/sdl/src/thread/pth
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/sdl/src/thread/pth')
-rw-r--r--apps/plugins/sdl/src/thread/pth/SDL_syscond.c164
-rw-r--r--apps/plugins/sdl/src/thread/pth/SDL_sysmutex.c87
-rw-r--r--apps/plugins/sdl/src/thread/pth/SDL_sysmutex_c.h31
-rw-r--r--apps/plugins/sdl/src/thread/pth/SDL_systhread.c103
-rw-r--r--apps/plugins/sdl/src/thread/pth/SDL_systhread_c.h31
5 files changed, 0 insertions, 416 deletions
diff --git a/apps/plugins/sdl/src/thread/pth/SDL_syscond.c b/apps/plugins/sdl/src/thread/pth/SDL_syscond.c
deleted file mode 100644
index ede74aaeae..0000000000
--- a/apps/plugins/sdl/src/thread/pth/SDL_syscond.c
+++ /dev/null
@@ -1,164 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/*
25 * GNU pth conditions variables
26 *
27 * Patrice Mandin
28 */
29
30#include <pth.h>
31
32#include "SDL_thread.h"
33#include "SDL_sysmutex_c.h"
34
35struct SDL_cond
36{
37 pth_cond_t condpth_p;
38};
39
40/* Create a condition variable */
41SDL_cond * SDL_CreateCond(void)
42{
43 SDL_cond *cond;
44
45 cond = (SDL_cond *) SDL_malloc(sizeof(SDL_cond));
46 if ( cond ) {
47 if ( pth_cond_init(&(cond->condpth_p)) < 0 ) {
48 SDL_SetError("pthread_cond_init() failed");
49 SDL_free(cond);
50 cond = NULL;
51 }
52 } else {
53 SDL_OutOfMemory();
54 }
55 return(cond);
56}
57
58/* Destroy a condition variable */
59void SDL_DestroyCond(SDL_cond *cond)
60{
61 if ( cond ) {
62 SDL_free(cond);
63 }
64}
65
66/* Restart one of the threads that are waiting on the condition variable */
67int SDL_CondSignal(SDL_cond *cond)
68{
69 int retval;
70
71 if ( ! cond ) {
72 SDL_SetError("Passed a NULL condition variable");
73 return -1;
74 }
75
76 retval = 0;
77 if ( pth_cond_notify(&(cond->condpth_p), FALSE) != 0 ) {
78 SDL_SetError("pth_cond_notify() failed");
79 retval = -1;
80 }
81 return retval;
82}
83
84/* Restart all threads that are waiting on the condition variable */
85int SDL_CondBroadcast(SDL_cond *cond)
86{
87 int retval;
88
89 if ( ! cond ) {
90 SDL_SetError("Passed a NULL condition variable");
91 return -1;
92 }
93
94 retval = 0;
95 if ( pth_cond_notify(&(cond->condpth_p), TRUE) != 0 ) {
96 SDL_SetError("pth_cond_notify() failed");
97 retval = -1;
98 }
99 return retval;
100}
101
102/* Wait on the condition variable for at most 'ms' milliseconds.
103 The mutex must be locked before entering this function!
104 The mutex is unlocked during the wait, and locked again after the wait.
105
106Typical use:
107
108Thread A:
109 SDL_LockMutex(lock);
110 while ( ! condition ) {
111 SDL_CondWait(cond);
112 }
113 SDL_UnlockMutex(lock);
114
115Thread B:
116 SDL_LockMutex(lock);
117 ...
118 condition = true;
119 ...
120 SDL_UnlockMutex(lock);
121 */
122int SDL_CondWaitTimeout(SDL_cond *cond, SDL_mutex *mutex, Uint32 ms)
123{
124 int retval;
125 pth_event_t ev;
126 int sec;
127
128 if ( ! cond ) {
129 SDL_SetError("Passed a NULL condition variable");
130 return -1;
131 }
132
133 retval = 0;
134
135 sec = ms/1000;
136 ev = pth_event(PTH_EVENT_TIME, pth_timeout(sec,(ms-sec*1000)*1000));
137
138 if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), ev) != 0 ) {
139 SDL_SetError("pth_cond_await() failed");
140 retval = -1;
141 }
142
143 pth_event_free(ev, PTH_FREE_ALL);
144
145 return retval;
146}
147
148/* Wait on the condition variable forever */
149int SDL_CondWait(SDL_cond *cond, SDL_mutex *mutex)
150{
151 int retval;
152
153 if ( ! cond ) {
154 SDL_SetError("Passed a NULL condition variable");
155 return -1;
156 }
157
158 retval = 0;
159 if ( pth_cond_await(&(cond->condpth_p), &(mutex->mutexpth_p), NULL) != 0 ) {
160 SDL_SetError("pth_cond_await() failed");
161 retval = -1;
162 }
163 return retval;
164}
diff --git a/apps/plugins/sdl/src/thread/pth/SDL_sysmutex.c b/apps/plugins/sdl/src/thread/pth/SDL_sysmutex.c
deleted file mode 100644
index ca83b92c24..0000000000
--- a/apps/plugins/sdl/src/thread/pth/SDL_sysmutex.c
+++ /dev/null
@@ -1,87 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/*
25 * GNU pth mutexes
26 *
27 * Patrice Mandin
28 */
29
30#include <pth.h>
31
32#include "SDL_mutex.h"
33#include "SDL_sysmutex_c.h"
34
35/* Create a mutex */
36SDL_mutex *SDL_CreateMutex(void)
37{
38 SDL_mutex *mutex;
39
40 /* Allocate mutex memory */
41 mutex = (SDL_mutex *)SDL_malloc(sizeof(*mutex));
42 if ( mutex ) {
43 /* Create the mutex, with initial value signaled */
44 if (!pth_mutex_init(&(mutex->mutexpth_p))) {
45 SDL_SetError("Couldn't create mutex");
46 SDL_free(mutex);
47 mutex = NULL;
48 }
49 } else {
50 SDL_OutOfMemory();
51 }
52 return(mutex);
53}
54
55/* Free the mutex */
56void SDL_DestroyMutex(SDL_mutex *mutex)
57{
58 if ( mutex ) {
59 SDL_free(mutex);
60 }
61}
62
63/* Lock the mutex */
64int SDL_mutexP(SDL_mutex *mutex)
65{
66 if ( mutex == NULL ) {
67 SDL_SetError("Passed a NULL mutex");
68 return -1;
69 }
70
71 pth_mutex_acquire(&(mutex->mutexpth_p), FALSE, NULL);
72
73 return(0);
74}
75
76/* Unlock the mutex */
77int SDL_mutexV(SDL_mutex *mutex)
78{
79 if ( mutex == NULL ) {
80 SDL_SetError("Passed a NULL mutex");
81 return -1;
82 }
83
84 pth_mutex_release(&(mutex->mutexpth_p));
85
86 return(0);
87}
diff --git a/apps/plugins/sdl/src/thread/pth/SDL_sysmutex_c.h b/apps/plugins/sdl/src/thread/pth/SDL_sysmutex_c.h
deleted file mode 100644
index d29060e9ff..0000000000
--- a/apps/plugins/sdl/src/thread/pth/SDL_sysmutex_c.h
+++ /dev/null
@@ -1,31 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _SDL_SYSMUTEX_C_H_
25#define _SDL_SYSMUTEX_C_H_
26
27struct SDL_mutex {
28 pth_mutex_t mutexpth_p;
29};
30
31#endif /* _SDL_SYSMUTEX_C_H_ */
diff --git a/apps/plugins/sdl/src/thread/pth/SDL_systhread.c b/apps/plugins/sdl/src/thread/pth/SDL_systhread.c
deleted file mode 100644
index bfccaf340f..0000000000
--- a/apps/plugins/sdl/src/thread/pth/SDL_systhread.c
+++ /dev/null
@@ -1,103 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24/*
25 * GNU pth threads
26 *
27 * Patrice Mandin
28 */
29
30#include <pth.h>
31#include <signal.h>
32
33#include "SDL_thread.h"
34#include "../SDL_thread_c.h"
35#include "../SDL_systhread.h"
36
37/* List of signals to mask in the subthreads */
38static int sig_list[] = {
39 SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGCHLD, SIGWINCH,
40 SIGVTALRM, SIGPROF, 0
41};
42
43static void *RunThread(void *data)
44{
45 SDL_RunThread(data);
46 pth_exit((void*)0);
47 return((void *)0); /* Prevent compiler warning */
48}
49
50int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
51{
52 pth_attr_t type;
53
54 /* Create a new attribute */
55 type = pth_attr_new();
56 if ( type == NULL ) {
57 SDL_SetError("Couldn't initialize pth attributes");
58 return(-1);
59 }
60 pth_attr_set(type, PTH_ATTR_JOINABLE, TRUE);
61
62 /* Create the thread and go! */
63 thread->handle = pth_spawn(type, RunThread, args);
64 if ( thread->handle == NULL ) {
65 SDL_SetError("Not enough resources to create thread");
66 return(-1);
67 }
68 return(0);
69}
70
71void SDL_SYS_SetupThread(void)
72{
73 int i;
74 sigset_t mask;
75 int oldstate;
76
77 /* Mask asynchronous signals for this thread */
78 sigemptyset(&mask);
79 for ( i=0; sig_list[i]; ++i ) {
80 sigaddset(&mask, sig_list[i]);
81 }
82 pth_sigmask(SIG_BLOCK, &mask, 0);
83
84 /* Allow ourselves to be asynchronously cancelled */
85 pth_cancel_state(PTH_CANCEL_ASYNCHRONOUS, &oldstate);
86}
87
88/* WARNING: This may not work for systems with 64-bit pid_t */
89Uint32 SDL_ThreadID(void)
90{
91 return((Uint32)pth_self());
92}
93
94void SDL_SYS_WaitThread(SDL_Thread *thread)
95{
96 pth_join(thread->handle, NULL);
97}
98
99void SDL_SYS_KillThread(SDL_Thread *thread)
100{
101 pth_cancel(thread->handle);
102 pth_join(thread->handle, NULL);
103}
diff --git a/apps/plugins/sdl/src/thread/pth/SDL_systhread_c.h b/apps/plugins/sdl/src/thread/pth/SDL_systhread_c.h
deleted file mode 100644
index 50bb26df54..0000000000
--- a/apps/plugins/sdl/src/thread/pth/SDL_systhread_c.h
+++ /dev/null
@@ -1,31 +0,0 @@
1/*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2012 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public
16 License along with this library; if not, write to the Free
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21*/
22#include "SDL_config.h"
23
24#ifndef _SDL_SYSTHREAD_C_H_
25#define _SDL_SYSTHREAD_C_H_
26
27#include <pth.h>
28
29typedef pth_t SYS_ThreadHandle;
30
31#endif /* _SDL_SYSTHREAD_C_H_ */