Blender V5.0
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.h" /* IWYU pragma: keep. Keep last. */
14
16{
17 list->dummy_node.next = nullptr;
18 list->head = list->tail = &list->dummy_node;
19}
20
22{
23 if (free_func != nullptr) {
24 /* NOTE: We start from a first user-added node. */
25 LockfreeLinkNode *node = list->head->next;
26 while (node != nullptr) {
27 LockfreeLinkNode *node_next = node->next;
28 free_func(node);
29 node = node_next;
30 }
31 }
32}
33
39
41{
42 /* Based on:
43 *
44 * John D. Valois
45 * Implementing Lock-Free Queues
46 *
47 * http://people.csail.mit.edu/bushl2/rpi/portfolio/lockfree-grape/documents/lock-free-linked-lists.pdf
48 */
49 bool keep_working;
50 LockfreeLinkNode *tail_node;
51 node->next = nullptr;
52 do {
53 tail_node = list->tail;
54 keep_working = (atomic_cas_ptr((void **)&tail_node->next, nullptr, node) != nullptr);
55 if (keep_working) {
56 atomic_cas_ptr((void **)&list->tail, tail_node, tail_node->next);
57 }
58 } while (keep_working);
59 atomic_cas_ptr((void **)&list->tail, tail_node, node);
60}
61
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)
static PyObject * free_func(PyObject *, PyObject *value)
Definition python.cpp:226
struct LockfreeLinkNode * next