Blender V5.3
BLI_linklist_lockfree.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
10
11#include "atomic_ops.h"
12
13#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
14
15namespace blender {
16
18{
19 list->dummy_node.next = nullptr;
20 list->head = list->tail = &list->dummy_node;
21}
22
24{
25 if (free_func != nullptr) {
26 /* NOTE: We start from a first user-added node. */
27 LockfreeLinkNode *node = list->head->next;
28 while (node != nullptr) {
29 LockfreeLinkNode *node_next = node->next;
30 free_func(node);
31 node = node_next;
32 }
33 }
34}
35
41
43{
44 /* Based on:
45 *
46 * John D. Valois
47 * Implementing Lock-Free Queues
48 *
49 * http://people.csail.mit.edu/bushl2/rpi/portfolio/lockfree-grape/documents/lock-free-linked-lists.pdf
50 */
51 bool keep_working;
52 LockfreeLinkNode *tail_node;
53 node->next = nullptr;
54 do {
55 tail_node = list->tail;
56 keep_working = (atomic_cas_ptr(reinterpret_cast<void **>(&tail_node->next), nullptr, node) !=
57 nullptr);
58 if (keep_working) {
59 atomic_cas_ptr(reinterpret_cast<void **>(&list->tail), tail_node, tail_node->next);
60 }
61 } while (keep_working);
62 atomic_cas_ptr(reinterpret_cast<void **>(&list->tail), tail_node, node);
63}
64
69
70} // namespace blender
Provides wrapper around system-specific atomic primitives, and some extensions (faked-atomic operatio...
ATOMIC_INLINE void * atomic_cas_ptr(void **v, void *old, void *_new)
BMesh Iterators.
void BLI_linklist_lockfree_init(LockfreeLinkList *list)
void BLI_linklist_lockfree_free(LockfreeLinkList *list, LockfreeeLinkNodeFreeFP free_func)
void(*) LockfreeeLinkNodeFreeFP(void *link)
void BLI_linklist_lockfree_insert(LockfreeLinkList *list, LockfreeLinkNode *node)
LockfreeLinkNode * BLI_linklist_lockfree_begin(LockfreeLinkList *list)
void BLI_linklist_lockfree_clear(LockfreeLinkList *list, LockfreeeLinkNodeFreeFP free_func)
struct LockfreeLinkNode * next