aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-08 17:56:39 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1994-11-08 17:56:39 -0200
commit2cf954b8ae08a9094354551ee3733f4ff8078443 (patch)
treebd6f42e34ad38802a31a135dbf446ea7e70b1427
parentaa7b1fcec4f4a8147150fcb726146800c3c6af7e (diff)
downloadlua-2cf954b8ae08a9094354551ee3733f4ff8078443.tar.gz
lua-2cf954b8ae08a9094354551ee3733f4ff8078443.tar.bz2
lua-2cf954b8ae08a9094354551ee3733f4ff8078443.zip
lock mechanism
-rw-r--r--fallback.c67
-rw-r--r--fallback.h6
-rw-r--r--lua.h6
-rw-r--r--opcode.c14
4 files changed, 88 insertions, 5 deletions
diff --git a/fallback.c b/fallback.c
index 023d11c3..68d052b3 100644
--- a/fallback.c
+++ b/fallback.c
@@ -3,11 +3,13 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_fallback="$Id: $"; 6char *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
59static Object *lockArray = NULL;
60static int lockSize = 0;
61
62int 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
98void lua_unlock (int ref)
99{
100 tag(&lockArray[ref]) = LUA_T_NIL;
101}
102
103
104Object *luaI_getlocked (int ref)
105{
106 return &lockArray[ref];
107}
108
109
110void luaI_travlock (void (*fn)(Object *))
111{
112 int i;
113 for (i=0; i<lockSize; i++)
114 fn(&lockArray[i]);
115}
116
diff --git a/fallback.h b/fallback.h
index 71080abd..b9b695fd 100644
--- a/fallback.h
+++ b/fallback.h
@@ -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
8void luaI_errorFB (void); 10void luaI_errorFB (void);
9void luaI_indexFB (void); 11void luaI_indexFB (void);
10void luaI_gettableFB (void); 12void luaI_gettableFB (void);
11void luaI_arithFB (void); 13void luaI_arithFB (void);
12void luaI_concatFB (void); 14void luaI_concatFB (void);
13void luaI_orderFB (void); 15void luaI_orderFB (void);
16Object *luaI_getlocked (int ref);
17void luaI_travlock (void (*fn)(Object *));
14 18
15#endif 19#endif
16 20
diff --git a/lua.h b/lua.h
index 11be9a6a..2a9e30b3 100644
--- a/lua.h
+++ b/lua.h
@@ -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
61int lua_type (lua_Object object); 61int lua_type (lua_Object object);
62 62
63int lua_lock (lua_Object object);
64lua_Object lua_getlocked (int ref);
65void lua_unlock (int ref);
66
63 67
64/* for lua 1.1 */ 68/* for lua 1.1 */
65 69
diff --git a/opcode.c b/opcode.c
index 0c30069b..1f6573cd 100644
--- a/opcode.c
+++ b/opcode.c
@@ -3,7 +3,7 @@
3** TecCGraf - PUC-Rio 3** TecCGraf - PUC-Rio
4*/ 4*/
5 5
6char *rcs_opcode="$Id: opcode.c,v 3.4 1994/11/07 16:34:44 roberto Exp roberto $"; 6char *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
549lua_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*/
551lua_Object lua_getglobal (char *name) 560lua_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