Skip to content

rcu-list: Fix the data-race #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rcu-list/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CFLAGS = -g
CFLAGS += -Wall
LDFLAGS += -lpthread
CFLAGS += -std=c99
# CFLAGS += -fsanitize=thread
CFLAGS += -fsanitize=thread

READER_NUM = 10
UPDATER_NUM = 1
Expand Down
17 changes: 16 additions & 1 deletion rcu-list/rculist.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#include <stddef.h>

#include "thread-rcu.h"
/* Reuse the RCU from thread-rcu */
#include "../thread-rcu/rcu.h"

#define __allow_unused __attribute__((unused))

#define container_of(ptr, type, member) \
__extension__({ \
Expand Down Expand Up @@ -63,10 +66,22 @@ static inline void list_del_rcu(struct list_head *node)
list_init_rcu(node);
}

/*
* For the write side only (i.e., it should hold the lock when we use the
* non-rcu postfix for loop API).
*/

#define list_for_each(n, head) for (n = (head)->next; n != (head); n = n->next)

#define list_for_each_from(pos, head) for (; pos != (head); pos = pos->next)

#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)

/* The read side should only use the following API. */

#define list_for_each_entry_rcu(pos, head, member) \
for (pos = list_entry_rcu((head)->next, __typeof__(*pos), member); \
&pos->member != (head); \
pos = list_entry_rcu(pos->member.next, __typeof__(*pos), member))
5 changes: 1 addition & 4 deletions rcu-list/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,12 @@ static struct test *test_alloc(int val)
static void *reader_side(void *argv)
{
struct test __allow_unused *tmp;
struct list_head *node;

rcu_init();

rcu_read_lock();

list_for_each (node, &head) {
tmp = list_entry_rcu(node, struct test, node);
}
list_for_each_entry_rcu(tmp, &head, node) {}

rcu_read_unlock();

Expand Down
218 changes: 0 additions & 218 deletions rcu-list/thread-rcu.h

This file was deleted.