Julian Noble
1 year ago
7 changed files with 199 additions and 115 deletions
@ -0,0 +1,87 @@
|
||||
# -*- tcl -*- |
||||
# Maintenance Instruction: leave the 999999.xxx.x as is and use 'pmix make' or src/make.tcl to update from <pkg>-buildversion.txt |
||||
# |
||||
# Please consider using a BSD or MIT style license for greatest compatibility with the Tcl ecosystem. |
||||
# Code using preferred Tcl licenses can be eligible for inclusion in Tcllib, Tklib and the punk package repository. |
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
# (C) 2023 |
||||
# |
||||
# @@ Meta Begin |
||||
# Application zzzload 999999.0a1.0 |
||||
# Meta platform tcl |
||||
# Meta license <unspecified> |
||||
# @@ Meta End |
||||
|
||||
|
||||
|
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
## Requirements |
||||
##e.g package require frobz |
||||
|
||||
package require Thread |
||||
|
||||
|
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
namespace eval zzzload { |
||||
variable loader_tid ;#thread id |
||||
set loader_tid [thread::create -preserved] |
||||
|
||||
proc pkg_require {pkgname args} { |
||||
variable loader_tid |
||||
if {![tsv::exists zzzload_pkg $pkgname]} { |
||||
tsv::set zzzload_pkg $pkgname "loading" |
||||
tsv::set zzzload_pkg_mutex $pkgname [thread::mutex create] |
||||
set cond [thread::cond create] |
||||
tsv::set zzzload_pkg_cond $pkgname $cond |
||||
thread::send -async $loader_tid [string map [list <pkg> $pkgname <cond> $cond] { |
||||
if {![catch {package require <pkg>} ver]} { |
||||
tsv::set zzzload_pkg <pkg> $ver |
||||
} else { |
||||
tsv::set zzzload_pkg <pkg> "failed" |
||||
} |
||||
thread::cond notify <cond> |
||||
}] |
||||
return "loading" |
||||
} else { |
||||
return [tsv::get zzzload_pkg $pkgname] |
||||
} |
||||
} |
||||
proc pkg_wait {pkgname} { |
||||
set pkgstate [tsv::get zzzload_pkg $pkgname] |
||||
if {$pkgstate eq "loading"} { |
||||
set mutex [tsv::get zzzload_pkg_mutex $pkgname] |
||||
thread::mutex lock $mutex |
||||
set cond [tsv::get zzzload_pkg_cond $pkgname] |
||||
while {[tsv::get zzzload_pkg $pkgname] eq "loading"} { |
||||
thread::cond wait $cond $mutex 3000 |
||||
} |
||||
set result [tsv::get zzzload_pkg $pkgname] |
||||
thread::mutex unlock $mutex |
||||
return $result |
||||
} else { |
||||
return $pkgstate |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ++ +++ +++ +++ +++ +++ +++ +++ +++ +++ +++ |
||||
## Ready |
||||
package provide zzzload [namespace eval zzzload { |
||||
variable version |
||||
set version 999999.0a1.0 |
||||
}] |
||||
return |
Loading…
Reference in new issue