source: mainline/uspace/lib/c/include/rcu.h@ 889cdb1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 889cdb1 was b1834a01, checked in by Jakub Jermar <jakub@…>, 7 years ago

Categorize the remaining orphan doxygroups

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/*
2 * Copyright (c) 2012 Adam Hraska
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libc
30 * @{
31 */
32/**
33 * @file
34 */
35
36#ifndef LIBURCU_RCU_H_
37#define LIBURCU_RCU_H_
38
39#include <barrier.h>
40#include <stdbool.h>
41
42/** Use to assign a pointer to newly initialized data to a rcu reader
43 * accessible pointer.
44 *
45 * Example:
46 * @code
47 * typedef struct exam {
48 * struct exam *next;
49 * int grade;
50 * } exam_t;
51 *
52 * exam_t *exam_list;
53 * // ..
54 *
55 * // Insert at the beginning of the list.
56 * exam_t *my_exam = malloc(sizeof(exam_t));
57 * my_exam->grade = 5;
58 * my_exam->next = exam_list;
59 * rcu_assign(exam_list, my_exam);
60 *
61 * // Changes properly propagate. Every reader either sees
62 * // the old version of exam_list or the new version with
63 * // the fully initialized my_exam.
64 * rcu_synchronize();
65 * // Now we can be sure every reader sees my_exam.
66 *
67 * @endcode
68 */
69#define rcu_assign(ptr, value) \
70 do { \
71 memory_barrier(); \
72 (ptr) = (value); \
73 } while (0)
74
75/** Use to access RCU protected data in a reader section.
76 *
77 * Example:
78 * @code
79 * exam_t *exam_list;
80 * // ...
81 *
82 * rcu_read_lock();
83 * exam_t *first_exam = rcu_access(exam_list);
84 * // We can now safely use first_exam, it won't change
85 * // under us while we're using it.
86 *
87 * // ..
88 * rcu_read_unlock();
89 * @endcode
90 */
91#define rcu_access(ptr) ACCESS_ONCE(ptr)
92
93extern void rcu_register_fibril(void);
94extern void rcu_deregister_fibril(void);
95
96extern void rcu_read_lock(void);
97extern void rcu_read_unlock(void);
98
99extern bool rcu_read_locked(void);
100
101extern void rcu_synchronize(void);
102
103#endif
104
105/** @}
106 */
Note: See TracBrowser for help on using the repository browser.