Skip to content

Commit

Permalink
Added low-effort sync
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Nov 29, 2024
1 parent 0be641c commit e89774e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ constructor(
val mutexes: Map<String, Int> = processes.keys.associateBy { "$it" },
val threadLookup: Map<VarDecl<*>, Int> = emptyMap(),
val bottom: Boolean = false,
val syncingOn: String? = null,
) : ExprState {

constructor(
Expand Down Expand Up @@ -172,6 +173,8 @@ constructor(
is StartLabel -> changes.add { state -> state.start(it) }.let { true }
is StmtLabel -> true
is WriteLabel -> error("Read/Write labels not yet supported")
is SyncSendLabel -> changes.add { state -> state.enterSync(it) }.let { true }
is SyncRecvLabel -> changes.add { state -> state.exitSync(it) }.let { true }
}
}

Expand All @@ -185,6 +188,18 @@ constructor(
)
}

private fun enterSync(syncSendLabel: SyncSendLabel): XcfaState<S> {
syncingOn?.also {
return copy(bottom = true)
}
return copy(syncingOn = syncSendLabel.key)
}

private fun exitSync(syncRecvLabel: SyncRecvLabel): XcfaState<S> {
syncingOn?.takeIf { it == syncRecvLabel.key } ?: return copy(bottom = true)
return copy(syncingOn = null)
}

private fun start(startLabel: StartLabel): XcfaState<S> {
val newProcesses: MutableMap<Int, XcfaProcessState> = LinkedHashMap(processes)
val newThreadLookup: MutableMap<VarDecl<*>, Int> = LinkedHashMap(threadLookup)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ constructor(val labels: Set<XcfaLabel>, override val metadata: MetaData = EmptyM
}
}

data class SyncSendLabel
@JvmOverloads
constructor(val key: String, override val metadata: MetaData = EmptyMetaData) :
XcfaLabel(metadata = metadata)

data class SyncRecvLabel
@JvmOverloads
constructor(val key: String, override val metadata: MetaData = EmptyMetaData) :
XcfaLabel(metadata = metadata)

object NopLabel : XcfaLabel(metadata = EmptyMetaData) {

override fun toStmt(): Stmt {
Expand Down

0 comments on commit e89774e

Please sign in to comment.