Blender V4.3
BLI_linklist_lockfree.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2018 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "MEM_guardedalloc.h"
10
12
13#include "atomic_ops.h"
14
15#include "BLI_strict_flags.h" /* Keep last. */
16
18{
19 list->dummy_node.next = NULL;
20 list->head = list->tail = &list->dummy_node;
21}
22
24{
25 if (free_func != NULL) {
26 /* NOTE: We start from a first user-added node. */
27 LockfreeLinkNode *node = list->head->next;
28 while (node != NULL) {
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 = NULL;
54 do {
55 tail_node = list->tail;
56 keep_working = (atomic_cas_ptr((void **)&tail_node->next, NULL, node) != NULL);
57 if (keep_working) {
58 atomic_cas_ptr((void **)&list->tail, tail_node, tail_node->next);
59 }
60 } while (keep_working);
61 atomic_cas_ptr((void **)&list->tail, tail_node, node);
62}
63
Read Guarded memory(de)allocation.
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)
#define NULL
static PyObject * free_func(PyObject *, PyObject *value)
Definition python.cpp:224
struct LockfreeLinkNode * next