Instead of locking/unlocking it for every command.

Reduces the runtime for the dslstat/lucistat commands to ~66%.

Before:
real    0m 2.66s
user    0m 0.90s
sys     0m 1.76s

After:
real    0m 1.76s
user    0m 0.63s
sys     0m 1.13s

Signed-off-by: Andre Heider <a.hei...@gmail.com>
---
 .../files/lib/functions/lantiq_dsl.sh         | 21 +++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git 
a/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh 
b/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh
index 39011f134f..89dc5c25c9 100755
--- a/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh
+++ b/package/network/utils/ltq-dsl-base/files/lib/functions/lantiq_dsl.sh
@@ -7,16 +7,24 @@ else
        XDSL_CTRL=dsl_cpe_control
 fi
 
+DSL_PIPE_LOCKED=0
+
 #
 # Basic functions to send CLI commands to the vdsl_cpe_control daemon
 #
+dsl_init() {
+       killall -q -0 ${XDSL_CTRL} && lock /var/lock/dsl_pipe && 
DSL_PIPE_LOCKED=1
+       trap dsl_deinit EXIT INT KILL TERM
+}
+dsl_deinit() {
+       test $DSL_PIPE_LOCKED -gt 0 && lock -u /var/lock/dsl_pipe && 
DSL_PIPE_LOCKED=0
+       exit
+}
 dsl_cmd() {
-       killall -q -0 ${XDSL_CTRL} && (
-               lock /var/lock/dsl_pipe
-               echo "$@" > /tmp/pipe/dsl_cpe0_cmd
-               cat /tmp/pipe/dsl_cpe0_ack
-               lock -u /var/lock/dsl_pipe
-       )
+       test $DSL_PIPE_LOCKED -eq 0 && return
+
+       echo "$@" > /tmp/pipe/dsl_cpe0_cmd
+       cat /tmp/pipe/dsl_cpe0_ack
 }
 dsl_val() {
        expr "$1" : '.*'$2'=\([-\.[:alnum:]]*\).*'
@@ -783,6 +791,7 @@ line_features() {
 }
 
 dslstat() {
+       dsl_init
        vendor
        chipset
        xtse
-- 
2.29.2


_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel

Reply via email to