Rev | Line | |
---|
[176] | 1 | /* |
---|
| 2 | * swift_backoff.c |
---|
| 3 | * |
---|
| 4 | * (c) 2009 Ionut Rosoiu <ionut.rosoiu@gmail.com> |
---|
| 5 | * |
---|
| 6 | */ |
---|
| 7 | |
---|
| 8 | #include "swift_backoff.h" |
---|
| 9 | #include "swift_log.h" |
---|
| 10 | #define _POSIX_C_SOURCE 199309L |
---|
| 11 | #include <time.h> |
---|
| 12 | |
---|
| 13 | void swift_backoff(swift_thread_t *thread) { |
---|
| 14 | struct timespec req, rem; |
---|
| 15 | |
---|
| 16 | //TODO: limit backoff (or cycle) |
---|
| 17 | req.tv_sec = 0; |
---|
| 18 | req.tv_nsec = thread->last_sleep_time; |
---|
| 19 | |
---|
| 20 | while (nanosleep(&req, &rem) == -1) { |
---|
| 21 | req = rem; |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | thread->last_sleep_time = (thread->last_sleep_time << 1) % 100L; |
---|
| 25 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.