[IMPROVE] Add ioctl wake up command
authorAlexander Aksenov <a.aksenov@samsung.com>
Thu, 26 Sep 2013 13:34:47 +0000 (17:34 +0400)
committerAlexander Aksenov <a.aksenov@samsung.com>
Thu, 26 Sep 2013 14:40:08 +0000 (18:40 +0400)
Prevents joining sleeping thread

Change-Id: Ie414de362d8e532a6711acde935ca4306a92b1be
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
daemon/buffer.c
daemon/buffer.h
daemon/ioctl_commands.h
daemon/transfer_thread.c

index 2c988e3f7ea6f32ed1e3db930ceddf2631bc9469..8a62bc27c0370656e6d583ba0188bad492508397 100644 (file)
@@ -108,6 +108,12 @@ void flush_buf(void)
                LOGW("Cannot flush buffer: %s\n", strerror(errno));
 }
 
+void wake_up_buf(void)
+{
+       if (ioctl(manager.buf_fd, SWAP_DRIVER_WAKE_UP) == -1)
+               LOGW("Cannot wake up buffer: %s\n", strerror(errno));
+}
+
 int write_to_buf(struct msg_data_t *msg)
 {
        if (write(manager.buf_fd, msg, MSG_DATA_HDR_LEN + msg->len) == -1) {
index 176bf346cfa44be3425dc7e78e549d92bd9447e6..66e470fe05e19477957f657f2ed6cc6bf5d264f7 100644 (file)
@@ -36,6 +36,7 @@
 int init_buf(void);
 void exit_buf(void);
 void flush_buf(void);
+void wake_up_buf(void);
 int write_to_buf(struct msg_data_t *msg);
 
 #endif /* _BUFFER_ */
index 2e314ba44de67d3a6a58501524db49a39f1db3c7..72305633bc762d77bbb29e893f1cb56c8d092f86 100644 (file)
@@ -48,6 +48,7 @@ struct buffer_initialize {
 #define SWAP_DRIVER_FLUSH_BUFFER                       _IO(SWAP_DRIVER_IOC_MAGIC, 4)
 #define SWAP_DRIVER_MSG                                                _IOW(SWAP_DRIVER_IOC_MAGIC, 5, \
                                                                                     void *)
+#define SWAP_DRIVER_WAKE_UP                             _IO(SWAP_DRIVER_IOC_MAGIC, 6)
 
 
 int ioctl_send_msg(struct msg_t *msg);
index 5e8dea7822718eed621adb1243e727e2f87aef51..9e048f1dbbc32e33f3c1f77580b83244faa61b07 100644 (file)
@@ -130,13 +130,10 @@ int start_transfer()
        return 0;
 }
 
-#define SECS_TO_FORCE_STOP 10
 void stop_transfer()
 {
        int saved_flags;
        int ret = 0;
-       struct timeval tv;
-       struct timespec ts;
 
        if (manager.transfer_thread == -1) {
                LOGI("transfer thread not running\n");
@@ -147,19 +144,12 @@ void stop_transfer()
        flush_buf();
        saved_flags = fcntl(manager.buf_fd, F_GETFL);
        fcntl(manager.buf_fd, F_SETFL, saved_flags | O_NONBLOCK);
+       wake_up_buf();
 
-       gettimeofday(&tv, NULL);
-       ts.tv_sec = tv.tv_sec + SECS_TO_FORCE_STOP;
-       ts.tv_nsec = tv.tv_usec * 1000;
-       ret = pthread_timedjoin_np(manager.transfer_thread, NULL, &ts);
-       if (ret == ETIMEDOUT) {
-               LOGW("transfer thread is not joined in %d sec, force stop\n",
-                       SECS_TO_FORCE_STOP);
-               ret = pthread_cancel(manager.transfer_thread);
-               if (ret == ESRCH)
-                       LOGW("no transfer thread to force stop\n");
-       } else if (ret != 0)
-               LOGW("pthread_timedjoin_np: unknown error %d\n", ret);
+       LOGI("joining thread...\n");
+       ret = pthread_join(manager.transfer_thread, NULL);
+       if (ret != 0)
+               LOGW("pthread_join: unknown error %d\n", ret);
 
        manager.transfer_thread = -1;