src/hotspot/share/utilities/waitBarrier_generic.hpp
author mr
Tue, 29 Oct 2019 13:52:04 -0700
changeset 58850 f4290bf1cc21
parent 53254 47bc06170313
permissions -rw-r--r--
8233137: runtime/ErrorHandling/VeryEarlyAssertTest.java fails after 8232080 Reviewed-by: stuefe, iignatyev, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
53254
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     1
/*
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     2
 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     4
 *
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     8
 *
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    13
 * accompanied this code).
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    14
 *
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    18
 *
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    21
 * questions.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    22
 *
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    23
 */
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    24
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    25
#ifndef SHARE_UTILITIES_WAITBARRIER_GENERIC_HPP
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    26
#define SHARE_UTILITIES_WAITBARRIER_GENERIC_HPP
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    27
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    28
#include "memory/allocation.hpp"
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    29
#include "runtime/semaphore.hpp"
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    30
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    31
// In addition to the barrier tag, it uses two counters to keep the semaphore
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    32
// count correct and not leave any late thread waiting.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    33
class GenericWaitBarrier : public CHeapObj<mtInternal> {
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    34
  volatile int _barrier_tag;
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    35
  // The number of threads waiting on or about to wait on the semaphore.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    36
  volatile int _waiters;
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    37
  // The number of threads in the wait path, before or after the tag check.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    38
  // These threads can become waiters.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    39
  volatile int _barrier_threads;
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    40
  Semaphore _sem_barrier;
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    41
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    42
  // Prevent copying and assignment of GenericWaitBarrier instances.
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    43
  GenericWaitBarrier(const GenericWaitBarrier&);
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    44
  GenericWaitBarrier& operator=(const GenericWaitBarrier&);
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    45
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    46
  int wake_if_needed();
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    47
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    48
 public:
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    49
  GenericWaitBarrier() : _barrier_tag(0), _waiters(0), _barrier_threads(0), _sem_barrier(0) {}
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    50
  ~GenericWaitBarrier() {}
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    51
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    52
  const char* description() { return "semaphore"; }
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    53
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    54
  void arm(int barrier_tag);
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    55
  void disarm();
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    56
  void wait(int barrier_tag);
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    57
};
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    58
47bc06170313 8214271: Fast primitive to wake many threads
rehn
parents:
diff changeset
    59
#endif // SHARE_UTILITIES_WAITBARRIER_GENERIC_HPP