Re: [PATCH 1/4] input: Introduce buflock, a one-to-many circular buffer mechanism

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

 



>> +#define buflock_write(bw, buf, size, item)				\
>> +	do {								\
>> +		bw.next_head = (bw.head + 1) & ((size) - 1);		\
>> +		smp_wmb();						\
> 
> Why do we need the write barrier here?

I believe my first answer to this question was foggy indeed, so allow me to go
again, with a time line:

Scenario 1, correct write order:

writer              store_next_head   store_buf        store_head
reader  load_head   load_buf       load_next_head

Result: head != next_head, incoherent read detected

Scenario 2, incorrect write order:

writer              store_buf         store_next_head  store_head
reader  load_head   load_buf       load_next_head

Result: head == next_head, incoherent read not detected

Based on the assumption that scenario 2 could happen if the smp_wmb() is not
present, the barrier is needed.

Henrik
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media Devel]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Linux Wireless Networking]     [Linux Omap]

  Powered by Linux