[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Memory address alignment and atomic operations.
Hello.
I want to use something like RCU (read copy update).
I want to "read a one-way linked list without a lock"
and "add to the tail of the list".
1: typedef struct foo {
2: struct foo *next;
3: char c;
4: int i;
5: } FOO;
6:
7: static FOO first = { NULL, 0, 0 };
8:
9: void add_tail(FOO *next) {
10: static spinlock_t lock = SPIN_LOCK_UNLOCKED;
11: FOO *f = &first;
12: spin_lock(&lock);
13: while (f->next) f = f->next;
14: next->next = NULL;
15: wmb();
16: f->next = next;
17: spin_unlock(&lock);
18: }
And I want to confirm some requirements for above code work properly.
(1) Is "first" always located as &first % sizeof(int) == 0 ?
(2) Is "first.i" always located as &first.i % sizeof(int) == 0 ?
(Do I need to use #pragma ?)
(3) Are there more requirements other than the following two
for atomic read/write operations ?
#1: 1 <= sizeof(var1) <= sizeof(int)
#2: &var1 % sizeof(int) == 0
#3: (Please mention if any.)
Regards.
--
Tetsuo Handa
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/