1#include "libxr_system.hpp"
5#include "libxr_assert.hpp"
6#include "libxr_def.hpp"
8#include "libxr_type.hpp"
11#include "semaphore.hpp"
13#include "timebase.hpp"
15#include "webasm_timebase.hpp"
20 void receive_input(
const char *js_input)
25 reinterpret_cast<const uint8_t *
>(js_input), strlen(js_input));
35 auto write_fun = [](WritePort &port)
37 static uint8_t write_buff[1024];
38 WritePort::WriteInfo info;
41 if (port.queue_info_->Pop(info) != ErrorCode::OK)
46 port.queue_data_->PopBatch(write_buff, info.size);
51 for (var i = 0; i < len; i++)
53 Module.put_char(String.fromCharCode(HEAPU8[ptr + i]));
56 reinterpret_cast<uintptr_t
>(write_buff), info.size);
58 port.queue_info_->Pop(info);
60 port.UpdateStatus(
false, ErrorCode::OK, info.op, info.size);
71 auto read_fun = [](ReadPort &port)
75 if (port.queue_block_->Peek(block) != ErrorCode::OK)
77 return ErrorCode::EMPTY;
80 block.op_.MarkAsRunning();
82 if (port.queue_data_->Size() >= block.data_.size_)
84 port.queue_data_->
PopBatch(block.data_.addr_, block.data_.size_);
85 port.queue_block_->Pop();
87 port.read_size_ = block.data_.size_;
88 block.op_.UpdateStatus(
false, ErrorCode::OK);
93 return ErrorCode::EMPTY;
98 new LibXR::ReadPort(32,
static_cast<size_t>(4 * LIBXR_PRINTF_BUFFER_SIZE));
ErrorCode PushBatch(const void *data, size_t size)
批量推入多个元素 (Push multiple elements into the queue).
ErrorCode PopBatch(Data *data, size_t batch_size)
批量弹出数据 / Pops multiple elements from the queue
ReadPort class for handling read operations.
void ProcessPendingReads()
Processes pending reads.
static ReadPort * read_
Read port instance. 读取端口。
static WritePort * write_
Write port instance. 写入端口。
static TimestampMS GetMilliseconds()
获取当前时间的毫秒级时间戳。 Gets the current timestamp in milliseconds.
static void Refresh()
刷新定时任务状态 Refreshes the state of periodic tasks
static void RefreshTimerInIdle()
在空闲时刷新定时器 Refreshes the timer during idle time
WebAsmTimebase 类,用于获取 WebAssembly 系统的时间基准。
WritePort class for handling write operations.
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值
void PlatformInit()
平台初始化函数 Platform initialization function