PatchworkOS  dbbdc99
A non-POSIX operating system.
Loading...
Searching...
No Matches
group.h
Go to the documentation of this file.
1#pragma once
2
3#include <kernel/fs/file.h>
4#include <kernel/sync/lock.h>
5#include <kernel/utils/ref.h>
6
7#include <sys/list.h>
8
9typedef struct process process_t;
10
11typedef struct group group_t;
12
13/**
14 * @brief Process groups.
15 * @defgroup kernel_proc_group Process groups
16 * @ingroup kernel_proc
17 *
18 * Process groups allow related processes to be grouped together, enabling operations such as sending
19 * notes to all processes within a group.
20 *
21 * As an example, if a user wishes to terminate a shell they most likely additionally want to terminate all
22 * child processes of that shell. By placing all such processes in the same group, a single "terminate" note
23 * can be sent to the entire group.
24 *
25 * @{
26 */
27
28/**
29 * @brief Group member structure.
30 * @struct group_member_t
31 *
32 * Stored in each process.
33 */
40
41/**
42 * @brief Process group structure.
43 * @struct group_t
44 */
45typedef struct group
46{
50} group_t;
51
52/**
53 * @brief Initializes a group member.
54 *
55 * @param member The group member to initialize.
56 * @param group A member storing the group to add the new member to, or `NULL` to create a new group.
57 * @return On success, `0`. On failure, `ERR` and `errno` is set to:
58 */
60
61/**
62 * @brief Deinitializes a group member.
63 *
64 * @param member The group member to deinitialize.
65 */
67
68/**
69 * @brief Retrieve the group of a group member.
70 *
71 * It is the responsibility of the caller to use `UNREF()` or `UNREF_DEFER()` on the returned group when it is no longer
72 * needed.
73 *
74 * @param member The group member.
75 * @return On success, a reference to the group. On failure, `NULL` and `errno` is set to:
76 * - `EINVAL`: Invalid parameters.
77 * - `ESRCH`: The member is not part of any group.
78 */
80
81/**
82 * @brief Joins a process to a specific group.
83 *
84 * If the member is already in a group it will be removed from that group first.
85 *
86 * @param group The group to join.
87 * @param member The group member of the process to add to the group.
88 */
89void group_add(group_t* group, group_member_t* member);
90
91/**
92 * @brief Removes a process from its group.
93 *
94 * If the group becomes empty after removing the process, it will be freed.
95 *
96 * @param member The group member of the process to remove from its group, or `NULL` for no-op.
97 */
98void group_remove(group_member_t* member);
99
100/**
101 * @brief Sends a note to all processes in the group of the specified member.
102 *
103 * @param member The member within the group to send the note to.
104 * @param note The note string to send.
105 * @return On success, `0`. On failure, `ERR` and `errno` is set to:
106 * - `EINVAL`: Invalid parameters.
107 * - Other values from `thread_send_note()`.
108 */
109uint64_t group_send_note(group_member_t* member, const char* note);
110
111/** @} */
group_t * group_get(group_member_t *member)
Retrieve the group of a group member.
Definition group.c:79
uint64_t group_send_note(group_member_t *member, const char *note)
Sends a note to all processes in the group of the specified member.
Definition group.c:142
void group_member_deinit(group_member_t *member)
Deinitializes a group member.
Definition group.c:74
void group_add(group_t *group, group_member_t *member)
Joins a process to a specific group.
Definition group.c:98
uint64_t group_member_init(group_member_t *member, group_member_t *group)
Initializes a group member.
Definition group.c:42
void group_remove(group_member_t *member)
Removes a process from its group.
Definition group.c:120
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
Group member structure.
Definition group.h:35
group_t * group
Definition group.h:37
list_entry_t entry
Definition group.h:36
lock_t lock
Definition group.h:38
Process group structure.
Definition group.h:46
ref_t ref
Definition group.h:47
list_t processes
Definition group.h:48
lock_t lock
Definition group.h:49
A entry in a doubly linked list.
Definition list.h:37
A doubly linked list.
Definition list.h:46
A simple ticket lock implementation.
Definition lock.h:44
Process structure.
Definition process.h:76
Reference counting structure.
Definition ref.h:52