synchronized boolean startRead() { Thread t = Thread.currentThread(); Object c = readers_.get(t); if (c != null) { // already held -- just increment hold count readers_.put(t, new Integer( ( (Integer) (c)).intValue() + 1)); ++activeReaders_; return true; } else if (allowReader()) { readers_.put(t, IONE); ++activeReaders_; return true; } else return false; }
synchronized boolean startRead() { Thread t = Thread.currentThread(); Object c = readers_.get(t); if (c != null) { // already held -- just increment hold count readers_.put(t, new Integer( ( (Integer) (c)).intValue() + 1)); ++activeReaders_; return true; } else if (allowReader()) { readers_.put(t, IONE); ++activeReaders_; return true; } else return false; }
synchronized boolean startRead() { Thread t = Thread.currentThread(); Object c = readers_.get(t); if (c != null) { // already held -- just increment hold count readers_.put(t, new Integer( ( (Integer) (c)).intValue() + 1)); ++activeReaders_; return true; } else if (allowReader()) { readers_.put(t, IONE); ++activeReaders_; return true; } else return false; }
synchronized int endWrite() { if (activeWriter_ != Thread.currentThread()) { throw new IllegalMonitorStateException(); } --writeHolds_; if (writeHolds_ > 0) // still being held return NONE; else { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return READER; else if (waitingWriters_ > 0) return WRITER; else return NONE; } }
synchronized int endWrite() { if (activeWriter_ != Thread.currentThread()) { throw new IllegalMonitorStateException(); } --writeHolds_; if (writeHolds_ > 0) // still being held return NONE; else { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return READER; else if (waitingWriters_ > 0) return WRITER; else return NONE; } }
synchronized int endWrite() { if (activeWriter_ != Thread.currentThread()) { throw new IllegalMonitorStateException(); } --writeHolds_; if (writeHolds_ > 0) // still being held return NONE; else { activeWriter_ = null; if (waitingReaders_ > 0 && allowReader()) return READER; else if (waitingWriters_ > 0) return WRITER; else return NONE; } }