Skip to content

Commit ca33751

Browse files
committed
Add comments.
1 parent 58bc615 commit ca33751

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

samples/rust/rust_semaphore.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
//! A counting semaphore that can be used by userspace.
4+
//!
5+
//! The count is incremented by writes to the device. A write of `n` bytes results in an increment
6+
//! of `n`. It is decremented by reads; each read results in the count being decremented by 1. If
7+
//! the count is already zero, a read will block until another write increments it.
8+
//!
9+
//! This can be used in user space from the shell for example as follows (assuming a node called
10+
//! `semaphore`): `cat semaphore` decrements the count by 1 (waiting for it to become non-zero
11+
//! before decrementing); `echo -n 123 > semaphore` increments the semaphore by 3, potentially
12+
//! unblocking up to 3 blocked readers.
13+
314
#![no_std]
415
#![feature(allocator_api, global_asm)]
516

samples/rust/semaphore.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0
22

3+
// This is a C implementation of `rust_semaphore.rs`. Refer to the description
4+
// in that file for details on the device.
35
#include <linux/miscdevice.h>
46
#include <linux/module.h>
57
#include <linux/fs.h>

0 commit comments

Comments
 (0)