aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Tarasikov <alexander.tarasikov@gmail.com>2012-08-20 14:12:20 +0400
committerAlexander Tarasikov <alexander.tarasikov@gmail.com>2012-08-20 14:12:20 +0400
commit9875a661bb960d329f992f1f63ef5c6241f63135 (patch)
tree642813919a2ace6974aa51dab2905248f6226a7d
parentd109d6c95ebb226754e6e8493bc19a4abee9b35c (diff)
downloadexternal_libsamsung-ipc-9875a661bb960d329f992f1f63ef5c6241f63135.zip
external_libsamsung-ipc-9875a661bb960d329f992f1f63ef5c6241f63135.tar.gz
external_libsamsung-ipc-9875a661bb960d329f992f1f63ef5c6241f63135.tar.bz2
Use static wakelock file descriptors
-rw-r--r--samsung-ipc/wakelock.c27
1 files changed, 17 insertions, 10 deletions
diff --git a/samsung-ipc/wakelock.c b/samsung-ipc/wakelock.c
index ea28048..1daaec9 100644
--- a/samsung-ipc/wakelock.c
+++ b/samsung-ipc/wakelock.c
@@ -22,17 +22,22 @@
#include <fcntl.h>
#include <wakelock.h>
+static int wake_lock_fd = -1;
+static int wake_unlock_fd = -1;
+
int wake_lock(char *lock_name) {
int rc;
assert(lock_name != NULL);
- int fd = open("/sys/power/wake_lock", O_RDWR);
- if (fd < 0) {
- return fd;
+ if (wake_lock_fd < 0) {
+ wake_lock_fd = open("/sys/power/wake_lock", O_RDWR);
+ }
+
+ if (wake_lock_fd < 0) {
+ return wake_lock_fd;
}
- rc = write(fd, lock_name, strlen(lock_name));
- close(fd);
+ rc = write(wake_lock_fd, lock_name, strlen(lock_name));
return rc;
}
@@ -41,13 +46,15 @@ int wake_unlock(char *lock_name) {
int rc;
assert(lock_name != NULL);
- int fd = open("/sys/power/wake_unlock", O_RDWR);
- if (fd < 0) {
- return fd;
+ if (wake_unlock_fd < 0) {
+ wake_unlock_fd = open("/sys/power/wake_unlock", O_RDWR);
+ }
+
+ if (wake_unlock_fd < 0) {
+ return wake_lock_fd;
}
- rc = write(fd, lock_name, strlen(lock_name));
- close(fd);
+ rc = write(wake_unlock_fd, lock_name, strlen(lock_name));
return rc;
}