Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxuuu committed Nov 1, 2023
2 parents f39e783 + 1013b4b commit 4a4a67b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion port/luat_base_mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static const luaL_Reg loadedlibs[] = {
{"http", luaopen_http},
{"mqtt", luaopen_mqtt},
{"websocket", luaopen_websocket},
{"ftp", luaopen_ftp},
// {"ftp", luaopen_ftp},
{"errDump", luaopen_errdump},
#endif
{NULL, NULL}
Expand Down
2 changes: 2 additions & 0 deletions port/luat_fs_mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ void *check_cmd_args(int index)
ptr = luat_heap_malloc(len);
if (ptr == NULL)
{
fclose(f);
LLOGE("luadb镜像文件太大,内存放不下 %s", path);
return NULL;
}
Expand All @@ -238,6 +239,7 @@ void *check_cmd_args(int index)
char *tmp = luat_heap_malloc(len);
if (tmp == NULL)
{
fclose(f);
LLOGE("lua文件太大,内存放不下 %s", path);
return NULL;
}
Expand Down
23 changes: 11 additions & 12 deletions port/rtos/luat_msgbus_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
static uv_queue_item_t head;

static uv_mutex_t m;
extern uv_loop_t *main_loop;

void luat_msgbus_init(void)
{
Expand All @@ -19,6 +20,7 @@ void luat_msgbus_init(void)
}
uint32_t luat_msgbus_put(rtos_msg_t *msg, size_t timeout)
{
(void)timeout;
// LLOGD("luat_msgbus_put %p %d", msg, timeout);
uv_queue_item_t *item = luat_heap_malloc(sizeof(uv_queue_item_t) + sizeof(rtos_msg_t));
if (item == NULL)
Expand All @@ -37,10 +39,13 @@ uint32_t luat_msgbus_put(rtos_msg_t *msg, size_t timeout)
uint32_t luat_msgbus_get(rtos_msg_t *msg, size_t timeout)
{
// LLOGD("luat_msgbus_get %d", timeout);
(void)timeout;
uv_queue_item_t *item = luat_heap_malloc(sizeof(uv_queue_item_t) + sizeof(rtos_msg_t));
int ret = 0;
int ret2 = 0;
while (1)
{
ret2 = uv_run(main_loop, UV_RUN_NOWAIT);
uv_mutex_lock(&m);
ret = luat_queue_pop(&head, item);
uv_mutex_unlock(&m);
Expand All @@ -50,16 +55,10 @@ uint32_t luat_msgbus_get(rtos_msg_t *msg, size_t timeout)
luat_heap_free(item);
return 0;
}
// 读不到, 只能返回错误了
if (timeout == 0)
{
return 1;
}
if (timeout > 0 && timeout != (size_t)(-1))
{
timeout--;
}
uv_sleep(1);
if (ret2 == 0)
uv_sleep(2);
else
uv_sleep(1);
}
return 1;
}
Expand All @@ -70,6 +69,6 @@ uint32_t luat_msgbus_freesize(void)

uint8_t luat_msgbus_is_empty(void)
{
// return head.next == NULL ? 1 : 0;
return 0;
return head.next == NULL ? 1 : 0;
// return 0;
}
2 changes: 1 addition & 1 deletion port/rtos/luat_timer_pc.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ int luat_timer_stop(luat_timer_t *timer)
{
uv_mutex_lock(&timer_lock);
// LLOGD("timer stop %d", timer);
uv_timer_t *timer_req = timer->os_timer;
uv_timer_t *timer_req = (uv_timer_t *)timer->os_timer;
int ret = 0;
for (size_t i = 0; i < TIMER_ID_MAX; i++)
{
Expand Down
7 changes: 4 additions & 3 deletions src/main_mini.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ int main(int argc, char** argv) {
luat_fs_init();
luat_network_init();

uv_thread_t l_main;
// uv_thread_t l_main;
uv_timer_t t;
uv_timer_init(main_loop, &t);
uv_timer_start(&t, timer_nop, 1000, 1000);
uv_clock_gettime(UV_CLOCK_MONOTONIC, &boot_ts);
uv_thread_create(&l_main, uv_luat_main, NULL);
// uv_thread_create(&l_main, uv_luat_main, NULL);

// uv_thread_join(&l_main);
uv_run(main_loop, UV_RUN_DEFAULT);
// uv_run(main_loop, UV_RUN_DEFAULT);
uv_luat_main(NULL);

uv_loop_close(main_loop);
free(main_loop);
Expand Down
4 changes: 2 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ target("luatos-lua")
add_files(luatos.."components/network/libhttp/*.c")

-- libftp
add_includedirs(luatos.."components/network/libftp",{public = true})
add_files(luatos.."components/network/libftp/*.c")
-- add_includedirs(luatos.."components/network/libftp",{public = true})
-- add_files(luatos.."components/network/libftp/*.c")

-- websocket
add_includedirs(luatos.."components/network/websocket",{public = true})
Expand Down

0 comments on commit 4a4a67b

Please sign in to comment.