~aleteoryx/tclircc

ref: dd09632658fec09c6e07d172295b0b1abc269b4a tclircc/threads.tcl -rw-r--r-- 1.0 KiB
dd096326aleteoryx this component is just gonna be routing management actually a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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
    }
  }
}