1 ---------------------------------
5 ---------------------------------
9 local memory = require
"memory"
10 local
ffi = require
"ffi"
11 local serpent = require
"Serpent"
12 local dpdk = require
"dpdk"
16 struct spsc_ptr_queue { };
18 struct spsc_ptr_queue* make_pipe();
19 void enqueue(
struct spsc_ptr_queue* queue,
void* data);
20 void* try_dequeue(
struct spsc_ptr_queue* queue);
21 void* peek(
struct spsc_ptr_queue* queue);
22 uint8_t pop(
struct spsc_ptr_queue* queue);
23 size_t count(
struct spsc_ptr_queue* queue);
30 local slowPipe =
mod.slowPipe
31 slowPipe.__index = slowPipe
33 --- Create a
new slow pipe.
34 --- A pipe can only be used by exactly two tasks: a single reader and a single writer.
35 --- Slow pipes are called slow pipe because they are slow (duh).
36 --- Any objects passed to it will be *serialized* as strings.
37 --- This means that it supports arbitrary Lua objects following MoonGens usual serialization rules.
38 --- Use a
'fast pipe' if you need fast inter-task communication. Fast pipes are restricted to LuaJIT FFI objects.
45 function slowPipe:send(...)
46 local vals = serpent.
dump({ ... })
47 local buf = memory.alloc(
"char*", #vals + 1)
49 C.enqueue(
self.pipe, buf)
54 local buf = C.try_dequeue(self.pipe)
56 local result = loadstring(
ffi.
string(buf))()
58 return unpackAll(result)
68 function slowPipe:
recv()
69 local function loop(...)
79 function slowPipe:count()
80 return tonumber(C.count(self.pipe))
83 function slowPipe:__serialize()
84 return "require'pipe'; return " .. serpent.addMt(serpent.dumpRaw(self), "require('pipe').slowPipe"), true
88 function
mod:newFastPipe()
function rxQueue recv(bufArray)
Receive packets from a rx queue.
local ffi
low-level dpdk wrapper
function rxQueue tryRecv(bufArray, maxWait)
Receive packets from a rx queue with a timeout.
function mod free(buf)
Free off-heap allocated object.
function pkt dump(bytes)
Dumps the packet data cast to the best fitting packet struct.
function mod sleepMicros(t)
Delay by t microseconds.
function mod newSlowPipe()
Create a new slow pipe.
local mod
high-level dpdk wrapper