class Parker : public PlatformParker { private:
NONCOPYABLE(Parker); public:
Parker() : PlatformParker() {}
// For simplicity of interface with Java, all forms of park (indefinite, // relative, and absolute) are multiplexed into one call. void park(bool isAbsolute, jlong time); void unpark();
};
///////////////////////////////////////////////////////////// // // ParkEvents are type-stable and immortal. // // Lifecycle: Once a ParkEvent is associated with a thread that ParkEvent remains // associated with the thread for the thread's entire lifetime - the relationship is // stable. A thread will be associated at most one ParkEvent. When the thread // expires, the ParkEvent moves to the EventFreeList. New threads attempt to allocate from // the EventFreeList before creating a new Event. Type-stability frees us from // worrying about stale Event or Thread references in the objectMonitor subsystem. // (A reference to ParkEvent is always valid, even though the event may no longer be associated // with the desired or expected thread. A key aspect of this design is that the callers of // park, unpark, etc must tolerate stale references and spurious wakeups). // // Only the "associated" thread can block (park) on the ParkEvent, although // any other thread can unpark a reachable parkevent. Park() is allowed to // return spuriously. In fact park-unpark a really just an optimization to // avoid unbounded spinning and surrender the CPU to be a polite system citizen. // A degenerate albeit "impolite" park-unpark implementation could simply return. // See http://blogs.sun.com/dave for more details. // // Eventually I'd like to eliminate Events and ObjectWaiters, both of which serve as // thread proxies, and simply make the THREAD structure type-stable and persistent. // Currently, we unpark events associated with threads, but ideally we'd just // unpark threads. // // The base-class, PlatformEvent, is platform-specific while the ParkEvent is // platform-independent. PlatformEvent provides park(), unpark(), etc., and // is abstract -- that is, a PlatformEvent should never be instantiated except // as part of a ParkEvent. // Equivalently we could have defined a platform-independent base-class that // exported Allocate(), Release(), etc. The platform-specific class would extend // that base-class, adding park(), unpark(), etc. // // A word of caution: The JVM uses 2 very similar constructs: // 1. ParkEvent are used for Java-level "monitor" synchronization. // 2. Parkers are used by JSR166-JUC park-unpark. // // We'll want to eventually merge these redundant facilities and use ParkEvent.
class ParkEvent : public PlatformEvent { private:
ParkEvent * FreeNext ;
// Current association
Thread * AssociatedWith ;
public: // MCS-CLH list linkage and Native Mutex/Monitor
ParkEvent * volatile ListNext ; volatileint TState ; volatileint Notified ; // for native monitor construct
// It's prudent to mark the dtor as "private" // ensuring that it's not visible outside the package. // Unfortunately gcc warns about such usage, so // we revert to the less desirable "protected" visibility. // The other compilers accept private dtors.
protected: // Ensure dtor is never invoked
~ParkEvent() { guarantee (0, "invariant") ; }
// We use placement-new to force ParkEvent instances to be // aligned on 256-byte address boundaries. This ensures that the least // significant byte of a ParkEvent address is always 0.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.