[haiku-bugs] Re: [Haiku] #10786: Lack of non-volatile "atomic_*" functions breaks some GCC4 apps

  • From: "pdziepak" <trac@xxxxxxxxxxxx>
  • Date: Mon, 28 Apr 2014 19:53:33 -0000

#10786: Lack of non-volatile "atomic_*" functions breaks some GCC4 apps
----------------------------+----------------------------
   Reporter:  waddlesplash  |      Owner:  nobody
       Type:  bug           |     Status:  closed
   Priority:  normal        |  Milestone:  R1
  Component:  System        |    Version:  R1/Development
 Resolution:  invalid       |   Keywords:
 Blocked By:                |   Blocking:
Has a Patch:  0             |   Platform:  All
----------------------------+----------------------------

Comment (by pdziepak):

 That `volatile` qualifier was pointless. `atomic_*()` functions do not
 need it and it didn't help in any way when the variable has been accessed
 directly (usually, in such situation either `volatile` is not enough and a
 memory barrier is also needed or `volatile` is not needed at all).
 Moreover, in some use cases it is actually harmful, e.g. consider
 [http://cgit.haiku-os.org/haiku/tree/src/system/kernel/fs/unused_vnodes.h
 this file] and how `sNextHotVnodeIndex` is used. That variable is accessed
 concurrently by many threads each holding read lock on `sHotVnodesLock`.
 It is also sometimes accessed with write lock on `sHotVnodesLock` and in
 such case neither `atomic_*()` functions are needed nor `volatile`
 qualifier.

 In that commit I also broke binary interface of `atomic_set()` but as far
 as I know that particular function is Haiku addition. Unfortunately, it
 looks like `atomic_{add, and, or}()` have to stay the way they are now,
 which is very bad since they are much more expensive than it is often
 necessary.

--
Ticket URL: <https://dev.haiku-os.org/ticket/10786#comment:3>
Haiku <https://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: