Skip to content

Commit

Permalink
remove rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
actboy168 committed Apr 29, 2024
1 parent d613355 commit 3ca2640
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 70 deletions.
35 changes: 0 additions & 35 deletions binding/lua_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ namespace bee::lua_thread {
spinlock mutex;
};

struct rpc {
atomic_semaphore sem = atomic_semaphore(0);
void* data = nullptr;
};

static channelmgr g_channel;
static std::atomic<int> g_thread_id = -1;
static int THREADID;
Expand Down Expand Up @@ -301,28 +296,6 @@ namespace bee::lua_thread {
return 0;
}

static void rpc_metatable(lua_State* L) {}

static int lrpc_create(lua_State* L) {
auto& r = lua::newudata<rpc>(L);
lua_pushlightuserdata(L, &r);
lua_rotate(L, 1, 1);
return 2;
}

static int lrpc_wait(lua_State* L) {
auto r = lua::checklightud<struct rpc*>(L, 1);
r->sem.acquire();
return seri_unpackptr(L, r->data);
}

static int lrpc_return(lua_State* L) {
auto r = lua::checklightud<struct rpc*>(L, 1);
r->data = seri_pack(L, 1, NULL);
r->sem.release();
return 0;
}

static void init_threadid(lua_State* L) {
if (lua_rawgetp(L, LUA_REGISTRYINDEX, &THREADID) != LUA_TNIL) {
return;
Expand All @@ -343,9 +316,6 @@ namespace bee::lua_thread {
{ "reset", lreset },
{ "wait", lwait },
{ "setname", lsetname },
{ "rpc_create", lrpc_create },
{ "rpc_wait", lrpc_wait },
{ "rpc_return", lrpc_return },
{ "preload_module", lua::preload_module },
{ "id", NULL },
{ NULL, NULL },
Expand All @@ -366,9 +336,4 @@ namespace bee::lua {
static inline auto name = "bee::channel";
static inline auto metatable = bee::lua_thread::channel_metatable;
};
template <>
struct udata<lua_thread::rpc> {
static inline auto name = "bee::rpc";
static inline auto metatable = bee::lua_thread::rpc_metatable;
};
}
35 changes: 0 additions & 35 deletions test/test_thread.lua
Original file line number Diff line number Diff line change
Expand Up @@ -293,41 +293,6 @@ function test_thread:test_thread_pop()
assertNotThreadError()
end

function test_thread:test_rpc()
thread.reset()
thread.newchannel "test"
local thd = createThread [[
local thread = require "bee.thread"
local c = thread.channel "test"
local quit
local cmd = {}
function cmd.add(a, b)
return a + b
end
function cmd.exit()
quit = true
return "ok"
end
local function dispatch(context, what, ...)
thread.rpc_return(context, cmd[what](...))
return not quit
end
while dispatch(c:bpop()) do
end
]]
local c = thread.channel "test"
local function call(...)
local r, _ = thread.rpc_create()
c:push(r, ...)
return thread.rpc_wait(r)
end
lt.assertEquals(call("add", 1, 2), 3)
lt.assertEquals(call("exit"), "ok")
thread.wait(thd)
assertNotThreadError()
thread.reset()
end

function test_thread:test_sleep()
local t1 = time.monotonic()
thread.sleep(1)
Expand Down

0 comments on commit 3ca2640

Please sign in to comment.