diff options
author | Luo Jinghua <sunmoon1997@gmail.com> | 2013-01-15 14:46:10 +0800 |
---|---|---|
committer | Luo Jinghua <sunmoon1997@gmail.com> | 2013-01-15 14:46:10 +0800 |
commit | fe8aca1c74b98f424eaaad330d9d824d4c2a1e92 (patch) | |
tree | 15cf5f52d7794b47a8b58d4e3c8a5dbf58ff3057 /src | |
parent | bac0b2d546db5ef1cdd474d6bb42029fdcd1e205 (diff) |
Replace usleep with select
usleep interacts with signals which is not safe with multi-threads.
Diffstat (limited to 'src')
-rw-r--r-- | src/threads_posix.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/threads_posix.cpp b/src/threads_posix.cpp index 3e8efd2..57f7b00 100644 --- a/src/threads_posix.cpp +++ b/src/threads_posix.cpp @@ -2,6 +2,8 @@ #include <unistd.h> #include <pthread.h> #include <sys/time.h> +#include <sys/select.h> +#include <sys/types.h> #include "threads.h" #include "utility.h" @@ -81,8 +83,11 @@ namespace audiere { int seconds = milliseconds / 1000; int useconds = (milliseconds % 1000) * 1000; - sleep(seconds); - usleep(useconds); + struct timeval tv; + + tv.tv_sec = seconds; + tv.tv_usec = useconds; + select(0, 0, 0, 0, &tv); } |