diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-04-22 15:00:37 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-04-22 15:00:37 -0300 |
commit | 0ef5cf22891c9d34a88ccc5d89eb0ed82b004471 (patch) | |
tree | 1a095acefa978d5a41f32ff7d0fef58a642aa66c /fallback.c | |
parent | fed9408ab51a4be5ff84450ad47d1e0cdaed97bc (diff) | |
download | lua-0ef5cf22891c9d34a88ccc5d89eb0ed82b004471.tar.gz lua-0ef5cf22891c9d34a88ccc5d89eb0ed82b004471.tar.bz2 lua-0ef5cf22891c9d34a88ccc5d89eb0ed82b004471.zip |
lock mechanism seperseded by the REFERENCE mechanism.
Diffstat (limited to 'fallback.c')
-rw-r--r-- | fallback.c | 70 |
1 files changed, 43 insertions, 27 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: fallback.c,v 1.22 1996/03/19 22:28:37 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.23 1996/03/21 16:31:32 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <string.h> | 9 | #include <string.h> |
@@ -12,6 +12,7 @@ char *rcs_fallback="$Id: fallback.c,v 1.22 1996/03/19 22:28:37 roberto Exp rober | |||
12 | #include "fallback.h" | 12 | #include "fallback.h" |
13 | #include "opcode.h" | 13 | #include "opcode.h" |
14 | #include "lua.h" | 14 | #include "lua.h" |
15 | #include "table.h" | ||
15 | 16 | ||
16 | 17 | ||
17 | static void errorFB (void); | 18 | static void errorFB (void); |
@@ -112,59 +113,74 @@ static void funcFB (void) | |||
112 | 113 | ||
113 | 114 | ||
114 | /* | 115 | /* |
115 | ** Lock routines | 116 | ** Reference routines |
116 | */ | 117 | */ |
117 | 118 | ||
118 | static Object *lockArray = NULL; | 119 | static struct ref { |
119 | static int lockSize = 0; | 120 | Object o; |
121 | enum {LOCK, HOLD, FREE, COLLECTED} status; | ||
122 | } *refArray = NULL; | ||
123 | static int refSize = 0; | ||
120 | 124 | ||
121 | int luaI_lock (Object *object) | 125 | lua_Reference luaI_ref (Object *object, int lock) |
122 | { | 126 | { |
123 | int i; | 127 | int i; |
124 | int oldSize; | 128 | int oldSize; |
125 | if (tag(object) == LUA_T_NIL) | 129 | if (tag(object) == LUA_T_NIL) |
126 | return -1; /* special lock ref for nil */ | 130 | return -1; /* special ref for nil */ |
127 | for (i=0; i<lockSize; i++) | 131 | for (i=0; i<refSize; i++) |
128 | if (tag(&lockArray[i]) == LUA_T_NIL) | 132 | if (refArray[i].status == FREE) |
129 | { | 133 | goto found; |
130 | lockArray[i] = *object; | ||
131 | return i; | ||
132 | } | ||
133 | /* no more empty spaces */ | 134 | /* no more empty spaces */ |
134 | oldSize = lockSize; | 135 | oldSize = refSize; |
135 | lockSize = growvector(&lockArray, lockSize, Object, lockEM, MAX_WORD); | 136 | refSize = growvector(&refArray, refSize, struct ref, refEM, MAX_WORD); |
136 | for (i=oldSize; i<lockSize; i++) | 137 | for (i=oldSize; i<refSize; i++) |
137 | tag(&lockArray[i]) = LUA_T_NIL; | 138 | refArray[i].status = FREE; |
138 | lockArray[oldSize] = *object; | 139 | i = oldSize; |
139 | return oldSize; | 140 | found: |
141 | refArray[i].o = *object; | ||
142 | refArray[i].status = lock ? LOCK : HOLD; | ||
143 | return i; | ||
140 | } | 144 | } |
141 | 145 | ||
142 | 146 | ||
143 | void lua_unlock (int ref) | 147 | void lua_unref (lua_Reference ref) |
144 | { | 148 | { |
145 | if (ref >= 0 && ref < lockSize) | 149 | if (ref >= 0 && ref < refSize) |
146 | tag(&lockArray[ref]) = LUA_T_NIL; | 150 | refArray[ref].status = FREE; |
147 | } | 151 | } |
148 | 152 | ||
149 | 153 | ||
150 | Object *luaI_getlocked (int ref) | 154 | Object *luaI_getref (lua_Reference ref) |
151 | { | 155 | { |
152 | static Object nul = {LUA_T_NIL, {0}}; | 156 | static Object nul = {LUA_T_NIL, {0}}; |
153 | if (ref >= 0 && ref < lockSize) | 157 | if (ref == -1) |
154 | return &lockArray[ref]; | ||
155 | else | ||
156 | return &nul; | 158 | return &nul; |
159 | if (ref >= 0 && ref < refSize && | ||
160 | (refArray[ref].status == LOCK || refArray[ref].status == HOLD)) | ||
161 | return &refArray[ref].o; | ||
162 | else | ||
163 | return NULL; | ||
157 | } | 164 | } |
158 | 165 | ||
159 | 166 | ||
160 | void luaI_travlock (int (*fn)(Object *)) | 167 | void luaI_travlock (int (*fn)(Object *)) |
161 | { | 168 | { |
162 | int i; | 169 | int i; |
163 | for (i=0; i<lockSize; i++) | 170 | for (i=0; i<refSize; i++) |
164 | fn(&lockArray[i]); | 171 | if (refArray[i].status == LOCK) |
172 | fn(&refArray[i].o); | ||
165 | } | 173 | } |
166 | 174 | ||
167 | 175 | ||
176 | void luaI_invalidaterefs (void) | ||
177 | { | ||
178 | int i; | ||
179 | for (i=0; i<refSize; i++) | ||
180 | if (refArray[i].status == HOLD && !luaI_ismarked(&refArray[i].o)) | ||
181 | refArray[i].status = COLLECTED; | ||
182 | } | ||
183 | |||
168 | char *luaI_travfallbacks (int (*fn)(Object *)) | 184 | char *luaI_travfallbacks (int (*fn)(Object *)) |
169 | { | 185 | { |
170 | int i; | 186 | int i; |