aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-14 14:48:57 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2005-09-14 14:48:57 -0300
commit8dcc6bc5321f12f28c6738b68350e920983101fb (patch)
tree18ab8546e074758ba793777dfc7551e8a506995e
parent38f585d271dd666d14d589909be22aa671a80eaa (diff)
downloadlua-8dcc6bc5321f12f28c6738b68350e920983101fb.tar.gz
lua-8dcc6bc5321f12f28c6738b68350e920983101fb.tar.bz2
lua-8dcc6bc5321f12f28c6738b68350e920983101fb.zip
avoid the use of global lock
-rw-r--r--ltests.c26
-rw-r--r--ltests.h17
2 files changed, 16 insertions, 27 deletions
diff --git a/ltests.c b/ltests.c
index cd595865..7530b7f9 100644
--- a/ltests.c
+++ b/ltests.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.c,v 2.29 2005/08/26 17:32:05 roberto Exp roberto $ 2** $Id: ltests.c,v 2.30 2005/08/26 17:36:32 roberto Exp roberto $
3** Internal Module for Debugging of the Lua Implementation 3** Internal Module for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -737,7 +737,6 @@ static int loadlib (lua_State *L) {
737static int closestate (lua_State *L) { 737static int closestate (lua_State *L) {
738 lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1))); 738 lua_State *L1 = cast(lua_State *, cast(unsigned long, luaL_checknumber(L, 1)));
739 lua_close(L1); 739 lua_close(L1);
740 lua_unlock(L); /* close cannot unlock that */
741 return 0; 740 return 0;
742} 741}
743 742
@@ -1121,39 +1120,26 @@ static const struct luaL_Reg tests_funcs[] = {
1121}; 1120};
1122 1121
1123 1122
1124static void fim (void) {
1125 if (!islocked)
1126 lua_close(lua_state);
1127 lua_assert(memcontrol.numblocks == 0);
1128 lua_assert(memcontrol.total == 0);
1129}
1130
1131
1132static int l_panic (lua_State *L) {
1133 UNUSED(L);
1134 fprintf(stderr, "unable to recover; exiting\n");
1135 return 0;
1136}
1137
1138
1139int luaB_opentests (lua_State *L) { 1123int luaB_opentests (lua_State *L) {
1140 void *ud; 1124 void *ud;
1141 lua_assert(lua_getallocf(L, &ud) == debug_realloc); 1125 lua_assert(lua_getallocf(L, &ud) == debug_realloc);
1142 lua_assert(ud == cast(void *, &memcontrol)); 1126 lua_assert(ud == cast(void *, &memcontrol));
1143 lua_atpanic(L, l_panic);
1144 lua_state = L; /* keep first state to be opened */ 1127 lua_state = L; /* keep first state to be opened */
1145 luaL_register(L, "T", tests_funcs); 1128 luaL_register(L, "T", tests_funcs);
1146 atexit(fim);
1147 return 0; 1129 return 0;
1148} 1130}
1149 1131
1150 1132
1151#undef main 1133#undef main
1152int main (int argc, char *argv[]) { 1134int main (int argc, char *argv[]) {
1135 int ret;
1153 char *limit = getenv("MEMLIMIT"); 1136 char *limit = getenv("MEMLIMIT");
1154 if (limit) 1137 if (limit)
1155 memcontrol.memlimit = strtoul(limit, NULL, 10); 1138 memcontrol.memlimit = strtoul(limit, NULL, 10);
1156 return l_main(argc, argv); 1139 ret = l_main(argc, argv);
1140 lua_assert(memcontrol.numblocks == 0);
1141 lua_assert(memcontrol.total == 0);
1142 return ret;
1157} 1143}
1158 1144
1159#endif 1145#endif
diff --git a/ltests.h b/ltests.h
index f609ad69..1d054bae 100644
--- a/ltests.h
+++ b/ltests.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltests.h,v 2.14 2005/05/03 19:01:17 roberto Exp roberto $ 2** $Id: ltests.h,v 2.15 2005/06/06 13:30:25 roberto Exp roberto $
3** Internal Header for Debugging of the Lua Implementation 3** Internal Header for Debugging of the Lua Implementation
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -55,16 +55,19 @@ int lua_checkpc (lua_State *L, pCallInfo ci);
55 55
56/* test for lock/unlock */ 56/* test for lock/unlock */
57#undef luai_userstateopen 57#undef luai_userstateopen
58#undef luai_userstatethread
58#undef lua_lock 59#undef lua_lock
59#undef lua_unlock 60#undef lua_unlock
60#undef LUAI_EXTRASPACE 61#undef LUAI_EXTRASPACE
61 62
62LUAI_DATA int islocked; 63struct L_EXTRA { int lock; int *plock; };
63#define LUAI_EXTRASPACE sizeof(double) 64#define LUAI_EXTRASPACE sizeof(struct L_EXTRA)
64#define getlock(l) (*(cast(int **, l) - 1)) 65#define getlock(l) (cast(struct L_EXTRA *, l) - 1)
65#define luai_userstateopen(l) getlock(l) = &islocked; 66#define luai_userstateopen(l) \
66#define lua_lock(l) lua_assert((*getlock(l))++ == 0) 67 (getlock(l)->lock = 0, getlock(l)->plock = &(getlock(l)->lock))
67#define lua_unlock(l) lua_assert(--(*getlock(l)) == 0) 68#define luai_userstatethread(l,l1) (getlock(l1)->plock = getlock(l)->plock)
69#define lua_lock(l) lua_assert((*getlock(l)->plock)++ == 0)
70#define lua_unlock(l) lua_assert(--(*getlock(l)->plock) == 0)
68 71
69 72
70int luaB_opentests (lua_State *L); 73int luaB_opentests (lua_State *L);