- 本文写于2021年6月末,可能官方文档会继续更新,因此不能保证在将来本文依然对大家有帮助。
- 英文原文使用了非常长的定语从句,由于能力有限,尽量拆分为小段句子,并尽量能让中文读起来顺畅。
- 尽量保留专业术语&词汇,以免引起二义性。
- 由于目前对 Fuchsia 和 Zircon 不熟悉,难免有翻译失误的地方,欢迎斧正。
- 一边翻译一边学习,暂时不能理解的地方留了 TODO,争取以后补上。对暂时不知如何翻译的单词会用【 xxx 】做翻译参考。
- 上班996,下班有空做翻译,不能保证更新速度。
- 谢绝转载
- 谢绝转载
- 谢绝转载
介绍 | Introduction
A signal is a single bit of information that waitable zircon kernel objects expose to applications. Each object can expose one or more signals, most of which are specific to the type of object.
For example, the signal ZX_CHANNEL_READABLE indicates “this channel endpoint has messages to read”, and ZX_PROCESS_TERMINATED indicates “this process stopped running.”
The signals for an object are stored in a uint32 bitmask, and their values (which are object-specific) are defined in the headerzircon/types.h. The typedef zx_signals_t is used to refer to signal bitmasks in syscalls and other APIs.
Most objects are waitable. Ports are an example of a non-waitable object.
Signal 是单 bit 位的信息,由可等待的 zircon kernel object 暴露给应用。每个 object 都可以暴露一个或多个 signal ,大部分都针对特定的 object 类型。
例如, ZX_CHANNEL_READABLE 表示“该 channel 终端有消息可以被读取”,ZX_PROCESS_TERMINATED 表明“该 process 停止运行了”。
一个 object 的 所有 signal 都存储在 uint32 的位掩码中,它们的值(针对特定的 object)都定义在头文件 zircon/types.h 中。在 syscall 和其他 API 中,zx_signals_t 定义为 signal 的位掩码(防盗:juejin,摩卡Code)。
大部分 object 都是可等待的。Port 属于不可等待的 object 中的一种。
状态,状态改变与专用术语 | State, State Changes and their Terminology
A signal is said to be Active when its bit is 1 and Inactive when its bit is 0.
A signal is said to be Asserted when it is made Active in response to an event (even if it was already Active), and is said to be Deasserted when it is made Inactive in response to an event (even if it was already Inactive).
For example: When a message is written into a Channel endpoint, the ZX_CHANNEL_READABLE signal of the opposing endpoint is asserted (which causes that signal to become active, if it were not already active). When the last message in a Channel endpoint’s queue is read from that endpoint, the ZX_CHANNEL_READABLE signal of that endpoint is deasserted (which causes that signal to become inactive)
当一个 signal 对应的 bit 位被设置为1时,称为 Acitve 【激活】状态。设置为0时,成为 Inactive 【非激活】状态。
当一个 signal 对一个 event 产生响应被设置为 Active 时(即使它之前已经处于 Active 状态),称为 Asserted 【断言】。对一个 event 产生响应被设置为 Inactive 时(即使它之前已经处于 Inactive 状态),称为 Deasserted 【取消断言】。
例如:当消息被写入到 channel 的一个终端,在另一个终端的 ZX_CHANNEL_READABLE signal 就会被 asserted(在该 signal 还未被 actvie 的情况下,它就会被 active)。当 channel 终端队列中的最后一个消息被读取后,ZX_CHANNEL_READABLE signal 就会被 deasserted(这样该 signal 变为 inactive)。
监测信号|Observing Signals
The syscalls zx_object_wait_one(), zx_object_wait_many(), and zx_object_wait_async(), in combination with a Port, can be used to wait for specified signals on one or more objects.
If multiple threads are operating on an object, the results of these syscalls may already be out of date by the time the calling thread actually acts on them. For example, a thread waiting on a Channel for the ZX_CHANNEL_READABLE signal may wake from a zx_object_wait_one() syscall only to find that there are no pending messages, because another thread has already read it.
zx_object_wait_one( ), zx_object_wait_many( ), 与 zx_object_wait_async( ) 这些 syscall,与 Port 一起使用时,可以被用来等待一个或多个 object 的特定 signal。
如果多个 thread 操作同一个 object, 当调用 thread 真正操作它们的时候,这些 syscall 的结果可能已经超时了。比如, 一个 thread 正在等待一个 channel 的 ZX_CHANNEL_READABLE signal,当 zx_object_wait_one( ) 唤醒它的时候,channel 中已经没有任何挂起【等待被读】的消息了,因为其它 thread 已经把消息读取走了。
合成信号 | Synthetic Signals
The signal ZX_SIGNAL_HANDLE_CLOSED is a synthetic signal only exists in the results of zx_object_wait_one() or zx_object_wait_many() and indicates that a handle that was being waited upon has been been closed causing the wait operation to be aborted.
This signal can only be obtained as a result of the above two wait calls when the wait itself returns with ZX_ERR_CANCELED.
ZX_SIGNAL_HANDLE_CLOSED 是一个合成 signal,仅存在于 zx_object_wait_one( ) 和 zx_object_wait_many( ) 的返回结果中,它表明被等待的 handle 已经被关闭,且导致等待操作被中止了。
这个 signal 只能作为上面2个等待调用的返回结果,而调用本身会的返回值为 ZX_ERR_CANCELED。
注:返回结果是只 observed 变量,返回值是 zx_status_t 类型
zx_status_t zx_object_wait_one(zx_handle_t handle,
zx_signals_t signals,
zx_time_t deadline,
zx_signals_t* observed);
复制代码
用户信号 | User Signals
There are eight User Signals (ZX_USER_SIGNAL_0 through ZX_USER_SIGNAL_7), which may asserted or deasserted using the zx_object_signal() and zx_object_signal_peer() syscalls, provided the handle has the appropriate rights (ZX_RIGHT_SIGNAL or ZX_RIGHT_SIGNAL_PEER, respectively). These User Signals are always initially inactive, and are only modified by the object signal syscalls.
总共有 8 个 用户 signal (从 ZX_USER_SIGNAL_0 到 ZX_USER_SIGNAL_7),如果 handle 有合适的权限(ZX_RIGHT_SIGNAL 或 ZX_RIGHT_SIGNAL_PEER,)它们相对应的可以通过 zx_object_signal( ) 和 zx_object_signal_peer( ) 进行 asserted 或 deasserted(juejin,摩卡Code)。
这些用户 signal 初始化时都是 Inactive 状态,且仅能被 object signal 的 syscall 修改。