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.h161
1 files changed, 13 insertions, 148 deletions
diff --git a/LuaSL/src/LuaSL_threads.h b/LuaSL/src/LuaSL_threads.h
index b12a50d..9fc38ea 100644
--- a/LuaSL/src/LuaSL_threads.h
+++ b/LuaSL/src/LuaSL_threads.h
@@ -32,168 +32,33 @@ THE SOFTWARE.
32#ifndef __LUASL_THREADS_H__ 32#ifndef __LUASL_THREADS_H__
33#define __LUASL_THREADS_H__ 33#define __LUASL_THREADS_H__
34 34
35//#include <Ecore.h> 35/* scheduler function return constants */
36 36#define LUAPROC_SCHED_OK 0
37 37#define LUAPROC_SCHED_SOCKET_ERROR -1
38#define CHANNEL_MAX_NAME_LENGTH 255 38#define LUAPROC_SCHED_SETSOCKOPT_ERROR -2
39#define LUAPROC_SCHED_BIND_ERROR -3
40#define LUAPROC_SCHED_LISTEN_ERROR -4
41#define LUAPROC_SCHED_FORK_ERROR -5
42#define LUAPROC_SCHED_PTHREAD_ERROR -6
43#define LUAPROC_SCHED_INIT_ERROR -7
39 44
40#define CHANNEL_DESTROYED 0
41 45
42/* message channel pointer type */ 46/* message channel pointer type */
43typedef struct stchannel *channel; 47typedef struct stchannel *channel;
44 48
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 */ 49/* lua process pointer type */
82typedef struct stluaproc *luaproc; 50typedef struct stluaproc *luaproc;
83 51
84 52
85 53void luaprocInit(void);
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 54
138/* create a new worker pthread */ 55/* create a new worker pthread */
139int sched_create_worker( void ); 56int sched_create_worker( void );
140 57
141 58int newProc(const char *code, int file, void *data);
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); 59const char *sendToChannel(const char *chname, const char *message, luaproc *dst, channel *chn);
179 60
180/* queue a luaproc that tried to receive a message */ 61/* join all worker threads and exit */
181void luaproc_queue_receiver( luaproc lp ); 62void sched_join_workerthreads( void );
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 63
199#endif 64#endif