summaryrefslogtreecommitdiffstats
path: root/testing/uwsgi/lua-lock.patch
blob: 059e8e9694ae4151453f4c80a4deaa768cb91103 (plain)
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
60
61
62
63
64
65
66
67
68
69
70
71
diff --git a/plugins/lua/lua_plugin.c b/plugins/lua/lua_plugin.c
index 6a2a2a9..692c4ef 100644
--- a/plugins/lua/lua_plugin.c
+++ b/plugins/lua/lua_plugin.c
@@ -291,6 +291,57 @@ static int uwsgi_api_req_fd(lua_State *L) {
 	return 1;
 }
 
+static int uwsgi_api_lock(lua_State *L) {
+
+	int lock_num = 0;
+
+	// the spooler cannot lock resources
+#ifdef UWSGI_SPOOLER
+	if (uwsgi.i_am_a_spooler) {
+		lua_pushstring(L, "The spooler cannot lock/unlock resources");
+		lua_error(L);
+	}
+#endif
+
+	if (lua_gettop(L) > 0) {
+		lock_num = lua_isnumber(L, 1) ? lua_tonumber(L, 1) : -1;
+		if (lock_num < 0 || lock_num > uwsgi.locks) {
+			lua_pushstring(L, "Invalid lock number");
+	    		lua_error(L);
+	  	}
+	}
+	
+	uwsgi_lock(uwsgi.user_lock[lock_num]);
+
+	return 0;
+}
+
+
+static int uwsgi_api_unlock(lua_State *L) {
+
+	int lock_num = 0;
+
+	// the spooler cannot lock resources
+#ifdef UWSGI_SPOOLER
+	if (uwsgi.i_am_a_spooler) {
+		lua_pushstring(L, "The spooler cannot lock/unlock resources");
+		lua_error(L);
+	}
+#endif
+
+	if (lua_gettop(L) > 0) {
+		lock_num = lua_isnumber(L, 1) ? lua_tonumber(L, 1) : -1;
+		if (lock_num < 0 || lock_num > uwsgi.locks) {
+			lua_pushstring(L, "Invalid lock number");
+	    		lua_error(L);
+	  	}
+	}
+	
+	uwsgi_unlock(uwsgi.user_lock[lock_num]);
+
+	return 0;
+}
+
 static const luaL_reg uwsgi_api[] = {
   {"log", uwsgi_api_log},
   {"cl", uwsgi_api_cl},
@@ -300,6 +351,8 @@ static const luaL_reg uwsgi_api[] = {
   {"cache_set", uwsgi_api_cache_set},
   {"register_signal", uwsgi_api_register_signal},
   {"register_rpc", uwsgi_api_register_rpc},
+  {"lock", uwsgi_api_lock},
+  {"unlock", uwsgi_api_unlock},
   {NULL, NULL}
 };