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;
}
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);
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;
if (!info)
return;
+ if (info->periodic.timer_fd == 0)
+ return;
+
ret = read(info->periodic.timer_fd, &missed, sizeof (missed));
- if (ret == -1) {
- perror("read timer");
+ if (ret == -1)
return;
- }
if (missed > 0)
info->periodic.wakeups_missed += (missed - 1);
if (info->periodic.timer_fd) {
timerfd_settime(info->periodic.timer_fd, 0, NULL, NULL);
close(info->periodic.timer_fd);
+ info->periodic.timer_fd = -1;
}
}