diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-08 17:08:34 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-02-08 17:08:34 -0200 |
| commit | 369c5fe3c056f80dc29a59a21535d2984c880b24 (patch) | |
| tree | d3594bad2cb9a2a7f827f32a1ec3fde9ed93dc17 | |
| parent | 7918c6cf113a2e05cd5b952588a240c268ca01a2 (diff) | |
| download | lua-369c5fe3c056f80dc29a59a21535d2984c880b24.tar.gz lua-369c5fe3c056f80dc29a59a21535d2984c880b24.tar.bz2 lua-369c5fe3c056f80dc29a59a21535d2984c880b24.zip | |
lock mechanism more robust; nil is pseudo-locked under index -1.
| -rw-r--r-- | fallback.c | 13 |
1 files changed, 9 insertions, 4 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.17 1995/10/17 14:30:05 roberto Exp roberto $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.18 1996/01/30 15:25:23 roberto Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdio.h> | 8 | #include <stdio.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -123,7 +123,7 @@ int luaI_lock (Object *object) | |||
| 123 | Word i; | 123 | Word i; |
| 124 | Word oldSize; | 124 | Word oldSize; |
| 125 | if (tag(object) == LUA_T_NIL) | 125 | if (tag(object) == LUA_T_NIL) |
| 126 | return -1; | 126 | return -1; /* special lock ref for nil */ |
| 127 | for (i=0; i<lockSize; i++) | 127 | for (i=0; i<lockSize; i++) |
| 128 | if (tag(&lockArray[i]) == LUA_T_NIL) | 128 | if (tag(&lockArray[i]) == LUA_T_NIL) |
| 129 | { | 129 | { |
| @@ -151,13 +151,18 @@ int luaI_lock (Object *object) | |||
| 151 | 151 | ||
| 152 | void lua_unlock (int ref) | 152 | void lua_unlock (int ref) |
| 153 | { | 153 | { |
| 154 | tag(&lockArray[ref]) = LUA_T_NIL; | 154 | if (ref >= 0 && ref < lockSize) |
| 155 | tag(&lockArray[ref]) = LUA_T_NIL; | ||
| 155 | } | 156 | } |
| 156 | 157 | ||
| 157 | 158 | ||
| 158 | Object *luaI_getlocked (int ref) | 159 | Object *luaI_getlocked (int ref) |
| 159 | { | 160 | { |
| 160 | return &lockArray[ref]; | 161 | static Object nul = {LUA_T_NIL, {0}}; |
| 162 | if (ref >= 0 && ref < lockSize) | ||
| 163 | return &lockArray[ref]; | ||
| 164 | else | ||
| 165 | return &nul; | ||
| 161 | } | 166 | } |
| 162 | 167 | ||
| 163 | 168 | ||
