1 ---------------------------------
5 ---------------------------------
9 local
ffi = require
"ffi"
10 local stp = require
"StackTracePlus"
15 struct lock* make_lock();
16 void lock_lock(
struct lock* lock);
17 void lock_unlock(
struct lock* lock);
18 uint32_t lock_try_lock(
struct lock* lock);
19 uint32_t lock_try_lock_for(
struct lock* lock, uint32_t us);
35 function lock:unlock()
39 --- Try to acquire the lock, blocking for max <timeout> microseconds.
40 --- This function does not block if timeout is <= 0.
41 --- This function may fail spuriously, i.e. return early or fail to acquire the lock.
42 --- @param timeout max time to wait in us
43 --- @returns true if the lock was acquired, false otherwise
45 return C.lock_try_lock_for(self, timeout) == 1
48 --- Wrap a function call in lock/unlock calls.
49 --- Calling this is equivalent to the following pseudo-code:
58 --- @param func the
function to call
59 --- @param ... arguments passed to the
function
60 function lock:
__call(func, ...)
62 local ok, err = xpcall(func, function(err)
63 return stp.stacktrace(err)
67 -- FIXME: this output is going to be ugly because it will output the local err as well :>
68 error("caught error in lock-wrapped call, inner error: " .. err, 2)
72 ffi.metatype("struct lock", lock)
local ffi
low-level dpdk wrapper
function lock tryLock(timeout)
Try to acquire the lock, blocking for max <timeout> microseconds.
function lock __call(func,...)
Wrap a function call in lock/unlock calls.
local mod
high-level dpdk wrapper