MonitorLocker is a subclass of MutexLocker. The member variable _monitor has the same value of _mutex in its base class.
The only difference is type of pointer. Because 2 constructs pass in Monitor*, it's safe to use static_cast<> to cast _mutex to Monitor*. eg.
Monitor* as_monitor() const {
return static_cast<Monitor* >(_mutex);
}
This can save 1 pointer for a MonitorLocker object. on x86_64 LP64, it can save 8 bytes.
The only difference is type of pointer. Because 2 constructs pass in Monitor*, it's safe to use static_cast<> to cast _mutex to Monitor*. eg.
Monitor* as_monitor() const {
return static_cast<Monitor* >(_mutex);
}
This can save 1 pointer for a MonitorLocker object. on x86_64 LP64, it can save 8 bytes.