Skip to content

Commit

Permalink
Skip scheduling decisions when there is only one schedulable thread. (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
aoli-al authored Jan 4, 2025
1 parent 798b215 commit 3a72a4a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
6 changes: 6 additions & 0 deletions core/src/main/kotlin/org/pastalab/fray/core/RunContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,14 @@ class RunContext(val config: Configuration) {

fun latchAwait(latch: CountDownLatch, timed: Boolean) {
val t = Thread.currentThread().id
val objId = System.identityHashCode(latch)
val context = registeredThreads[t]!!
val latchContext = latchManager.getContext(latch)

context.pendingOperation = ObjectWaitOperation(objId)
context.state = ThreadState.Enabled
scheduleNextOperation(true)

if (latchContext.await(true, context)) {
context.pendingOperation = CountDownLatchAwaitBlocking(timed, latchContext)
context.state = ThreadState.Paused
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class FrayIdeaPluginScheduler : Scheduler {
threads: List<ThreadContext>,
allThreads: List<ThreadContext>
): ThreadContext {
if (threads.size == 1) {
return threads.first()
}
val index = remoteScheduler.scheduleNextOperation(allThreads.map { it.toStackInfo() })
return allThreads[index]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class FrayDebuggerManager(val debugSession: XDebugSession) :
}

fun stop() {
schedulerPanel.stop()
registry.unbind("RemoteScheduler")
UnicastRemoteObject.unexportObject(scheduler, true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class SchedulerPanel(val project: Project) : JPanel() {

init {
layout = BorderLayout()

comboBox = ComboBox<ThreadInfo>(comboBoxModel)
comboBox.renderer =
object : DefaultListCellRenderer() {
Expand Down Expand Up @@ -99,6 +98,10 @@ class SchedulerPanel(val project: Project) : JPanel() {
}
}

fun stop() {
currentRangeHighlighters.forEach { it.first.removeHighlighter(it.second) }
}

fun comboBoxSelected(threadInfo: ThreadInfo) {
myFrameListModel.clear()
ApplicationManager.getApplication().invokeAndWait {
Expand Down Expand Up @@ -159,12 +162,8 @@ class SchedulerPanel(val project: Project) : JPanel() {
break
}
}
try {
enabledThreads.first { it.index == selected?.index }.let { comboBoxModel.selectedItem = it }
} catch (e: NoSuchElementException) {
comboBoxModel.selectedItem = enabledThreads.first()
}

comboBoxModel.selectedItem =
enabledThreads.find { it.index == selected?.index } ?: enabledThreads.first()
callback = onThreadSelected
}

Expand Down

0 comments on commit 3a72a4a

Please sign in to comment.