Skip to contentSkip to conversation

kernel: Provide READ_ONCE and ASSIGN_ONCE

PATCH George Spelvin 2 participants 3 messages Dec 5, 2014 Generic include/asm header files

lore
Share & tools
lore
#0 lore raw

Review

Quoted 5 lines
(quoted diff) +5 -0
+#define READ_ONCE(p) \
+	 typeof(p) __val; __read_once_size(&p, &__val, sizeof(__val)); __val; })
+
+#define ASSIGN_ONCE(val, p) \
+	({ typeof(p) __val; __val = val; __assign_once_size(&p, &__val, sizeof(__val)); __val; })

Minor style nit: is it necessary to name a non-pointer variable "p"? I expect typeof(p) to be a pointer type.

(The other fun style question, which is a lot less minor, is whether ASSIGN_ONCE should be (src,dst) as above, or (dst,src) like = and <string.h>.)

#1 lore raw

Am 05.12.2014 um 03:12 schrieb George Spelvin:

Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+#define READ_ONCE(p) \
+	 typeof(p) __val; __read_once_size(&p, &__val, sizeof(__val)); __val; })
+
+#define ASSIGN_ONCE(val, p) \
+	({ typeof(p) __val; __val = val; __assign_once_size(&p, &__val, sizeof(__val)); __val; })

Minor style nit: is it necessary to name a non-pointer variable "p"? I expect typeof(p) to be a pointer type.

v might be better.

Quoted 4 lines

(The other fun style question, which is a lot less minor, is whether ASSIGN_ONCE should be (src,dst) as above, or (dst,src) like = and <string.h>.)

I tend to prefer dst, src, but Linus used src, dst in his proposal - so I used that.

#2 lore raw
Quoted 4 lines
Quoted 2 lines

Minor style nit: is it necessary to name a non-pointer variable "p"? I expect typeof(p) to be a pointer type.

v might be better.

The current ACCESS_ONCE uses x. I also considered "var" and "mem".

Quoted 6 lines
Quoted 3 lines

(The other fun style question, which is a lot less minor, is whether ASSIGN_ONCE should be (src,dst) as above, or (dst,src) like = and <string.h>.)

I tend to prefer dst, src, but Linus used src, dst in his proposal - so I used that.

The question is, does Linus actually care (hey, Linus, do you?), or was that just a thoughtless part of a discussion about semantics?

Because if you prefer it too, there are arguments... There are plenty of "store" operations with (src, dst) arguments, because the focus is on the value being stored, so it comes first.

But the name "assign" almost always refers to the ":=" operation, with the focus more on the destination.

(Now you have me thinking about German grammar and how the destination can be identified by the dative "dem". But even though German depends on word order less than English, normally the dative comes first.)