1
1
/* ###
2
2
* IP: GHIDRA
3
+ * REVIEWED: YES
3
4
*
4
5
* Licensed under the Apache License, Version 2.0 (the "License");
5
6
* you may not use this file except in compliance with the License.
16
17
package ghidra .util ;
17
18
18
19
/**
19
- * Ghidra synchronization lock. This class allows creation of named locks for
20
+ * Ghidra synchronization lock. This class allows creation of named locks for
20
21
* modifying tables in the Ghidra data base. This class also creates an instance
21
- * of a global lock that must first be obtained when synchronizing using
22
- * multiple of the named locks.
22
+ * of a global lock that must first be obtained when synchronizing using multiple
23
+ * of the named locks.
23
24
*/
24
25
public class Lock {
25
26
private Thread owner ;
26
27
private int cnt = 0 ;
27
- private int waiting = 0 ;
28
28
private String name ;
29
29
30
30
/**
31
31
* Creates an instance of a lock for synchronization within Ghidra.
32
- *
33
32
* @param name the name of this lock
34
33
*/
35
34
public Lock (String name ) {
36
35
this .name = name ;
37
36
}
38
37
39
38
/**
40
- * Acquire this synchronization lock. (i.e. begin synchronizing on this named
41
- * lock.)
39
+ * Acquire this synchronization lock.
40
+ * (i.e. begin synchronizing on this named lock.)
42
41
*/
43
42
public synchronized void acquire () {
44
43
Thread currThread = Thread .currentThread ();
@@ -48,16 +47,15 @@ public synchronized void acquire() {
48
47
cnt = 1 ;
49
48
owner = currThread ;
50
49
return ;
51
- } else if (owner == currThread ) {
50
+ }
51
+ else if (owner == currThread ) {
52
52
cnt ++;
53
53
return ;
54
54
}
55
55
try {
56
- waiting ++;
57
56
wait ();
58
- } catch (InterruptedException e ) {
59
- } finally {
60
- waiting --;
57
+ }
58
+ catch (InterruptedException e ) {
61
59
}
62
60
}
63
61
}
@@ -72,24 +70,20 @@ public synchronized void release() {
72
70
if (cnt > 0 && (owner == currThread )) {
73
71
if (--cnt == 0 ) {
74
72
owner = null ;
75
- // This is purely to help sample profiling. If notify() is called the
76
- // sampler can attribute time to the methods calling this erroneously. For some reason
77
- // the visualvm sampler gets a sample more often when notify() is called.
78
- if (waiting != 0 ) {
79
- notify ();
80
- }
73
+ notify ();
81
74
}
82
- } else {
75
+ }
76
+ else {
83
77
throw new IllegalStateException ("Attempted to release an unowned lock: " + name );
84
78
}
85
79
}
86
80
87
81
/**
88
82
* Gets the thread that currently owns the lock.
89
- *
90
83
* @return the thread that owns the lock or null.
91
84
*/
92
85
public Thread getOwner () {
93
86
return owner ;
94
87
}
88
+
95
89
}
0 commit comments