hotspot/src/share/vm/runtime/mutex.hpp
changeset 28163 322d55d167be
parent 22551 9bf46d16dcc6
child 41710 b830f5141dbb
equal deleted inserted replaced
28023:a4075664328d 28163:322d55d167be
     1 /*
     1 /*
     2  * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1998, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
   152     _no_safepoint_check_flag    = true,
   152     _no_safepoint_check_flag    = true,
   153     _allow_vm_block_flag        = true,
   153     _allow_vm_block_flag        = true,
   154     _as_suspend_equivalent_flag = true
   154     _as_suspend_equivalent_flag = true
   155   };
   155   };
   156 
   156 
       
   157   // Locks can be acquired with or without safepoint check.
       
   158   // Monitor::lock and Monitor::lock_without_safepoint_check
       
   159   // checks these flags when acquiring a lock to ensure
       
   160   // consistent checking for each lock.
       
   161   // A few existing locks will sometimes have a safepoint check and
       
   162   // sometimes not, but these locks are set up in such a way to avoid deadlocks.
       
   163   enum SafepointCheckRequired {
       
   164     _safepoint_check_never,       // Monitors with this value will cause errors
       
   165                                   // when acquired with a safepoint check.
       
   166     _safepoint_check_sometimes,   // Certain locks are called sometimes with and
       
   167                                   // sometimes without safepoint checks. These
       
   168                                   // locks will not produce errors when locked.
       
   169     _safepoint_check_always       // Causes error if locked without a safepoint
       
   170                                   // check.
       
   171   };
       
   172 
       
   173   NOT_PRODUCT(SafepointCheckRequired _safepoint_check_required;)
       
   174 
   157   enum WaitResults {
   175   enum WaitResults {
   158     CONDVAR_EVENT,         // Wait returned because of condition variable notification
   176     CONDVAR_EVENT,         // Wait returned because of condition variable notification
   159     INTERRUPT_EVENT,       // Wait returned because waiting thread was interrupted
   177     INTERRUPT_EVENT,       // Wait returned because waiting thread was interrupted
   160     NUMBER_WAIT_RESULTS
   178     NUMBER_WAIT_RESULTS
   161   };
   179   };
   173  protected:
   191  protected:
   174    static void ClearMonitor (Monitor * m, const char* name = NULL) ;
   192    static void ClearMonitor (Monitor * m, const char* name = NULL) ;
   175    Monitor() ;
   193    Monitor() ;
   176 
   194 
   177  public:
   195  public:
   178   Monitor(int rank, const char *name, bool allow_vm_block=false);
   196   Monitor(int rank, const char *name, bool allow_vm_block = false,
       
   197           SafepointCheckRequired safepoint_check_required = _safepoint_check_always);
   179   ~Monitor();
   198   ~Monitor();
   180 
   199 
   181   // Wait until monitor is notified (or times out).
   200   // Wait until monitor is notified (or times out).
   182   // Defaults are to make safepoint checks, wait time is forever (i.e.,
   201   // Defaults are to make safepoint checks, wait time is forever (i.e.,
   183   // zero), and not a suspend-equivalent condition. Returns true if wait
   202   // zero), and not a suspend-equivalent condition. Returns true if wait
   259 // thread-specific park-unpark platform-specific primitives.
   278 // thread-specific park-unpark platform-specific primitives.
   260 
   279 
   261 
   280 
   262 class Mutex : public Monitor {      // degenerate Monitor
   281 class Mutex : public Monitor {      // degenerate Monitor
   263  public:
   282  public:
   264    Mutex (int rank, const char *name, bool allow_vm_block=false);
   283    Mutex(int rank, const char *name, bool allow_vm_block = false,
       
   284          SafepointCheckRequired safepoint_check_required = _safepoint_check_always);
   265    ~Mutex () ;
   285    ~Mutex () ;
   266  private:
   286  private:
   267    bool notify ()    { ShouldNotReachHere(); return false; }
   287    bool notify ()    { ShouldNotReachHere(); return false; }
   268    bool notify_all() { ShouldNotReachHere(); return false; }
   288    bool notify_all() { ShouldNotReachHere(); return false; }
   269    bool wait (bool no_safepoint_check, long timeout, bool as_suspend_equivalent) {
   289    bool wait (bool no_safepoint_check, long timeout, bool as_suspend_equivalent) {