[haiku-bugs] Re: [Haiku] #11121: Set return value of atomic_get_and_set to prevent attempting to acquire spinlock twice

  • From: "pulkomandy" <trac@xxxxxxxxxxxx>
  • Date: Tue, 12 Aug 2014 15:14:53 -0000

#11121: Set return value of atomic_get_and_set to prevent attempting to acquire
spinlock twice
----------------------------------+----------------------------
   Reporter:  arvindsraj          |      Owner:  axeld
       Type:  bug                 |     Status:  new
   Priority:  normal              |  Milestone:  R1
  Component:  System/Boot Loader  |    Version:  R1/Development
 Resolution:                      |   Keywords:  gsoc2014
 Blocked By:                      |   Blocking:
Has a Patch:  1                   |   Platform:  arm
----------------------------------+----------------------------

Comment (by pulkomandy):

 pdziepak proposed a C++ implementation of this, which could be used in a
 cross platform way:
 {{{
 int32_t atomic_get_and_set(int32_t* ptr, int32_t value)
 {
     auto& obj = *reinterpret_cast<std::atomic<int32_t>*>(ptr);
     return obj.exchange(value);
 }
 }}}

 This would make things work for all platforms, however it uses the C++11
 std::atomic so we have to keep the current implementation at least for
 x86_gcc2. But it would be best to have all gcc4 platforms use this.

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

Other related posts: