1 /*  src/threads.h: Constants and prototypes for thread handling
2     Copyright 2010 Andrew Church
3 
4     This file is part of Yabause.
5 
6     Yabause is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     Yabause is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with Yabause; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 */
20 
21 #ifndef THREADS_H
22 #define THREADS_H
23 
24 ///////////////////////////////////////////////////////////////////////////
25 // Thread constants
26 ///////////////////////////////////////////////////////////////////////////
27 
28 // Thread IDs
29 enum {
30    YAB_THREAD_SCSP = 0,
31    YAB_THREAD_GDBSTUBCLIENT,
32    YAB_THREAD_GDBSTUBLISTENER,
33    YAB_THREAD_NETLINKLISTENER,
34    YAB_THREAD_NETLINKCONNECT,
35    YAB_THREAD_NETLINKCLIENT,
36    YAB_THREAD_OPENAL,
37    YAB_THREAD_VIDSOFT_LAYER_NBG3,
38    YAB_THREAD_VIDSOFT_LAYER_NBG2,
39    YAB_THREAD_VIDSOFT_LAYER_NBG1,
40    YAB_THREAD_VIDSOFT_LAYER_NBG0,
41    YAB_THREAD_VIDSOFT_LAYER_RBG0,
42    YAB_THREAD_VIDSOFT_VDP1,
43    YAB_THREAD_VIDSOFT_PRIORITY_0,
44    YAB_THREAD_VIDSOFT_PRIORITY_1,
45    YAB_THREAD_VIDSOFT_PRIORITY_2,
46    YAB_THREAD_VIDSOFT_PRIORITY_3,
47    YAB_THREAD_VIDSOFT_PRIORITY_4,
48    YAB_THREAD_VIDSOFT_LAYER_SPRITE,
49    YAB_NUM_THREADS      // Total number of subthreads
50 };
51 
52 // Number of (boolean) semaphores available per thread
53 #define YAB_NUM_SEMAPHORES  2
54 
55 ///////////////////////////////////////////////////////////////////////////
56 // Thread functions (must be implemented by the port; only used if
57 // yabauseinit_struct.usethreads != 0 at YabauseInit() time)
58 ///////////////////////////////////////////////////////////////////////////
59 
60 // YabThreadStart:  Start a new thread for the given function.  Only one
61 // thread will be started for each thread ID (YAB_THREAD_*).  Returns 0 on
62 // success, -1 on error.
63 int YabThreadStart(unsigned int id, void (*func)(void *), void *arg);
64 
65 // YabThreadWait:  Wait for the given ID's thread to terminate.  Returns
66 // immediately if no thread has been started on the given ID.
67 void YabThreadWait(unsigned int id);
68 
69 // YabThreadYield:  Yield CPU execution to another thread.
70 void YabThreadYield(void);
71 
72 // YabThreadSleep:  Put the current thread to sleep.
73 void YabThreadSleep(void);
74 
75 // YabThreadSleep:  Put the specified thread to sleep.
76 void YabThreadRemoteSleep(unsigned int id);
77 
78 // YabThreadWake:  Wake up the given thread if it is asleep.
79 void YabThreadWake(unsigned int id);
80 
81 ///////////////////////////////////////////////////////////////////////////
82 
83 #endif  // THREADS_H
84