~aleteoryx/tclircc

dd09632658fec09c6e07d172295b0b1abc269b4a — aleteoryx a month ago b0e4537
this component is just gonna be routing management actually
2 files changed, 19 insertions(+), 20 deletions(-)

M main.tcl
R state.tcl => threads.tcl
M main.tcl => main.tcl +5 -5
@@ 10,11 10,11 @@ set log [logger::init tclircc::main]
${log}::info "tclircc $version <https://amehut.dev/~aleteoryx/tclircc>"
${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..."

R state.tcl => threads.tcl +14 -15
@@ 1,34 1,33 @@
namespace eval state {
namespace eval threads {
  variable threads [list main [thread::id]]
  variable log [logger::init tclircc::state]
  variable logt [logger::init tclircc::state::threads]
  variable log [logger::init tclircc::threads]

  variable ns

  proc manage_thread {tid name} {
  proc manage {tid name} {
    variable threads
    variable logt
    variable log
    dict set threads $name $tid
    ${logt}::debug "managing thread $tid as \"$name\""
    ${log}::debug "managing thread $tid as \"$name\""

    thread::send -head $tid {
      namespace eval state {
      namespace eval threads {
        variable ns
        proc update {} {
          variable ns
          thread::send -head [set ns(main)] state::update
          thread::send -head [set ns(main)] threads::update
        }
      }
    }

    ::state::update
    ::threads::update
  }
  proc unmanage_thread {name} {
  proc unmanage {name} {
    variable threads
    variable logt
    variable log
    dict unset threads $name
    ${logt}::debug "unmanaging thread $tid (\"$name\")"
    ::state::update
    ${log}::debug "unmanaging thread $tid (\"$name\")"
    ::threads::update
  }
  proc update {} {
    variable threads


@@ 36,9 35,9 @@ namespace eval state {
      if ![thread::exists $tid] {dict unset $threads $name}
    }
    dict for {name tid} $threads {
      set payload {array unset state::ns; }
      set payload {array unset threads::ns; }
      dict for {n t} $threads {
        append payload {set state::ns(} $n {) } $t {; }
        append payload {set threads::ns(} $n {) } $t {; }
      }
      thread::send -head $tid $payload
    }