Skip to content

Commit

Permalink
Merge pull request #119 from FolkComputer/nm/clear-mailbox
Browse files Browse the repository at this point in the history
Clear mailbox of unmatched processes
  • Loading branch information
osnr authored Nov 23, 2023
2 parents 9c40b91 + ee4cc94 commit a1676cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/peer.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ proc ::peer {process {dieOnDisconnect false}} {
variable process
Mailbox::receive $process $::thisProcess
}
proc clear {} {
variable process
Mailbox::clear $process $::thisProcess
}

proc share {shareStatements} {
variable process
Expand Down
2 changes: 2 additions & 0 deletions lib/process.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ proc Start-process {name body} {
}
}
On unmatch {
# Clear the mailbox
::Peers::${name}::clear
# Remember to suppress/kill the process if it shows up
# later after we're gone.
dict set ::peersBlacklist $name true
Expand Down
8 changes: 8 additions & 0 deletions main.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,14 @@ namespace eval ::Mailbox {
} pthread_mutex_unlock(&mailbox->mutex);
return ret;
}
$cc proc clear {char* from char* to} void {
mailbox_t* mailbox = find(from, to);
pthread_mutex_lock(&mailbox->mutex); {
mailbox->active = 0;
mailbox->mail[0] = '\0';
mailbox->mailLen = 0;
} pthread_mutex_unlock(&mailbox->mutex);
}
$cc compile
init
}
Expand Down

0 comments on commit a1676cb

Please sign in to comment.