Files
ViperOS/vpsdk/process.vp
T
TermiNexus bb82c2fe75 fix(desk)!: 事件环改为单环+按 pid 过滤,并补 getpid(S3d 前置)
缺陷:原设计把事件环按 win_id 索引,但建窗答复 CREATED 必须在 app 知道 win_id 之前送达 —— 按 win_id 索引物理上不可能送达。改为**单一事件环**,每条事件带目标 pid,由 app 用自己的 pid 过滤(与内核旧接口 poll_event(buf, caller_pid) 同口径)。

DeskMsg 增 pid 字段(ring_push/ring_pop 同步搬运,漏搬则事件全被当成 pid=0);desk_evt_ring_off() 去掉 win_id 参数;desk_format 只初始化一个事件环;服务端 push_event 从窗口槽取 pid、建窗答复走新增的 push_event_pid(此时槽里还没有 pid)。

新增 GETPID(Linux 号 39,此前是"留空"项,现在真正实现):内核 GETPID() 返回 process.current(),SDK 侧 process.get_pid()。app 需要它才能过滤自己的窗口事件。
2026-10-16 18:58:43 +08:00

74 lines
2.0 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from . import syscall as syscall
def exit(code: int):
syscall._syscall1(uint64(syscall.Syscall.EXIT), uint64(code))
def thread_exit():
"""当前用户线程显式退出:内核回收其用户栈并标记线程结束(不返回)。"""
syscall._syscall0(uint64(syscall.Syscall.THREAD_EXIT))
def yield_cpu():
syscall._syscall2(uint64(syscall.Syscall.WAIT_WINDOW), uint64(0), uint64(2))
def get_pid() -> int:
"""当前进程 pid(getpid)。/dev/desk 的事件按 pid 过滤,建窗前就要拿到它。"""
return int(syscall._syscall0(uint64(syscall.Syscall.GETPID)))
def spawn(path: const str, blocking: int = 0) -> int:
return int(syscall._syscall2(uint64(syscall.Syscall.SPAWN), uint64(path), uint64(blocking)))
def thread_create(func: rawptr, arg: rawptr = None) -> int:
return int(syscall._syscall2(uint64(syscall.Syscall.THREAD_CREATE), uint64(func), uint64(arg)))
class Thread:
_tid: int
_func: rawptr
_arg: rawptr
_running: int
def __init__(self, func: rawptr, arg: rawptr = None):
self._func = func
self._arg = arg
self._tid = -1
self._running = 0
def start(self) -> int:
if self._running: return -1
self._tid = thread_create(self._func, self._arg)
if self._tid < 0: return -1
self._running = 1
return 0
def is_alive(self) -> int:
return self._running
def get_tid(self) -> int:
return self._tid
class Process:
_pid: int
_path: [128]char
def __init__(self, path: const str):
self._pid = -1
i: int = 0
for ch in path:
if i >= 127: break
self._path[i] = ch
i += 1
self._path[i] = 0
def start(self) -> int:
self._pid = spawn(&self._path[0], 0)
return self._pid
def start_blocking(self) -> int:
self._pid = spawn(&self._path[0], 1)
return self._pid
def get_pid(self) -> int:
return self._pid