Skip to content

Commit fa45107

Browse files
cuiweixieagentzh
authored andcommitted
change: updated ngx.semaphore to reflect recent API changes in ngx_lua.
thanks Dejiang Zhu for the tweaks. Signed-off-by: Yichun Zhang (agentzh) <agentzh@gmail.com>
1 parent 9745219 commit fa45107

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

README.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Prerequisites
8181
=============
8282

8383
* LuaJIT 2.1 (for now, it is the v2.1 git branch in the official luajit-2.0 git repository: http://luajit.org/download.html )
84-
* [ngx_lua](https://github.com/openresty/lua-nginx-module) v0.10.1 or later.
84+
* [ngx_lua](https://github.com/openresty/lua-nginx-module) v0.10.3 or later.
8585
* [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)
8686

8787
[Back to TOC](#table-of-contents)

lib/ngx/semaphore.lua

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ local errmsg = base.get_errmsg_ptr()
3030

3131

3232
ffi.cdef[[
33-
struct ngx_http_lua_semaphore_s;
34-
typedef struct ngx_http_lua_semaphore_s ngx_http_lua_semaphore_t;
33+
struct ngx_http_lua_sema_s;
34+
typedef struct ngx_http_lua_sema_s ngx_http_lua_sema_t;
3535

36-
int ngx_http_lua_ffi_semaphore_new(ngx_http_lua_semaphore_t **psem,
36+
int ngx_http_lua_ffi_sema_new(ngx_http_lua_sema_t **psem,
3737
int n, char **errmsg);
3838

39-
int ngx_http_lua_ffi_semaphore_post(ngx_http_lua_semaphore_t *sem, int n);
39+
int ngx_http_lua_ffi_sema_post(ngx_http_lua_sema_t *sem, int n);
4040

41-
int ngx_http_lua_ffi_semaphore_count(ngx_http_lua_semaphore_t *sem);
41+
int ngx_http_lua_ffi_sema_count(ngx_http_lua_sema_t *sem);
4242

43-
int ngx_http_lua_ffi_semaphore_wait(ngx_http_request_t *r,
44-
ngx_http_lua_semaphore_t *sem, int wait_ms,
43+
int ngx_http_lua_ffi_sema_wait(ngx_http_request_t *r,
44+
ngx_http_lua_sema_t *sem, int wait_ms,
4545
unsigned char *errstr, size_t *errlen);
4646

47-
void ngx_http_lua_ffi_semaphore_gc(ngx_http_lua_semaphore_t *sem);
47+
void ngx_http_lua_ffi_sema_gc(ngx_http_lua_sema_t *sem);
4848
]]
4949

5050

51-
local psem = ffi_new("ngx_http_lua_semaphore_t *[1]")
51+
local psem = ffi_new("ngx_http_lua_sema_t *[1]")
5252

5353

5454
local _M = { version = base.version }
@@ -61,14 +61,14 @@ function _M.new(n)
6161
return error("no negative number")
6262
end
6363

64-
local ret = C.ngx_http_lua_ffi_semaphore_new(psem, n, errmsg)
64+
local ret = C.ngx_http_lua_ffi_sema_new(psem, n, errmsg)
6565
if ret == FFI_ERROR then
6666
return nil, ffi_str(errmsg[0])
6767
end
6868

6969
local sem = psem[0]
7070

71-
ffi_gc(sem, C.ngx_http_lua_ffi_semaphore_gc)
71+
ffi_gc(sem, C.ngx_http_lua_ffi_sema_gc)
7272

7373
return setmetatable({ sem = sem }, mt)
7474
end
@@ -95,8 +95,8 @@ function _M.wait(self, seconds)
9595
local errlen = get_size_ptr()
9696
errlen[0] = ERR_BUF_SIZE
9797

98-
local ret = C.ngx_http_lua_ffi_semaphore_wait(r, cdata_sem,
99-
milliseconds, err, errlen)
98+
local ret = C.ngx_http_lua_ffi_sema_wait(r, cdata_sem,
99+
milliseconds, err, errlen)
100100

101101
if ret == FFI_ERROR then
102102
return nil, ffi_str(err, errlen[0])
@@ -132,7 +132,7 @@ function _M.post(self, n)
132132
end
133133

134134
-- always return NGX_OK
135-
C.ngx_http_lua_ffi_semaphore_post(cdata_sem, num)
135+
C.ngx_http_lua_ffi_sema_post(cdata_sem, num)
136136

137137
return true
138138
end
@@ -143,7 +143,7 @@ function _M.count(self)
143143
return error("not a semaphore instance")
144144
end
145145

146-
return C.ngx_http_lua_ffi_semaphore_count(self.sem)
146+
return C.ngx_http_lua_ffi_sema_count(self.sem)
147147
end
148148

149149

lib/resty/core/base.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ local FREE_LIST_REF = 0
1717

1818
if not ngx.config
1919
or not ngx.config.ngx_lua_version
20-
or ngx.config.ngx_lua_version < 10001
20+
or ngx.config.ngx_lua_version < 10003
2121
then
22-
error("ngx_lua 0.10.1+ required")
22+
error("ngx_lua 0.10.3+ required")
2323
end
2424

2525

0 commit comments

Comments
 (0)