GT-3260_emteere removing lock profiling change

This commit is contained in:
emteere 2019-11-05 08:19:09 -05:00
parent 4a4cb2a1e4
commit 40a7425b3c

View file

@ -1,5 +1,6 @@
/* ### /* ###
* IP: GHIDRA * IP: GHIDRA
* REVIEWED: YES
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,18 +19,16 @@ package ghidra.util;
/** /**
* Ghidra synchronization lock. This class allows creation of named locks for * Ghidra synchronization lock. This class allows creation of named locks for
* modifying tables in the Ghidra data base. This class also creates an instance * modifying tables in the Ghidra data base. This class also creates an instance
* of a global lock that must first be obtained when synchronizing using * of a global lock that must first be obtained when synchronizing using multiple
* multiple of the named locks. * of the named locks.
*/ */
public class Lock { public class Lock {
private Thread owner; private Thread owner;
private int cnt = 0; private int cnt = 0;
private int waiting = 0;
private String name; private String name;
/** /**
* Creates an instance of a lock for synchronization within Ghidra. * Creates an instance of a lock for synchronization within Ghidra.
*
* @param name the name of this lock * @param name the name of this lock
*/ */
public Lock(String name) { public Lock(String name) {
@ -37,8 +36,8 @@ public class Lock {
} }
/** /**
* Acquire this synchronization lock. (i.e. begin synchronizing on this named * Acquire this synchronization lock.
* lock.) * (i.e. begin synchronizing on this named lock.)
*/ */
public synchronized void acquire() { public synchronized void acquire() {
Thread currThread = Thread.currentThread(); Thread currThread = Thread.currentThread();
@ -48,16 +47,15 @@ public class Lock {
cnt = 1; cnt = 1;
owner = currThread; owner = currThread;
return; return;
} else if (owner == currThread) { }
else if (owner == currThread) {
cnt++; cnt++;
return; return;
} }
try { try {
waiting++;
wait(); wait();
} catch (InterruptedException e) { }
} finally { catch (InterruptedException e) {
waiting--;
} }
} }
} }
@ -72,24 +70,20 @@ public class Lock {
if (cnt > 0 && (owner == currThread)) { if (cnt > 0 && (owner == currThread)) {
if (--cnt == 0) { if (--cnt == 0) {
owner = null; owner = null;
// This is purely to help sample profiling. If notify() is called the notify();
// sampler can attribute time to the methods calling this erroneously. For some reason
// the visualvm sampler gets a sample more often when notify() is called.
if (waiting != 0) {
notify();
}
} }
} else { }
else {
throw new IllegalStateException("Attempted to release an unowned lock: " + name); throw new IllegalStateException("Attempted to release an unowned lock: " + name);
} }
} }
/** /**
* Gets the thread that currently owns the lock. * Gets the thread that currently owns the lock.
*
* @return the thread that owns the lock or null. * @return the thread that owns the lock or null.
*/ */
public Thread getOwner() { public Thread getOwner() {
return owner; return owner;
} }
} }