summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fainelli <florian@openwrt.org>2012-10-14 16:22:04 +0000
committerFlorian Fainelli <florian@openwrt.org>2012-10-14 16:22:04 +0000
commit19f91b26f520542297e6a1edc807e64ce2a0ca0f (patch)
tree655b18b7c2cc241f5d617a7b658741e176621ac9
parented393422a0ccf63b829d715b72631a0aa0cbac7f (diff)
downloadmtk-20170518-19f91b26f520542297e6a1edc807e64ce2a0ca0f.zip
mtk-20170518-19f91b26f520542297e6a1edc807e64ce2a0ca0f.tar.gz
mtk-20170518-19f91b26f520542297e6a1edc807e64ce2a0ca0f.tar.bz2
rssileds: improve performance
LEDs brightness is now only updated if the value actually changed, thus reducing the number of fwrite syscalls significantly. Signed-off-by: Daniel Golle <dgolle@allnet.de> SVN-Revision: 33766
-rw-r--r--package/network/utils/rssileds/Makefile2
-rw-r--r--package/network/utils/rssileds/src/rssileds.c58
2 files changed, 35 insertions, 25 deletions
diff --git a/package/network/utils/rssileds/Makefile b/package/network/utils/rssileds/Makefile
index 8e292df..b572eac 100644
--- a/package/network/utils/rssileds/Makefile
+++ b/package/network/utils/rssileds/Makefile
@@ -8,7 +8,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=rssileds
-PKG_VERSION:=0.1
+PKG_VERSION:=0.2
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
diff --git a/package/network/utils/rssileds/src/rssileds.c b/package/network/utils/rssileds/src/rssileds.c
index 2f25c84..60d30f1 100644
--- a/package/network/utils/rssileds/src/rssileds.c
+++ b/package/network/utils/rssileds/src/rssileds.c
@@ -70,6 +70,32 @@ void log_rules(rule_t *rules)
}
}
+int set_led(struct led *led, unsigned char value)
+{
+ char buf[8];
+
+ if ( ! led )
+ return -1;
+
+ if ( ! led->controlfd )
+ return -1;
+
+ if ( led->state == value )
+ return 0;
+
+ snprintf(buf, 8, "%d", value);
+
+ rewind(led->controlfd);
+
+ if ( ! fwrite(buf, sizeof(char), strlen(buf), led->controlfd) )
+ return -2;
+
+ fflush(led->controlfd);
+ led->state=value;
+
+ return 0;
+}
+
int init_led(struct led **led, char *ledname)
{
struct led *newled;
@@ -102,8 +128,15 @@ int init_led(struct led **led, char *ledname)
newled->sysfspath = bp;
newled->controlfd = bfp;
-
+
*led = newled;
+
+ if ( set_led(newled, 255) )
+ goto cleanup_fp;
+
+ if ( set_led(newled, 0) )
+ goto cleanup_fp;
+
return 0;
cleanup_fp:
@@ -124,29 +157,6 @@ void close_led(struct led **led)
(*led)=NULL;
}
-int set_led(struct led *led, unsigned char value)
-{
- char buf[8];
-
- if ( ! led )
- return -1;
-
- if ( ! led->controlfd )
- return -1;
-
- snprintf(buf, 8, "%d", value);
-
- rewind(led->controlfd);
-
- if ( ! fwrite(buf, sizeof(char), strlen(buf), led->controlfd) )
- return -2;
-
- fflush(led->controlfd);
- led->state=value;
-
- return 0;
-}
-
int quality(const struct iwinfo_ops *iw, const char *ifname)
{