diff options
author | David Walter Seikel | 2012-02-25 00:09:31 +1000 |
---|---|---|
committer | David Walter Seikel | 2012-02-25 00:09:31 +1000 |
commit | eff5b6e0fc5d7106a1a38967c3bbcbf73fdd6e44 (patch) | |
tree | ea1acf1bbd9fdd1f9905a7327183f0fe2bd87468 /LuaSL/src/LuaSL_threads.h | |
parent | Time to fork luaproc and turn it into an EFL based thing, with tighter integr... (diff) | |
download | SledjHamr-eff5b6e0fc5d7106a1a38967c3bbcbf73fdd6e44.zip SledjHamr-eff5b6e0fc5d7106a1a38967c3bbcbf73fdd6e44.tar.gz SledjHamr-eff5b6e0fc5d7106a1a38967c3bbcbf73fdd6e44.tar.bz2 SledjHamr-eff5b6e0fc5d7106a1a38967c3bbcbf73fdd6e44.tar.xz |
Moved luaproc into LuaSL, merged it all into it's own file, and replaced the luaproc list with Eina_Clist.
From this point on, luaproc is officialy forked.
Diffstat (limited to 'LuaSL/src/LuaSL_threads.h')
-rw-r--r-- | LuaSL/src/LuaSL_threads.h | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/LuaSL/src/LuaSL_threads.h b/LuaSL/src/LuaSL_threads.h new file mode 100644 index 0000000..b12a50d --- /dev/null +++ b/LuaSL/src/LuaSL_threads.h | |||
@@ -0,0 +1,199 @@ | |||
1 | /* This code is heavily based on luaproc. | ||
2 | * | ||
3 | * The luaproc copyright notice and license is - | ||
4 | |||
5 | *************************************************** | ||
6 | |||
7 | Copyright 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy | ||
8 | |||
9 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
10 | of this software and associated documentation files (the "Software"), to deal | ||
11 | in the Software without restriction, including without limitation the rights | ||
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
13 | copies of the Software, and to permit persons to whom the Software is | ||
14 | furnished to do so, subject to the following conditions: | ||
15 | |||
16 | The above copyright notice and this permission notice shall be included in | ||
17 | all copies or substantial portions of the Software. | ||
18 | |||
19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
25 | THE SOFTWARE. | ||
26 | |||
27 | **************************************************** | ||
28 | * | ||
29 | * Additions and changes Copyright 2012 by David Seikel, using the above license. | ||
30 | */ | ||
31 | |||
32 | #ifndef __LUASL_THREADS_H__ | ||
33 | #define __LUASL_THREADS_H__ | ||
34 | |||
35 | //#include <Ecore.h> | ||
36 | |||
37 | |||
38 | #define CHANNEL_MAX_NAME_LENGTH 255 | ||
39 | |||
40 | #define CHANNEL_DESTROYED 0 | ||
41 | |||
42 | /* message channel pointer type */ | ||
43 | typedef struct stchannel *channel; | ||
44 | |||
45 | |||
46 | |||
47 | /* scheduler function return constants */ | ||
48 | #define LUAPROC_SCHED_OK 0 | ||
49 | #define LUAPROC_SCHED_SOCKET_ERROR -1 | ||
50 | #define LUAPROC_SCHED_SETSOCKOPT_ERROR -2 | ||
51 | #define LUAPROC_SCHED_BIND_ERROR -3 | ||
52 | #define LUAPROC_SCHED_LISTEN_ERROR -4 | ||
53 | #define LUAPROC_SCHED_FORK_ERROR -5 | ||
54 | #define LUAPROC_SCHED_PTHREAD_ERROR -6 | ||
55 | #define LUAPROC_SCHED_INIT_ERROR -7 | ||
56 | |||
57 | /* ready process queue insertion status */ | ||
58 | #define LUAPROC_SCHED_QUEUE_PROC_OK 0 | ||
59 | #define LUAPROC_SCHED_QUEUE_PROC_ERR -1 | ||
60 | |||
61 | /* scheduler listener service default hostname and port */ | ||
62 | #define LUAPROC_SCHED_DEFAULT_HOST "127.0.0.1" | ||
63 | #define LUAPROC_SCHED_DEFAULT_PORT 3133 | ||
64 | |||
65 | /* scheduler default number of worker threads */ | ||
66 | #define LUAPROC_SCHED_DEFAULT_WORKER_THREADS 1 | ||
67 | |||
68 | |||
69 | |||
70 | /* process is idle */ | ||
71 | #define LUAPROC_STAT_IDLE 0 | ||
72 | /* process is ready to run */ | ||
73 | #define LUAPROC_STAT_READY 1 | ||
74 | /* process is blocked on send */ | ||
75 | #define LUAPROC_STAT_BLOCKED_SEND 2 | ||
76 | /* process is blocked on receive */ | ||
77 | #define LUAPROC_STAT_BLOCKED_RECV 3 | ||
78 | /* process is finished */ | ||
79 | #define LUAPROC_STAT_FINISHED 4 | ||
80 | |||
81 | /* lua process pointer type */ | ||
82 | typedef struct stluaproc *luaproc; | ||
83 | |||
84 | |||
85 | |||
86 | |||
87 | |||
88 | /* initialize channels */ | ||
89 | void channel_init( void ); | ||
90 | |||
91 | /* create new channel */ | ||
92 | channel channel_create( const char *cname ); | ||
93 | |||
94 | /* destroy a channel */ | ||
95 | int channel_destroy( channel chan, const char *chname ); | ||
96 | |||
97 | /* search for and return a channel with a given name */ | ||
98 | channel channel_search( const char *cname ); | ||
99 | |||
100 | /* return a channel's send queue */ | ||
101 | Eina_Clist *channel_get_sendq( channel chan ); | ||
102 | |||
103 | /* return a channel's receive queue */ | ||
104 | Eina_Clist *channel_get_recvq( channel chan ); | ||
105 | |||
106 | /* return a channel's mutex */ | ||
107 | pthread_mutex_t *channel_get_mutex( channel chan ); | ||
108 | |||
109 | /* return a channel's conditional variable */ | ||
110 | pthread_cond_t *channel_get_cond( channel chan ); | ||
111 | |||
112 | |||
113 | |||
114 | |||
115 | |||
116 | |||
117 | /* initialize local scheduler */ | ||
118 | int sched_init_local( int numworkers ); | ||
119 | |||
120 | /* initialize socket enabled scheduler */ | ||
121 | int sched_init_socket( int numworkers, const char *host, int port ); | ||
122 | |||
123 | /* exit scheduler */ | ||
124 | void sched_exit( void ); | ||
125 | |||
126 | /* move process to ready queue (ie, schedule process) */ | ||
127 | int sched_queue_proc( luaproc lp ); | ||
128 | |||
129 | /* join all worker threads and exit */ | ||
130 | void sched_join_workerthreads( void ); | ||
131 | |||
132 | /* increase active luaproc count */ | ||
133 | void sched_lpcount_inc( void ); | ||
134 | |||
135 | /* decrease active luaproc count */ | ||
136 | void sched_lpcount_dec( void ); | ||
137 | |||
138 | /* create a new worker pthread */ | ||
139 | int sched_create_worker( void ); | ||
140 | |||
141 | |||
142 | |||
143 | |||
144 | |||
145 | |||
146 | void luaprocInit(void); | ||
147 | void luaprocRegister(lua_State *L); | ||
148 | int newProc(const char *code, int file, Ecore_Cb callback, void *data); | ||
149 | |||
150 | |||
151 | /* return a process' status */ | ||
152 | int luaproc_get_status( luaproc lp ); | ||
153 | |||
154 | /* set a process' status */ | ||
155 | void luaproc_set_status( luaproc lp, int status ); | ||
156 | |||
157 | /* return a process' state */ | ||
158 | lua_State *luaproc_get_state( luaproc lp ); | ||
159 | |||
160 | /* return the number of arguments expected by a given a process */ | ||
161 | int luaproc_get_args( luaproc lp ); | ||
162 | |||
163 | /* set the number of arguments expected by a given process */ | ||
164 | void luaproc_set_args( luaproc lp, int n ); | ||
165 | |||
166 | /* create luaproc (from scheduler) */ | ||
167 | luaproc luaproc_create_sched( char *code ); | ||
168 | |||
169 | /* register luaproc's functions in a lua_State */ | ||
170 | void luaproc_register_funcs( lua_State *L ); | ||
171 | |||
172 | /* allow registering of luaproc's functions in c main prog */ | ||
173 | void luaproc_register_lib( lua_State *L ); | ||
174 | |||
175 | /* queue a luaproc that tried to send a message */ | ||
176 | void luaproc_queue_sender( luaproc lp ); | ||
177 | |||
178 | const char *sendToChannel(const char *chname, const char *message, luaproc *dst, channel *chn); | ||
179 | |||
180 | /* queue a luaproc that tried to receive a message */ | ||
181 | void luaproc_queue_receiver( luaproc lp ); | ||
182 | |||
183 | /* unlock a channel's access */ | ||
184 | void luaproc_unlock_channel( channel chan ); | ||
185 | |||
186 | /* return a luaproc's channel */ | ||
187 | channel luaproc_get_channel( luaproc lp ); | ||
188 | |||
189 | /* return status (boolean) indicating if worker thread should be destroyed after luaproc execution */ | ||
190 | int luaproc_get_destroyworker( luaproc lp ); | ||
191 | |||
192 | /* return status (boolean) indicating if lua process should be recycled */ | ||
193 | luaproc luaproc_recycle_pop( void ); | ||
194 | |||
195 | /* add a lua process to the recycle list */ | ||
196 | int luaproc_recycle_push( luaproc lp ); | ||
197 | |||
198 | |||
199 | #endif | ||