ACCESS_ONCE usage inside llist_add_batch function

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 ?

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies




[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux