< prev index next >

src/hotspot/share/utilities/singleWriterSynchronizer.hpp

Print this page
rev 57095 : [mq]: use
rev 57096 : [mq]: trailing_semi
   1 /*
   2  * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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  *


  38 // completion of all critical sections for the synchronizer object
  39 // that were extant when the wait was initiated.  Usage is that there
  40 // is some state that can be accessed either before or after some
  41 // change.  An accessing thread performs the access within a critical
  42 // section.  A writer thread performs the state change, and then waits
  43 // for critical sections to complete, thereby ensuring there are no
  44 // threads in a critical section that might have seen the old state.
  45 //
  46 // Generally, GlobalCounter should be used instead of this class, as
  47 // GlobalCounter has measurably better performance and doesn't have
  48 // the single writer at a time restriction.  Use this only in
  49 // situations where GlobalCounter won't work for some reason.
  50 class SingleWriterSynchronizer {
  51   volatile uint _enter;
  52   volatile uint _exit[2];
  53   volatile uint _waiting_for;
  54   Semaphore _wakeup;
  55 
  56   DEBUG_ONLY(volatile uint _writers;)
  57 
  58   // Noncopyable.
  59   SingleWriterSynchronizer(const SingleWriterSynchronizer&);
  60   SingleWriterSynchronizer& operator=(const SingleWriterSynchronizer&);
  61 
  62 public:
  63   SingleWriterSynchronizer();
  64 
  65   // Enter a critical section for this synchronizer.  Entering a
  66   // critical section never blocks.  While in a critical section, a
  67   // thread should avoid blocking, or even take a long time.  In
  68   // particular, a thread must never safepoint while in a critical
  69   // section.
  70   // Precondition: The current thread must not already be in a
  71   // critical section for this synchronizer.
  72   inline uint enter();
  73 
  74   // Exit a critical section for this synchronizer.
  75   // Precondition: enter_value must be the result of the corresponding
  76   // enter() for the critical section.
  77   inline void exit(uint enter_value);
  78 
  79   // Wait until all threads currently in a critical section for this
  80   // synchronizer have exited their critical section.  Threads that


   1 /*
   2  * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  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  *


  38 // completion of all critical sections for the synchronizer object
  39 // that were extant when the wait was initiated.  Usage is that there
  40 // is some state that can be accessed either before or after some
  41 // change.  An accessing thread performs the access within a critical
  42 // section.  A writer thread performs the state change, and then waits
  43 // for critical sections to complete, thereby ensuring there are no
  44 // threads in a critical section that might have seen the old state.
  45 //
  46 // Generally, GlobalCounter should be used instead of this class, as
  47 // GlobalCounter has measurably better performance and doesn't have
  48 // the single writer at a time restriction.  Use this only in
  49 // situations where GlobalCounter won't work for some reason.
  50 class SingleWriterSynchronizer {
  51   volatile uint _enter;
  52   volatile uint _exit[2];
  53   volatile uint _waiting_for;
  54   Semaphore _wakeup;
  55 
  56   DEBUG_ONLY(volatile uint _writers;)
  57 
  58   NONCOPYABLE(SingleWriterSynchronizer);


  59 
  60 public:
  61   SingleWriterSynchronizer();
  62 
  63   // Enter a critical section for this synchronizer.  Entering a
  64   // critical section never blocks.  While in a critical section, a
  65   // thread should avoid blocking, or even take a long time.  In
  66   // particular, a thread must never safepoint while in a critical
  67   // section.
  68   // Precondition: The current thread must not already be in a
  69   // critical section for this synchronizer.
  70   inline uint enter();
  71 
  72   // Exit a critical section for this synchronizer.
  73   // Precondition: enter_value must be the result of the corresponding
  74   // enter() for the critical section.
  75   inline void exit(uint enter_value);
  76 
  77   // Wait until all threads currently in a critical section for this
  78   // synchronizer have exited their critical section.  Threads that


< prev index next >