Removes locks for the specified job, all in reverse order.
()
| 146 | * Removes locks for the specified job, all in reverse order. |
| 147 | */ |
| 148 | public void release() { |
| 149 | final Long id = Thread.currentThread().getId(); |
| 150 | final Locks locks = locked.remove(id); |
| 151 | final LockList reads = locks.reads, writes = locks.writes; |
| 152 | final boolean lock = reads.locking() || writes.locking(); |
| 153 | |
| 154 | // release all local locks |
| 155 | for(final String string : reads) unpin(string).readLock().unlock(); |
| 156 | for(final String string : writes) unpin(string).writeLock().unlock(); |
| 157 | |
| 158 | // allow next global reader to resume |
| 159 | synchronized(globalLock) { |
| 160 | if(reads.global()) { |
| 161 | globalReaders--; |
| 162 | globalLock.notifyAll(); |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | // allow next local writer to resume |
| 167 | synchronized(globalLock) { |
| 168 | if(writes.local()) { |
| 169 | localWriters--; |
| 170 | globalLock.notifyAll(); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | // release exclusive lock (global write), or shared lock otherwise |
| 175 | if(lock) (writes.global() ? globalLocks.writeLock() : globalLocks.readLock()).unlock(); |
| 176 | |
| 177 | // allow next queued job to resume (non-locking jobs were never counted) |
| 178 | if(lock) queue.release(); |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Pins a lock string. Creates a new lock if necessary. |