-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Expand file tree
/
Copy pathlua_user.c
More file actions
59 lines (47 loc) · 1.22 KB
/
lua_user.c
File metadata and controls
59 lines (47 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <windows.h>
#include "lua.h"
#include "lua_user.h"
//todo: lock specific lua state, but then again, I usually only have one state...
static struct {
CRITICAL_SECTION LockSct;
HANDLE e;
BOOL Init;
int tid;
int lockcount;
} Gl;
void LuaLockInitial(lua_State * L)
{
// MessageBox(0, "LuaLockInitial","LuaLockInitial", MB_OK);
if (! Gl.Init)
{
/* Create a mutex */
// Gl.e=CreateEvent(NULL,FALSE, TRUE,NULL);
InitializeCriticalSection(&Gl.LockSct);
Gl.Init = TRUE;
}
}
void LuaLockFinal(lua_State * L) /* Not called by Lua. */
{
MessageBox(0, "LuaLockFinal","LuaLockFinal", MB_OK);
/* Destroy a mutex. */
if (Gl.Init)
{
// CloseHandle(Gl.e);
DeleteCriticalSection(&Gl.LockSct);
Gl.Init = FALSE;
}
}
void LuaLock(lua_State * L)
{
if (! Gl.Init)
LuaLockInitial(L);
// MessageBox(0, "LuaLock","LuaLock", MB_OK);
/* Wait for control of mutex */
EnterCriticalSection(&Gl.LockSct);
}
void LuaUnlock(lua_State * L)
{
// MessageBox(0, "LuaUnlock","LuaUnlock", MB_OK);
/* Release control of mutex */
LeaveCriticalSection(&Gl.LockSct);
}