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

Last change on this file since eec201d 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
RevLine 
[a82d33d]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
[b1834a01]29/** @addtogroup libc
[a82d33d]30 * @{
31 */
32/**
33 * @file
34 */
35
36#ifndef LIBURCU_RCU_H_
37#define LIBURCU_RCU_H_
38
[05882233]39#include <barrier.h>
[fd1b1ce]40#include <stdbool.h>
[a82d33d]41
[1b20da0]42/** Use to assign a pointer to newly initialized data to a rcu reader
[a82d33d]43 * accessible pointer.
[1b20da0]44 *
[a82d33d]45 * Example:
46 * @code
47 * typedef struct exam {
48 * struct exam *next;
49 * int grade;
50 * } exam_t;
[1b20da0]51 *
[a82d33d]52 * exam_t *exam_list;
53 * // ..
[1b20da0]54 *
[a82d33d]55 * // Insert at the beginning of the list.
[7473807]56 * exam_t *my_exam = malloc(sizeof(exam_t));
[a82d33d]57 * my_exam->grade = 5;
58 * my_exam->next = exam_list;
59 * rcu_assign(exam_list, my_exam);
[1b20da0]60 *
[a82d33d]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.
[1b20da0]66 *
[a82d33d]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.
[1b20da0]76 *
[a82d33d]77 * Example:
78 * @code
79 * exam_t *exam_list;
80 * // ...
[1b20da0]81 *
[a82d33d]82 * rcu_read_lock();
83 * exam_t *first_exam = rcu_access(exam_list);
[1b20da0]84 * // We can now safely use first_exam, it won't change
[a82d33d]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
[a2f42e5]99extern bool rcu_read_locked(void);
100
[3679f51a]101extern void rcu_synchronize(void);
[a82d33d]102
103#endif
104
105/** @}
106 */
Note: See TracBrowser for help on using the repository browser.