From dd09632658fec09c6e07d172295b0b1abc269b4a Mon Sep 17 00:00:00 2001 From: aleteoryx Date: Thu, 7 Nov 2024 11:03:35 -0500 Subject: [PATCH] this component is just gonna be routing management actually --- main.tcl | 10 +++++----- state.tcl | 46 ---------------------------------------------- threads.tcl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 51 deletions(-) delete mode 100644 state.tcl create mode 100644 threads.tcl diff --git a/main.tcl b/main.tcl index 7d9b664..aba2ee5 100755 --- a/main.tcl +++ b/main.tcl @@ -10,11 +10,11 @@ set log [logger::init tclircc::main] ${log}::info "tclircc $version " ${log}::info "running from $path" -source state.tcl +source threads.tcl ${log}::debug "starting db thread..." set db_thread [thread::create -preserved] -state::manage_thread $db_thread tclircc::db +threads::manage $db_thread tclircc::db thread::send $db_thread [list variable path $path version $version] if {[thread::send $db_thread [list source "$path[file separator]db[file separator]main.tcl"] result] == 1} { ${log}::critical "couldn't start db thread: $result" @@ -24,7 +24,7 @@ ${log}::debug "started db thread." ${log}::debug "starting ui thread..." set ui_thread [thread::create -preserved] -state::manage_thread $ui_thread tclircc::ui +threads::manage $ui_thread tclircc::ui thread::send $ui_thread [list variable path $path version $version] if {[thread::send $ui_thread [list source "$path[file separator]ui[file separator]main.tcl"] result] == 1} { ${log}::critical "couldn't start ui thread: $result" @@ -33,8 +33,8 @@ if {[thread::send $ui_thread [list source "$path[file separator]ui[file separato ${log}::debug "started ui thread." update -foreach key [array names state::ns] { - ${log}::debug "thread \"$key\" has id [set state::ns($key)]" +foreach key [array names threads::ns] { + ${log}::debug "thread \"$key\" has id [set threads::ns($key)]" } ${log}::debug "opening main window..." diff --git a/state.tcl b/state.tcl deleted file mode 100644 index 5141118..0000000 --- a/state.tcl +++ /dev/null @@ -1,46 +0,0 @@ -namespace eval state { - variable threads [list main [thread::id]] - variable log [logger::init tclircc::state] - variable logt [logger::init tclircc::state::threads] - - variable ns - - proc manage_thread {tid name} { - variable threads - variable logt - dict set threads $name $tid - ${logt}::debug "managing thread $tid as \"$name\"" - - thread::send -head $tid { - namespace eval state { - variable ns - proc update {} { - variable ns - thread::send -head [set ns(main)] state::update - } - } - } - - ::state::update - } - proc unmanage_thread {name} { - variable threads - variable logt - dict unset threads $name - ${logt}::debug "unmanaging thread $tid (\"$name\")" - ::state::update - } - proc update {} { - variable threads - dict for {name tid} $threads { - if ![thread::exists $tid] {dict unset $threads $name} - } - dict for {name tid} $threads { - set payload {array unset state::ns; } - dict for {n t} $threads { - append payload {set state::ns(} $n {) } $t {; } - } - thread::send -head $tid $payload - } - } -} diff --git a/threads.tcl b/threads.tcl new file mode 100644 index 0000000..057b060 --- /dev/null +++ b/threads.tcl @@ -0,0 +1,45 @@ +namespace eval threads { + variable threads [list main [thread::id]] + variable log [logger::init tclircc::threads] + + variable ns + + proc manage {tid name} { + variable threads + variable log + dict set threads $name $tid + ${log}::debug "managing thread $tid as \"$name\"" + + thread::send -head $tid { + namespace eval threads { + variable ns + proc update {} { + variable ns + thread::send -head [set ns(main)] threads::update + } + } + } + + ::threads::update + } + proc unmanage {name} { + variable threads + variable log + dict unset threads $name + ${log}::debug "unmanaging thread $tid (\"$name\")" + ::threads::update + } + proc update {} { + variable threads + dict for {name tid} $threads { + if ![thread::exists $tid] {dict unset $threads $name} + } + dict for {name tid} $threads { + set payload {array unset threads::ns; } + dict for {n t} $threads { + append payload {set threads::ns(} $n {) } $t {; } + } + thread::send -head $tid $payload + } + } +} -- 2.45.2