From 9875a661bb960d329f992f1f63ef5c6241f63135 Mon Sep 17 00:00:00 2001 From: Alexander Tarasikov Date: Mon, 20 Aug 2012 14:12:20 +0400 Subject: Use static wakelock file descriptors --- samsung-ipc/wakelock.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'samsung-ipc') 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 #include +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; } -- cgit v1.1