diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-08 17:56:39 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-08 17:56:39 -0200 |
commit | 2cf954b8ae08a9094354551ee3733f4ff8078443 (patch) | |
tree | bd6f42e34ad38802a31a135dbf446ea7e70b1427 | |
parent | aa7b1fcec4f4a8147150fcb726146800c3c6af7e (diff) | |
download | lua-2cf954b8ae08a9094354551ee3733f4ff8078443.tar.gz lua-2cf954b8ae08a9094354551ee3733f4ff8078443.tar.bz2 lua-2cf954b8ae08a9094354551ee3733f4ff8078443.zip |
lock mechanism
-rw-r--r-- | fallback.c | 67 | ||||
-rw-r--r-- | fallback.h | 6 | ||||
-rw-r--r-- | lua.h | 6 | ||||
-rw-r--r-- | opcode.c | 14 |
4 files changed, 88 insertions, 5 deletions
@@ -3,11 +3,13 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_fallback="$Id: $"; | 6 | char *rcs_fallback="$Id: fallback.c,v 1.1 1994/11/07 15:20:56 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | ||
9 | 10 | ||
10 | #include "fallback.h" | 11 | #include "fallback.h" |
12 | #include "opcode.h" | ||
11 | #include "lua.h" | 13 | #include "lua.h" |
12 | 14 | ||
13 | 15 | ||
@@ -49,3 +51,66 @@ void luaI_orderFB (void) | |||
49 | lua_error("unexpected type at comparison"); | 51 | lua_error("unexpected type at comparison"); |
50 | } | 52 | } |
51 | 53 | ||
54 | |||
55 | /* | ||
56 | ** Lock routines | ||
57 | */ | ||
58 | |||
59 | static Object *lockArray = NULL; | ||
60 | static int lockSize = 0; | ||
61 | |||
62 | int lua_lock (lua_Object object) | ||
63 | { | ||
64 | int i; | ||
65 | int oldSize; | ||
66 | if (lua_isnil(object)) | ||
67 | return -1; | ||
68 | for (i=0; i<lockSize; i++) | ||
69 | if (tag(&lockArray[i]) == LUA_T_NIL) | ||
70 | { | ||
71 | lockArray[i] = *luaI_Address(object); | ||
72 | return i; | ||
73 | } | ||
74 | /* no more empty spaces */ | ||
75 | oldSize = lockSize; | ||
76 | if (lockArray == NULL) | ||
77 | { | ||
78 | lockSize = 10; | ||
79 | lockArray = (Object *)malloc(lockSize); | ||
80 | } | ||
81 | else | ||
82 | { | ||
83 | lockSize = 3*oldSize/2 + 5; | ||
84 | lockArray = (Object *)realloc(lockArray, lockSize); | ||
85 | } | ||
86 | if (lockArray == NULL) | ||
87 | { | ||
88 | lockSize = 0; | ||
89 | lua_error("lock - not enough memory"); | ||
90 | } | ||
91 | for (i=oldSize; i<lockSize; i++) | ||
92 | tag(&lockArray[i]) = LUA_T_NIL; | ||
93 | lockArray[oldSize] = *luaI_Address(object); | ||
94 | return oldSize; | ||
95 | } | ||
96 | |||
97 | |||
98 | void lua_unlock (int ref) | ||
99 | { | ||
100 | tag(&lockArray[ref]) = LUA_T_NIL; | ||
101 | } | ||
102 | |||
103 | |||
104 | Object *luaI_getlocked (int ref) | ||
105 | { | ||
106 | return &lockArray[ref]; | ||
107 | } | ||
108 | |||
109 | |||
110 | void luaI_travlock (void (*fn)(Object *)) | ||
111 | { | ||
112 | int i; | ||
113 | for (i=0; i<lockSize; i++) | ||
114 | fn(&lockArray[i]); | ||
115 | } | ||
116 | |||
@@ -1,16 +1,20 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: $ | 2 | ** $Id: fallback.h,v 1.1 1994/11/07 15:20:56 roberto Exp roberto $ |
3 | */ | 3 | */ |
4 | 4 | ||
5 | #ifndef fallback_h | 5 | #ifndef fallback_h |
6 | #define fallback_h | 6 | #define fallback_h |
7 | 7 | ||
8 | #include "opcode.h" | ||
9 | |||
8 | void luaI_errorFB (void); | 10 | void luaI_errorFB (void); |
9 | void luaI_indexFB (void); | 11 | void luaI_indexFB (void); |
10 | void luaI_gettableFB (void); | 12 | void luaI_gettableFB (void); |
11 | void luaI_arithFB (void); | 13 | void luaI_arithFB (void); |
12 | void luaI_concatFB (void); | 14 | void luaI_concatFB (void); |
13 | void luaI_orderFB (void); | 15 | void luaI_orderFB (void); |
16 | Object *luaI_getlocked (int ref); | ||
17 | void luaI_travlock (void (*fn)(Object *)); | ||
14 | 18 | ||
15 | #endif | 19 | #endif |
16 | 20 | ||
@@ -2,7 +2,7 @@ | |||
2 | ** LUA - Linguagem para Usuarios de Aplicacao | 2 | ** LUA - Linguagem para Usuarios de Aplicacao |
3 | ** Grupo de Tecnologia em Computacao Grafica | 3 | ** Grupo de Tecnologia em Computacao Grafica |
4 | ** TeCGraf - PUC-Rio | 4 | ** TeCGraf - PUC-Rio |
5 | ** $Id: lua.h,v 3.3 1994/11/07 16:34:44 roberto Exp $ | 5 | ** $Id: lua.h,v 3.4 1994/11/07 18:27:39 roberto Exp roberto $ |
6 | */ | 6 | */ |
7 | 7 | ||
8 | 8 | ||
@@ -60,6 +60,10 @@ lua_Object lua_getsubscript (void); | |||
60 | 60 | ||
61 | int lua_type (lua_Object object); | 61 | int lua_type (lua_Object object); |
62 | 62 | ||
63 | int lua_lock (lua_Object object); | ||
64 | lua_Object lua_getlocked (int ref); | ||
65 | void lua_unlock (int ref); | ||
66 | |||
63 | 67 | ||
64 | /* for lua 1.1 */ | 68 | /* for lua 1.1 */ |
65 | 69 | ||
@@ -3,7 +3,7 @@ | |||
3 | ** TecCGraf - PUC-Rio | 3 | ** TecCGraf - PUC-Rio |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_opcode="$Id: opcode.c,v 3.4 1994/11/07 16:34:44 roberto Exp roberto $"; | 6 | char *rcs_opcode="$Id: opcode.c,v 3.5 1994/11/07 18:27:39 roberto Exp $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |
@@ -545,14 +545,24 @@ void *lua_getuserdata (lua_Object object) | |||
545 | else return (uvalue(Address(object))); | 545 | else return (uvalue(Address(object))); |
546 | } | 546 | } |
547 | 547 | ||
548 | |||
549 | lua_Object lua_getlocked (int ref) | ||
550 | { | ||
551 | adjustC(0); | ||
552 | *(top++) = *luaI_getlocked(ref); | ||
553 | CBase++; /* incorporate object in the stack */ | ||
554 | return Ref(top-1); | ||
555 | } | ||
556 | |||
548 | /* | 557 | /* |
549 | ** Get a global object. Return the object handle or NULL on error. | 558 | ** Get a global object. Return the object handle or NULL on error. |
550 | */ | 559 | */ |
551 | lua_Object lua_getglobal (char *name) | 560 | lua_Object lua_getglobal (char *name) |
552 | { | 561 | { |
553 | int n = lua_findsymbol(name); | 562 | int n = lua_findsymbol(name); |
554 | if (n < 0) return 0; | 563 | adjustC(0); |
555 | *(top++) = s_object(n); | 564 | *(top++) = s_object(n); |
565 | CBase++; /* incorporate object in the stack */ | ||
556 | return Ref(top-1); | 566 | return Ref(top-1); |
557 | } | 567 | } |
558 | 568 | ||