Skip to content

Commit 90f970e

Browse files
committed
doc: make admonitions collapsible
1 parent fdf7067 commit 90f970e

File tree

3 files changed

+66
-10
lines changed

3 files changed

+66
-10
lines changed

src/r3/src/common.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,23 @@
3030
*
3131
* # Usage
3232
*
33+
* ## Normal
34+
*
3335
* <div class="admonition-follows"></div>
3436
*
3537
* > **Title:** lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
3638
* > lorem ipsum
39+
*
40+
* ## Collapsible
41+
*
42+
* <div class="admonition-follows"></div>
43+
*
44+
* > <details>
45+
* > <summary>Title</summary>
46+
* >
47+
* > lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum
48+
* >
49+
* > </details>
3750
*/
3851
.admonition-follows + blockquote {
3952
background: rgba(128, 128, 128, 0.1) !important;
@@ -44,6 +57,20 @@
4457
content: ""; display: block; margin-top: 1em;
4558
}
4659

60+
.admonition-follows + blockquote summary {
61+
cursor: pointer;
62+
will-change: opacity;
63+
user-select: none;
64+
-webkit-user-select: none;
65+
font-weight: bold;
66+
}
67+
.admonition-follows + blockquote summary:not([open]):not(:hover) {
68+
opacity: 0.5;
69+
}
70+
.admonition-follows + blockquote summary + * {
71+
margin-top: 1em;
72+
}
73+
4774
/* Display a warning if some Cargo features are disabled. */
4875
.disabled-feature-warning > p > span:before { content: "Warning:"; font-weight: bold; }
4976
.disabled-feature-warning > p > span:after { content: " This documentation was built without a "; }
@@ -87,7 +114,7 @@ body.theme-ayu span.center img, body.theme-ayu center img {
87114
<script type="application/javascript">
88115
<!--
89116
// Monitors the current rustdoc theme and adds `.theme-NAME` to `<body>`
90-
(function () {
117+
function initThemeMonitor() {
91118
if (typeof getCurrentValue !== 'function' ||
92119
typeof switchTheme !== 'function' ||
93120
typeof getSystemValue !== 'function' ||
@@ -114,6 +141,12 @@ body.theme-ayu span.center img, body.theme-ayu center img {
114141
onApplyTheme(newTheme);
115142
originalSwitchTheme.apply(this, arguments);
116143
};
117-
})();
144+
}
145+
146+
if (document.readyState === 'interactive' || document.readyState === 'complete') {
147+
initThemeMonitor();
148+
} else {
149+
document.addEventListener('DOMContentLoaded', initThemeMonitor);
150+
}
118151
-->
119152
</script>

src/r3/src/kernel/mutex.rs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ pub enum MutexProtocol {
122122
///
123123
/// <div class="admonition-follows"></div>
124124
///
125-
/// > **Relation to Other Specifications:** This behavior is based on robust
126-
/// > mutexes from POSIX.1-2008 (`PTHREAD_MUTEX_ROBUST`) with one difference:
125+
/// > <details>
126+
/// > <summary>Relation to Other Specifications</summary>
127+
/// >
128+
/// > This behavior is based on robust mutexes from POSIX.1-2008
129+
/// > (`PTHREAD_MUTEX_ROBUST`) with one difference:
127130
/// > A mutex never falls into an irrecoverable state — [`Mutex::lock`] would
128131
/// > repeatedly return `Err(Abandoned)` until [`Mutex::mark_consistent`] is
129132
/// > called. This change reduces the internal state bits and the complexity of
@@ -141,12 +144,17 @@ pub enum MutexProtocol {
141144
/// > All of the other operating systems' behavior described above can be
142145
/// > emulated by having a per-mutex flag and performing additional tasks in the
143146
/// > API translation layer.
147+
/// >
148+
/// > </details>
144149
///
145150
/// [Win32 mutex]: https://docs.microsoft.com/en-us/windows/win32/sync/mutex-objects
146151
///
147152
/// <div class="admonition-follows"></div>
148153
///
149-
/// > **Rationale:** Every customization option brings an additional overhead.
154+
/// > <details>
155+
/// > <summary>Rationale</summary>
156+
/// >
157+
/// > Every customization option brings an additional overhead.
150158
/// > The overhead introduced by the robustness is likely to outweigh the
151159
/// > overhead to provide choices. Therefore, we decided not to add an attribute
152160
/// > to control the robustness.
@@ -162,6 +170,8 @@ pub enum MutexProtocol {
162170
/// > accessed again. To ensure this recommendation is followed correctly
163171
/// > (unless explicitly opted out), we decided to make the robustness the
164172
/// > default behavior.
173+
/// >
174+
/// > </details>
165175
///
166176
/// # Locking Protocols
167177
///
@@ -177,7 +187,9 @@ pub enum MutexProtocol {
177187
///
178188
/// <div class="admonition-follows"></div>
179189
///
180-
/// > **Relation to Other Specifications:**
190+
/// > <details>
191+
/// > <summary>Relation to Other Specifications</summary>
192+
/// >
181193
/// > POSIX supports specifying a locking protocol by
182194
/// > `pthread_mutexattr_setprotocol`. The following protocols are supported:
183195
/// > `PTHREAD_PRIO_NONE` (none), `PTHREAD_PRIO_INHERIT`
@@ -228,12 +240,16 @@ pub enum MutexProtocol {
228240
/// > - The **Lower Priority** column indicates whether an owning task's
229241
/// > priority may be lowered whenever it unlocks a mutex or only when it
230242
/// > unlocks the last mutex held.
243+
/// >
244+
/// > </details>
231245
///
232246
/// [the priority inheritance protocol]: https://en.wikipedia.org/wiki/Priority_inheritance
233247
///
234248
/// <div class="admonition-follows"></div>
235249
///
236-
/// > **Rationale:**
250+
/// > <details>
251+
/// > <summary>Rationale</summary>
252+
/// >
237253
/// > There are numerous reasons that led to the decision not to implement the
238254
/// > priority inheritance protocol.
239255
/// >
@@ -278,6 +294,8 @@ pub enum MutexProtocol {
278294
/// >
279295
/// > We decided to restrict the unlocking order to a lock-reverse order to
280296
/// > minimize the cost of maintaining the list of mutexes held by a task.
297+
/// >
298+
/// > </details>
281299
///
282300
#[doc(include = "../common.md")]
283301
#[repr(transparent)]

src/r3/src/lib.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ Like a lock guard of a mutex, CPU Lock can be thought of as something to be “o
261261

262262
<div class="admonition-follows"></div>
263263

264-
> **Relation to Other Specifications:** Inspired from [the μITRON4.0 specification](http://www.ertl.jp/ITRON/SPEC/mitron4-e.html). CPU Lock and Priority Boost correspond to a CPU locked state and a dispatching state from μITRON4.0, respectively. In contrast to this specification, both concepts are denoted by proper nouns in the R3 RTOS. This means phrases like “when the CPU is locked” are not allowed.
264+
> **Relation to Other Specifications:** Inspired from the μITRON4.0 specification. CPU Lock and Priority Boost correspond to a CPU locked state and a dispatching state from μITRON4.0, respectively. In contrast to this specification, both concepts are denoted by proper nouns in the R3 RTOS. This means phrases like “when the CPU is locked” are not allowed.
265265
>
266266
> CPU Lock corresponds to `SuspendOSInterrupts` and `ResumeOSInterrupts` from the OSEK/VDX specification.
267267
@@ -294,7 +294,7 @@ A **task** ([`Task`]) is the kernel object that can create a thread whose execut
294294

295295
<div class="admonition-follows"></div>
296296

297-
> **Relation to Other Specifications:** Not many kernel designs use the word “thread” to describe the concept that applies to both of interrupts and tasks (one notable exception being [TI-RTOS]), most likely because threads are used to refer to a specific concept in general-purpose operating systems, or they are simply considered synonymous with tasks. For example, the closest concept in [the μITRON4.0 specification](http://www.ertl.jp/ITRON/SPEC/mitron4-e.html) is *processing units*. Despite that, it was decided that “thread” was an appropriate term to refer to this concept. The primary factors that drove this decision include: (1) the need for a conceptual entity that can “own” locks, and (2) that this concept is important for discussing thread safety without substituting every mention of “thread” with “task or interrupt handler”.
297+
> **Relation to Other Specifications:** Not many kernel designs use the word “thread” to describe the concept that applies to both of interrupts and tasks (one notable exception being [TI-RTOS]), most likely because threads are used to refer to a specific concept in general-purpose operating systems, or they are simply considered synonymous with tasks. For example, the closest concept in the μITRON4.0 specification is *processing units*. Despite that, it was decided that “thread” was an appropriate term to refer to this concept. The primary factors that drove this decision include: (1) the need for a conceptual entity that can “own” locks, and (2) that this concept is important for discussing thread safety without substituting every mention of “thread” with “task or interrupt handler”.
298298
299299
[TI-RTOS]: http://software-dl.ti.com/lprf/simplelink_cc13x0_sdk/1_30_00_06/exports/docs/ti154stack/ti154stack-sdg/ti154stack-sdg/tirtos/rtos-overview.html
300300

@@ -388,7 +388,10 @@ The kernel expects that timer interrupts are handled in a timely manner. The res
388388

389389
<div class="admonition-follows"></div>
390390

391-
> **Relation to Other Specifications:** There are many major design choices when it comes to kernel timing and timed APIs, and they are quite diverse between operating system or kernel specifications. The following list shows some of them:
391+
> <details>
392+
> <summary>Relation to Other Specifications</summary>
393+
>
394+
> There are many major design choices when it comes to kernel timing and timed APIs, and they are quite diverse between operating system or kernel specifications. The following list shows some of them:
392395
>
393396
> 1. *What time unit does the application-facing API use?* In embedded operating systems, it's very common to expose internal ticks and provide C macros to convert real time values into ticks. The conversion is prone to unexpected rounding and integer overflow, and this sort of error is easy to go unnoticed. (For instance, `pdMS_TO_TICKS` from FreeRTOS uses `uint32_t` for intermediate value calculation, and `gcc` won't report overflow even with `-Wall` because `uint32_t` is defined to exhibit a wrap-around behavior. `z_tmcvt` from Zephyr doesn't detect overflow.) Even if it could be detected statically (which is never true for dynamically calculated values), the range of real time values that doesn't cause overflow varies between target systems, harming the portability of software components written for the operating system (how often this cause a problem is debatable).
394397
>
@@ -432,6 +435,8 @@ The kernel expects that timer interrupts are handled in a timely manner. The res
432435
> | [μITRON4.0] | unspecified | N/A | no | no | unspecified bits | N/A |
433436
> | μT-Kernel 3.0 | milli- or micro-seconds | ? | no | no | 32 or 64 bits | ? |
434437
> | **R3** | microseconds | fixed, microseconds | yes | no | 31 bits | 32 bits |
438+
>
439+
> </details>
435440
436441
[μITRON4.0]: http://www.ertl.jp/ITRON/SPEC/mitron4-e.html
437442
[AUTOSAR OS 4.3.1]: https://www.autosar.org/fileadmin/user_upload/standards/classic/4-3/AUTOSAR_SWS_OS.pdf

0 commit comments

Comments
 (0)