X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=task-utils.c;h=12b00027a2bae479f130252b501cd1dfd5104727;hb=6bcb03dda1f92ee50819748edb55c5a99820b1ed;hp=10e3f0fc6b4db6495bbdcb2d51cdce4182e9074c;hpb=48e06b7fa46f70b9f9f8093ebd76c09cf93c1cbf;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/task-utils.c b/task-utils.c index 10e3f0f..12b0002 100644 --- a/task-utils.c +++ b/task-utils.c @@ -50,10 +50,8 @@ int task_start(struct task_info *info) ret = pthread_create(&info->id, NULL, info->threadfn, info->private_data); - if (ret == 0) - pthread_detach(info->id); - else - info->id = -1; + if (ret) + info->id = 0; return ret; } @@ -63,11 +61,16 @@ void task_stop(struct task_info *info) if (!info) return; - if (info->periodic.timer_fd) - close(info->periodic.timer_fd); - - if (info->id > 0) + if (info->id > 0) { pthread_cancel(info->id); + pthread_join(info->id, NULL); + info->id = 0; + } + + if (info->periodic.timer_fd) { + close(info->periodic.timer_fd); + info->periodic.timer_fd = 0; + } if (info->postfn) info->postfn(info->private_data); @@ -91,8 +94,10 @@ int task_period_start(struct task_info *info, unsigned int period_ms) return -1; info->periodic.timer_fd = timerfd_create(CLOCK_MONOTONIC, 0); - if (info->periodic.timer_fd == -1) + if (info->periodic.timer_fd == -1) { + info->periodic.timer_fd = 0; return info->periodic.timer_fd; + } info->periodic.wakeups_missed = 0; @@ -114,6 +119,9 @@ void task_period_wait(struct task_info *info) if (!info) return; + if (info->periodic.timer_fd == 0) + return; + ret = read(info->periodic.timer_fd, &missed, sizeof (missed)); if (ret == -1) return; @@ -130,5 +138,6 @@ void task_period_stop(struct task_info *info) if (info->periodic.timer_fd) { timerfd_settime(info->periodic.timer_fd, 0, NULL, NULL); close(info->periodic.timer_fd); + info->periodic.timer_fd = -1; } }