Changeset bd41ac52 in mainline for uspace/lib/c/generic/thread
- Timestamp:
- 2018-08-25T22:21:25Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cca80a2
- Parents:
- e2625b1a
- Location:
- uspace/lib/c/generic/thread
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/thread/fibril.c
re2625b1a rbd41ac52 60 60 typedef struct { 61 61 link_t link; 62 struct time valexpires;62 struct timespec expires; 63 63 fibril_event_t *event; 64 64 } _timeout_t; … … 142 142 } 143 143 144 static inline errno_t _ready_down(const struct time val*expires)144 static inline errno_t _ready_down(const struct timespec *expires) 145 145 { 146 146 if (multithreaded) … … 253 253 } 254 254 255 static errno_t _ipc_wait(ipc_call_t *call, const struct time val*expires)255 static errno_t _ipc_wait(ipc_call_t *call, const struct timespec *expires) 256 256 { 257 257 if (!expires) … … 261 261 return ipc_wait(call, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); 262 262 263 struct time valnow;263 struct timespec now; 264 264 getuptime(&now); 265 265 266 if (t v_gteq(&now, expires))266 if (ts_gteq(&now, expires)) 267 267 return ipc_wait(call, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NON_BLOCKING); 268 268 269 return ipc_wait(call, tv_sub_diff(expires, &now), SYNCH_FLAGS_NONE); 269 return ipc_wait(call, NSEC2USEC(ts_sub_diff(expires, &now)), 270 SYNCH_FLAGS_NONE); 270 271 } 271 272 … … 275 276 * wait after new ready fibrils are added. 276 277 */ 277 static fibril_t *_ready_list_pop(const struct time val*expires, bool locked)278 static fibril_t *_ready_list_pop(const struct timespec *expires, bool locked) 278 279 { 279 280 if (locked) { … … 370 371 static fibril_t *_ready_list_pop_nonblocking(bool locked) 371 372 { 372 struct time val tv = { .tv_sec = 0, .tv_usec = 0 };373 struct timespec tv = { .tv_sec = 0, .tv_nsec = 0 }; 373 374 return _ready_list_pop(&tv, locked); 374 375 } … … 393 394 394 395 /* Blocks the current fibril until an IPC call arrives. */ 395 static errno_t _wait_ipc(ipc_call_t *call, const struct time val*expires)396 static errno_t _wait_ipc(ipc_call_t *call, const struct timespec *expires) 396 397 { 397 398 futex_assert_is_not_locked(&fibril_futex); … … 430 431 431 432 /** Fire all timeouts that expired. */ 432 static struct time val *_handle_expired_timeouts(struct timeval*next_timeout)433 { 434 struct time val tv;435 getuptime(&t v);433 static struct timespec *_handle_expired_timeouts(struct timespec *next_timeout) 434 { 435 struct timespec ts; 436 getuptime(&ts); 436 437 437 438 futex_lock(&fibril_futex); … … 441 442 _timeout_t *to = list_get_instance(cur, _timeout_t, link); 442 443 443 if (t v_gt(&to->expires, &tv)) {444 if (ts_gt(&to->expires, &ts)) { 444 445 *next_timeout = to->expires; 445 446 futex_unlock(&fibril_futex); … … 535 536 (void) arg; 536 537 537 struct time valnext_timeout;538 struct timespec next_timeout; 538 539 while (true) { 539 struct time val*to = _handle_expired_timeouts(&next_timeout);540 struct timespec *to = _handle_expired_timeouts(&next_timeout); 540 541 fibril_t *f = _ready_list_pop(to, false); 541 542 if (f) { … … 615 616 _timeout_t *cur = list_get_instance(tmp, _timeout_t, link); 616 617 617 if (t v_gteq(&cur->expires, &timeout->expires))618 if (ts_gteq(&cur->expires, &timeout->expires)) 618 619 break; 619 620 … … 634 635 * @return ETIMEOUT if timed out. EOK otherwise. 635 636 */ 636 errno_t fibril_wait_timeout(fibril_event_t *event, const struct timeval *expires) 637 errno_t fibril_wait_timeout(fibril_event_t *event, 638 const struct timespec *expires) 637 639 { 638 640 assert(fibril_self()->rmutex_locks == 0); … … 889 891 } 890 892 891 void fibril_usleep( suseconds_t timeout)892 { 893 struct time valexpires;893 void fibril_usleep(usec_t timeout) 894 { 895 struct timespec expires; 894 896 getuptime(&expires); 895 t v_add_diff(&expires, timeout);897 ts_add_diff(&expires, USEC2NSEC(timeout)); 896 898 897 899 fibril_event_t event = FIBRIL_EVENT_INIT; … … 899 901 } 900 902 901 void fibril_sleep( unsigned int sec)902 { 903 struct time valexpires;903 void fibril_sleep(sec_t sec) 904 { 905 struct timespec expires; 904 906 getuptime(&expires); 905 907 expires.tv_sec += sec; … … 916 918 } 917 919 918 errno_t fibril_ipc_wait(ipc_call_t *call, const struct time val*expires)920 errno_t fibril_ipc_wait(ipc_call_t *call, const struct timespec *expires) 919 921 { 920 922 return _wait_ipc(call, expires); -
uspace/lib/c/generic/thread/fibril_synch.c
re2625b1a rbd41ac52 37 37 #include <async.h> 38 38 #include <adt/list.h> 39 #include < sys/time.h>39 #include <time.h> 40 40 #include <errno.h> 41 41 #include <assert.h> … … 390 390 errno_t 391 391 fibril_condvar_wait_timeout(fibril_condvar_t *fcv, fibril_mutex_t *fm, 392 suseconds_t timeout)392 usec_t timeout) 393 393 { 394 394 assert(fibril_mutex_is_locked(fm)); … … 400 400 wdata.mutex = fm; 401 401 402 struct time val tv;403 struct time val*expires = NULL;402 struct timespec ts; 403 struct timespec *expires = NULL; 404 404 if (timeout) { 405 getuptime(&t v);406 t v_add_diff(&tv, timeout);407 expires = &t v;405 getuptime(&ts); 406 ts_add_diff(&ts, USEC2NSEC(timeout)); 407 expires = &ts; 408 408 } 409 409 … … 557 557 * @param arg Argument for @a fun 558 558 */ 559 void fibril_timer_set(fibril_timer_t *timer, suseconds_t delay,559 void fibril_timer_set(fibril_timer_t *timer, usec_t delay, 560 560 fibril_timer_fun_t fun, void *arg) 561 561 { … … 575 575 * @param arg Argument for @a fun 576 576 */ 577 void fibril_timer_set_locked(fibril_timer_t *timer, suseconds_t delay,577 void fibril_timer_set_locked(fibril_timer_t *timer, usec_t delay, 578 578 fibril_timer_fun_t fun, void *arg) 579 579 { … … 728 728 } 729 729 730 errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *sem, suseconds_t timeout)730 errno_t fibril_semaphore_down_timeout(fibril_semaphore_t *sem, usec_t timeout) 731 731 { 732 732 if (timeout < 0) … … 751 751 futex_unlock(&fibril_synch_futex); 752 752 753 struct time val tv;754 struct time val*expires = NULL;753 struct timespec ts; 754 struct timespec *expires = NULL; 755 755 if (timeout) { 756 getuptime(&t v);757 t v_add_diff(&tv, timeout);758 expires = &t v;756 getuptime(&ts); 757 ts_add_diff(&ts, USEC2NSEC(timeout)); 758 expires = &ts; 759 759 } 760 760 -
uspace/lib/c/generic/thread/mpsc.c
re2625b1a rbd41ac52 146 146 * there is no message left in the queue. 147 147 */ 148 errno_t mpsc_receive(mpsc_t *q, void *b, const struct time val*expires)148 errno_t mpsc_receive(mpsc_t *q, void *b, const struct timespec *expires) 149 149 { 150 150 mpsc_node_t *n; -
uspace/lib/c/generic/thread/thread.c
re2625b1a rbd41ac52 176 176 * 177 177 */ 178 int thread_usleep(useconds_t usec)178 void thread_usleep(usec_t usec) 179 179 { 180 180 (void) __SYSCALL1(SYS_THREAD_USLEEP, usec); 181 return 0;182 181 } 183 182 … … 185 184 * 186 185 */ 187 unsigned int thread_sleep(unsigned int sec)186 void thread_sleep(sec_t sec) 188 187 { 189 188 /* 190 * Sleep in 1000 second steps to support 191 * full argument range 189 * Sleep in 1000 second steps to support full argument range 192 190 */ 193 194 191 while (sec > 0) { 195 192 unsigned int period = (sec > 1000) ? 1000 : sec; 196 193 197 thread_usleep( period * 1000000);194 thread_usleep(SEC2USEC(period)); 198 195 sec -= period; 199 196 } 200 201 return 0;202 197 } 203 198
Note:
See TracChangeset
for help on using the changeset viewer.