File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff line change 1
1
// SPDX-License-Identifier: GPL-2.0
2
2
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
+
3
14
#![ no_std]
4
15
#![ feature( allocator_api, global_asm) ]
5
16
Original file line number Diff line number Diff line change 1
1
// SPDX-License-Identifier: GPL-2.0
2
2
3
+ // This is a C implementation of `rust_semaphore.rs`. Refer to the description
4
+ // in that file for details on the device.
3
5
#include <linux/miscdevice.h>
4
6
#include <linux/module.h>
5
7
#include <linux/fs.h>
You can’t perform that action at this time.
0 commit comments