aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/src/LuaSL_threads.h
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/src/LuaSL_threads.h')
-rw-r--r--LuaSL/src/LuaSL_threads.h199
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
7Copyright 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE 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 */
43typedef 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 */
82typedef struct stluaproc *luaproc;
83
84
85
86
87
88/* initialize channels */
89void channel_init( void );
90
91/* create new channel */
92channel channel_create( const char *cname );
93
94/* destroy a channel */
95int channel_destroy( channel chan, const char *chname );
96
97/* search for and return a channel with a given name */
98channel channel_search( const char *cname );
99
100/* return a channel's send queue */
101Eina_Clist *channel_get_sendq( channel chan );
102
103/* return a channel's receive queue */
104Eina_Clist *channel_get_recvq( channel chan );
105
106/* return a channel's mutex */
107pthread_mutex_t *channel_get_mutex( channel chan );
108
109/* return a channel's conditional variable */
110pthread_cond_t *channel_get_cond( channel chan );
111
112
113
114
115
116
117/* initialize local scheduler */
118int sched_init_local( int numworkers );
119
120/* initialize socket enabled scheduler */
121int sched_init_socket( int numworkers, const char *host, int port );
122
123/* exit scheduler */
124void sched_exit( void );
125
126/* move process to ready queue (ie, schedule process) */
127int sched_queue_proc( luaproc lp );
128
129/* join all worker threads and exit */
130void sched_join_workerthreads( void );
131
132/* increase active luaproc count */
133void sched_lpcount_inc( void );
134
135/* decrease active luaproc count */
136void sched_lpcount_dec( void );
137
138/* create a new worker pthread */
139int sched_create_worker( void );
140
141
142
143
144
145
146void luaprocInit(void);
147void luaprocRegister(lua_State *L);
148int newProc(const char *code, int file, Ecore_Cb callback, void *data);
149
150
151/* return a process' status */
152int luaproc_get_status( luaproc lp );
153
154/* set a process' status */
155void luaproc_set_status( luaproc lp, int status );
156
157/* return a process' state */
158lua_State *luaproc_get_state( luaproc lp );
159
160/* return the number of arguments expected by a given a process */
161int luaproc_get_args( luaproc lp );
162
163/* set the number of arguments expected by a given process */
164void luaproc_set_args( luaproc lp, int n );
165
166/* create luaproc (from scheduler) */
167luaproc luaproc_create_sched( char *code );
168
169/* register luaproc's functions in a lua_State */
170void luaproc_register_funcs( lua_State *L );
171
172/* allow registering of luaproc's functions in c main prog */
173void luaproc_register_lib( lua_State *L );
174
175/* queue a luaproc that tried to send a message */
176void luaproc_queue_sender( luaproc lp );
177
178const char *sendToChannel(const char *chname, const char *message, luaproc *dst, channel *chn);
179
180/* queue a luaproc that tried to receive a message */
181void luaproc_queue_receiver( luaproc lp );
182
183/* unlock a channel's access */
184void luaproc_unlock_channel( channel chan );
185
186/* return a luaproc's channel */
187channel luaproc_get_channel( luaproc lp );
188
189/* return status (boolean) indicating if worker thread should be destroyed after luaproc execution */
190int luaproc_get_destroyworker( luaproc lp );
191
192/* return status (boolean) indicating if lua process should be recycled */
193luaproc luaproc_recycle_pop( void );
194
195/* add a lua process to the recycle list */
196int luaproc_recycle_push( luaproc lp );
197
198
199#endif