Skip to content

Commit

Permalink
Replace Thread.holdsLock(Session) with Session.isLockedByCurrentThread()
Browse files Browse the repository at this point in the history
(cherry picked from commit 2300b99)
  • Loading branch information
katzyn authored and andreitokar committed Sep 2, 2023
1 parent 8ba3ea3 commit 493251f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 10 additions & 0 deletions h2/src/main/org/h2/engine/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,16 @@ public final void unlock() {
lock.unlock();
}

/**
* Returns whether this session is locked by the current thread.
*
* @return {@code true} if it locked by the current thread, {@code false} if
* it is locked by another thread or is not locked at all
*/
public final boolean isLockedByCurrentThread() {
return lock.isHeldByCurrentThread();
}

/**
* Get the list of the cluster servers for this session.
*
Expand Down
5 changes: 2 additions & 3 deletions h2/src/main/org/h2/engine/SessionLocal.java
Original file line number Diff line number Diff line change
Expand Up @@ -714,8 +714,7 @@ private void analyzeTables() {
// On rare occasions it can be called concurrently (i.e. from close())
// without proper locking, but instead of oversynchronizing
// we just skip this optional operation in such case
if (tablesToAnalyze != null &&
Thread.holdsLock(this)) {
if (tablesToAnalyze != null && isLockedByCurrentThread()) {
// take a local copy and clear because in rare cases we can call
// back into markTableForAnalyze while iterating here
HashSet<Table> tablesToAnalyzeLocal = tablesToAnalyze;
Expand Down Expand Up @@ -1503,7 +1502,7 @@ public void waitIfExclusiveModeEnabled() {
if (exclusive == null || exclusive == this) {
break;
}
if (Thread.holdsLock(exclusive)) {
if (exclusive.isLockedByCurrentThread()) {
// if another connection is used within the connection
break;
}
Expand Down

0 comments on commit 493251f

Please sign in to comment.