< prev index next >

src/hotspot/share/utilities/waitBarrier.hpp

Print this page
rev 57095 : [mq]: use
rev 57096 : [mq]: trailing_semi


  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_UTILITIES_WAITBARRIER_HPP
  26 #define SHARE_UTILITIES_WAITBARRIER_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/thread.hpp"
  30 #include "utilities/debug.hpp"

  31 #include "utilities/waitBarrier_generic.hpp"
  32 
  33 #if defined(LINUX)
  34 #include "waitBarrier_linux.hpp"
  35 typedef LinuxWaitBarrier WaitBarrierDefault;
  36 #else
  37 typedef GenericWaitBarrier WaitBarrierDefault;
  38 #endif
  39 
  40 // Platform independent WaitBarrier API.
  41 // An armed WaitBarrier prevents threads from advancing until the threads are
  42 // woken by calling disarm(). The barrier is armed by setting a non-zero value
  43 // - the tag. When the WaitBarrier is created, a thread is designated the owner
  44 // and is the thread that should arm and disarm the WaitBarrier. In debug builds
  45 // this is enforced.
  46 //
  47 // Expected Usage:
  48 //  - Arming thread:
  49 //     tag = ...;  // non-zero value
  50 //     barrier.arm(tag);


  64 //     <work>
  65 //
  66 //    - A call to wait(tag) will block if the barrier is armed with the value
  67 //      'tag'; else it will return immediately.
  68 //    - A blocked thread is eligible to execute again once the barrier is
  69 //      disarmed when disarm() has been called.
  70 //
  71 // It is a usage error to:
  72 //  - call arm on a barrier that is already armed
  73 //  - call disarm on a barrier that is not armed
  74 //  - arm with the same tag as last used
  75 // Usage errors are checked in debug builds but may be ignored otherwise.
  76 //
  77 // A primary goal of the WaitBarrier implementation is to wake all waiting
  78 // threads as fast, and as concurrently, as possible.
  79 //
  80 template <typename WaitBarrierImpl>
  81 class WaitBarrierType : public CHeapObj<mtInternal> {
  82   WaitBarrierImpl _impl;
  83 
  84   // Prevent copying and assignment of WaitBarrier instances.
  85   WaitBarrierType(const WaitBarrierDefault&);
  86   WaitBarrierType& operator=(const WaitBarrierDefault&);
  87 
  88 #ifdef ASSERT
  89   int _last_arm_tag;
  90   Thread* _owner;
  91 #endif
  92 
  93  public:
  94   WaitBarrierType(Thread* owner) : _impl() {
  95 #ifdef ASSERT
  96     _last_arm_tag = 0;
  97     _owner = owner;
  98 #endif
  99   }
 100   ~WaitBarrierType() {}
 101 
 102   // Returns implementation description.
 103   const char* description()    { return _impl.description(); }
 104 
 105   // Guarantees any thread calling wait() with same tag will be blocked.
 106   // Provides a trailing fence.




  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_UTILITIES_WAITBARRIER_HPP
  26 #define SHARE_UTILITIES_WAITBARRIER_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/thread.hpp"
  30 #include "utilities/debug.hpp"
  31 #include "utilities/macros.hpp"
  32 #include "utilities/waitBarrier_generic.hpp"
  33 
  34 #if defined(LINUX)
  35 #include "waitBarrier_linux.hpp"
  36 typedef LinuxWaitBarrier WaitBarrierDefault;
  37 #else
  38 typedef GenericWaitBarrier WaitBarrierDefault;
  39 #endif
  40 
  41 // Platform independent WaitBarrier API.
  42 // An armed WaitBarrier prevents threads from advancing until the threads are
  43 // woken by calling disarm(). The barrier is armed by setting a non-zero value
  44 // - the tag. When the WaitBarrier is created, a thread is designated the owner
  45 // and is the thread that should arm and disarm the WaitBarrier. In debug builds
  46 // this is enforced.
  47 //
  48 // Expected Usage:
  49 //  - Arming thread:
  50 //     tag = ...;  // non-zero value
  51 //     barrier.arm(tag);


  65 //     <work>
  66 //
  67 //    - A call to wait(tag) will block if the barrier is armed with the value
  68 //      'tag'; else it will return immediately.
  69 //    - A blocked thread is eligible to execute again once the barrier is
  70 //      disarmed when disarm() has been called.
  71 //
  72 // It is a usage error to:
  73 //  - call arm on a barrier that is already armed
  74 //  - call disarm on a barrier that is not armed
  75 //  - arm with the same tag as last used
  76 // Usage errors are checked in debug builds but may be ignored otherwise.
  77 //
  78 // A primary goal of the WaitBarrier implementation is to wake all waiting
  79 // threads as fast, and as concurrently, as possible.
  80 //
  81 template <typename WaitBarrierImpl>
  82 class WaitBarrierType : public CHeapObj<mtInternal> {
  83   WaitBarrierImpl _impl;
  84 
  85   NONCOPYABLE(WaitBarrierType);


  86 
  87 #ifdef ASSERT
  88   int _last_arm_tag;
  89   Thread* _owner;
  90 #endif
  91 
  92  public:
  93   WaitBarrierType(Thread* owner) : _impl() {
  94 #ifdef ASSERT
  95     _last_arm_tag = 0;
  96     _owner = owner;
  97 #endif
  98   }
  99   ~WaitBarrierType() {}
 100 
 101   // Returns implementation description.
 102   const char* description()    { return _impl.description(); }
 103 
 104   // Guarantees any thread calling wait() with same tag will be blocked.
 105   // Provides a trailing fence.


< prev index next >