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 /libraries/luaproc/channel.c | |
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 '')
-rw-r--r-- | libraries/luaproc/channel.c | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/libraries/luaproc/channel.c b/libraries/luaproc/channel.c deleted file mode 100644 index ef4ab4b..0000000 --- a/libraries/luaproc/channel.c +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | /*************************************************** | ||
2 | |||
3 | Copyright 2008 Alexandre Skyrme, Noemi Rodriguez, Roberto Ierusalimschy | ||
4 | |||
5 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
6 | of this software and associated documentation files (the "Software"), to deal | ||
7 | in the Software without restriction, including without limitation the rights | ||
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
9 | copies of the Software, and to permit persons to whom the Software is | ||
10 | furnished to do so, subject to the following conditions: | ||
11 | |||
12 | The above copyright notice and this permission notice shall be included in | ||
13 | all copies or substantial portions of the Software. | ||
14 | |||
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
21 | THE SOFTWARE. | ||
22 | |||
23 | ***************************************************** | ||
24 | |||
25 | [channel.c] | ||
26 | |||
27 | ****************************************************/ | ||
28 | |||
29 | #include <stdio.h> | ||
30 | #include <stdlib.h> | ||
31 | #include <string.h> | ||
32 | #include <lua.h> | ||
33 | #include <lauxlib.h> | ||
34 | #include <lualib.h> | ||
35 | |||
36 | #include "channel.h" | ||
37 | #include "list.h" | ||
38 | |||
39 | /* global channel lua_State mutex */ | ||
40 | pthread_mutex_t mutex_channel_lstate = PTHREAD_MUTEX_INITIALIZER; | ||
41 | |||
42 | /* global lua_State where channel hash table will be stored */ | ||
43 | lua_State *chanls = NULL; | ||
44 | |||
45 | /* message channel */ | ||
46 | struct stchannel { | ||
47 | list send; | ||
48 | list recv; | ||
49 | pthread_mutex_t *mutex; | ||
50 | pthread_cond_t *in_use; | ||
51 | }; | ||
52 | |||
53 | /* initialize channel table */ | ||
54 | void channel_init( void ) { | ||
55 | chanls = luaL_newstate(); | ||
56 | lua_newtable( chanls ); | ||
57 | lua_setglobal( chanls, "channeltb" ); | ||
58 | } | ||
59 | |||
60 | /* create new channel */ | ||
61 | channel channel_create( const char *cname ) { | ||
62 | |||
63 | channel chan; | ||
64 | |||
65 | /* get exclusive access to the channel table */ | ||
66 | pthread_mutex_lock( &mutex_channel_lstate ); | ||
67 | |||
68 | /* create a new channel */ | ||
69 | lua_getglobal( chanls, "channeltb"); | ||
70 | lua_pushstring( chanls, cname ); | ||
71 | chan = (channel )lua_newuserdata( chanls, sizeof( struct stchannel )); | ||
72 | chan->send = list_new(); | ||
73 | chan->recv = list_new(); | ||
74 | chan->mutex = (pthread_mutex_t *)malloc( sizeof( pthread_mutex_t )); | ||
75 | pthread_mutex_init( chan->mutex, NULL ); | ||
76 | chan->in_use = (pthread_cond_t *)malloc( sizeof( pthread_cond_t )); | ||
77 | pthread_cond_init( chan->in_use, NULL ); | ||
78 | lua_settable( chanls, -3 ); | ||
79 | lua_pop( chanls, 1 ); | ||
80 | |||
81 | /* let others access the channel table */ | ||
82 | pthread_mutex_unlock( &mutex_channel_lstate ); | ||
83 | |||
84 | return chan; | ||
85 | } | ||
86 | |||
87 | /* destroy a channel */ | ||
88 | int channel_destroy( channel chan, const char *chname ) { | ||
89 | |||
90 | /* get exclusive access to the channel table */ | ||
91 | pthread_mutex_lock( &mutex_channel_lstate ); | ||
92 | |||
93 | list_destroy( chan->send ); | ||
94 | list_destroy( chan->recv ); | ||
95 | |||
96 | lua_getglobal( chanls, "channeltb"); | ||
97 | lua_pushstring( chanls, chname ); | ||
98 | lua_pushnil( chanls ); | ||
99 | lua_settable( chanls, -3 ); | ||
100 | lua_pop( chanls, 1 ); | ||
101 | |||
102 | /* let others access the channel table */ | ||
103 | pthread_mutex_unlock( &mutex_channel_lstate ); | ||
104 | |||
105 | return CHANNEL_DESTROYED; | ||
106 | } | ||
107 | |||
108 | /* search for and return a channel with a given name */ | ||
109 | channel channel_search( const char *cname ) { | ||
110 | |||
111 | channel chan; | ||
112 | |||
113 | /* get exclusive access to the channel table */ | ||
114 | pthread_mutex_lock( &mutex_channel_lstate ); | ||
115 | |||
116 | /* search for channel */ | ||
117 | lua_getglobal( chanls, "channeltb"); | ||
118 | lua_getfield( chanls, -1, cname ); | ||
119 | if (( lua_type( chanls, -1 )) == LUA_TUSERDATA ) { | ||
120 | chan = (channel )lua_touserdata( chanls, -1 ); | ||
121 | } else { | ||
122 | chan = NULL; | ||
123 | } | ||
124 | lua_pop( chanls, 2 ); | ||
125 | |||
126 | /* let others access channel table */ | ||
127 | pthread_mutex_unlock( &mutex_channel_lstate ); | ||
128 | |||
129 | return chan; | ||
130 | } | ||
131 | |||
132 | /* return a channel's send queue */ | ||
133 | list channel_get_sendq( channel chan ) { | ||
134 | return chan->send; | ||
135 | } | ||
136 | |||
137 | /* return a channel's receive queue */ | ||
138 | list channel_get_recvq( channel chan ) { | ||
139 | return chan->recv; | ||
140 | } | ||
141 | |||
142 | /* return a channel's mutex */ | ||
143 | pthread_mutex_t *channel_get_mutex( channel chan ) { | ||
144 | return chan->mutex; | ||
145 | } | ||
146 | |||
147 | /* return a channel's conditional variable */ | ||
148 | pthread_cond_t *channel_get_cond( channel chan ) { | ||
149 | return chan->in_use; | ||
150 | } | ||
151 | |||