kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* ACCESS_ONCE usage inside llist_add_batch function
@ 2015-02-28 20:12 Cihangir Akturk
  2015-03-03  6:21 ` John de la Garza
  2015-03-04  8:34 ` Arun KS
  0 siblings, 2 replies; 5+ messages in thread
From: Cihangir Akturk @ 2015-02-28 20:12 UTC (permalink / raw)
  To: kernelnewbies

Reading the lib/llist.c file in the kernel sources, I came across
the llist_add_bach function defined like this;

bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
		     struct llist_head *head)
{
	struct llist_node *first;

	do {
		new_last->next = first = ACCESS_ONCE(head->first);
	} while (cmpxchg(&head->first, first, new_first) != first);

	return !first;
}

One thing bugging my mind is the ACCESS_ONCE macro. Is it really
needed here ? I mean I would write this function with ACCES_ONCE
moved outside the loop like as follows;

bool llist_add_batch(struct llist_node *new_first, struct llist_node *new_last,
		     struct llist_head *head)
{
	struct llist_node *first, *old;

	old = ACCESS_ONCE(head->first);
	for (;;) {
		first = old;
		new_last->next = old;
		old = cmpxchg(&head->first, first, new_first);
		if (old == first)
			break;
	}

	return !first;
}

I think that it may be faster to just use the return value of cmpxchg.
But I am not sure about this.

Is my understanding correct ?

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-03-04  8:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-02-28 20:12 ACCESS_ONCE usage inside llist_add_batch function Cihangir Akturk
2015-03-03  6:21 ` John de la Garza
2015-03-03  6:38   ` Chinmay V S
2015-03-04  0:41     ` Cihangir Akturk
2015-03-04  8:34 ` Arun KS

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).