hotspot/src/os/bsd/vm/os_bsd.hpp
changeset 15855 2ac9ebea17f3
parent 14286 ec9e76cd402f
child 18025 b7bcf7497f93
equal deleted inserted replaced
15800:55dcad6bc1a5 15855:2ac9ebea17f3
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2013, 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.
   149   // Bsd suspend/resume support - this helper is a shadow of its former
   149   // Bsd suspend/resume support - this helper is a shadow of its former
   150   // self now that low-level suspension is barely used, and old workarounds
   150   // self now that low-level suspension is barely used, and old workarounds
   151   // for BsdThreads are no longer needed.
   151   // for BsdThreads are no longer needed.
   152   class SuspendResume {
   152   class SuspendResume {
   153   private:
   153   private:
   154     volatile int _suspend_action;
   154     volatile int  _suspend_action;
       
   155     volatile jint _state;
       
   156   public:
   155     // values for suspend_action:
   157     // values for suspend_action:
   156     #define SR_NONE               (0x00)
   158     enum {
   157     #define SR_SUSPEND            (0x01)  // suspend request
   159       SR_NONE              = 0x00,
   158     #define SR_CONTINUE           (0x02)  // resume request
   160       SR_SUSPEND           = 0x01,  // suspend request
   159 
   161       SR_CONTINUE          = 0x02,  // resume request
   160     volatile jint _state;
   162       SR_SUSPENDED         = 0x20   // values for _state: + SR_NONE
   161     // values for _state: + SR_NONE
   163     };
   162     #define SR_SUSPENDED          (0x20)
   164 
   163   public:
       
   164     SuspendResume() { _suspend_action = SR_NONE; _state = SR_NONE; }
   165     SuspendResume() { _suspend_action = SR_NONE; _state = SR_NONE; }
   165 
   166 
   166     int suspend_action() const     { return _suspend_action; }
   167     int suspend_action() const     { return _suspend_action; }
   167     void set_suspend_action(int x) { _suspend_action = x;    }
   168     void set_suspend_action(int x) { _suspend_action = x;    }
   168 
   169 
   169     // atomic updates for _state
   170     // atomic updates for _state
   170     void set_suspended()           {
   171     inline void set_suspended();
   171       jint temp, temp2;
   172     inline void clear_suspended();
   172       do {
       
   173         temp = _state;
       
   174         temp2 = Atomic::cmpxchg(temp | SR_SUSPENDED, &_state, temp);
       
   175       } while (temp2 != temp);
       
   176     }
       
   177     void clear_suspended()        {
       
   178       jint temp, temp2;
       
   179       do {
       
   180         temp = _state;
       
   181         temp2 = Atomic::cmpxchg(temp & ~SR_SUSPENDED, &_state, temp);
       
   182       } while (temp2 != temp);
       
   183     }
       
   184     bool is_suspended()            { return _state & SR_SUSPENDED;       }
   173     bool is_suspended()            { return _state & SR_SUSPENDED;       }
   185 
   174 
   186     #undef SR_SUSPENDED
   175     #undef SR_SUSPENDED
   187   };
   176   };
   188 
   177