Changeset 9a99aa5 in mainline


Ignore:
Timestamp:
2017-05-30T19:35:46Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
316795c
Parents:
134e3f1
Message:

Fibrils need sleep, too.

Location:
uspace/lib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/fibril_synch.c

    r134e3f1 r9a99aa5  
    629629}
    630630
     631/** Delay fibril execution for the specified number of microseconds
     632 *
     633 * @param usec Number of microseconds to sleep
     634 */
     635void fibril_usleep(useconds_t usec)
     636{
     637        fibril_condvar_t cv;
     638        fibril_mutex_t lock;
     639
     640        fibril_condvar_initialize(&cv);
     641        fibril_mutex_initialize(&lock);
     642        fibril_mutex_lock(&lock);
     643        fibril_condvar_wait_timeout(&cv, &lock, usec);
     644        fibril_mutex_unlock(&lock);
     645}
     646
     647/** Delay fibril execution for the specified number of seconds
     648 *
     649 * @param sec Number of seconds to sleep
     650 */
     651void fibril_sleep(unsigned int sec)
     652{
     653        /*
     654         * Sleep in 1000 second steps to support
     655         * full argument range
     656         */
     657
     658        while (sec > 0) {
     659                unsigned int period = (sec > 1000) ? 1000 : sec;
     660
     661                fibril_usleep(period * 1000000);
     662                sec -= period;
     663        }
     664}
     665
     666
    631667/** @}
    632668 */
  • uspace/lib/c/include/fibril_synch.h

    r134e3f1 r9a99aa5  
    173173extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
    174174extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *);
     175extern void fibril_usleep(useconds_t);
     176extern void fibril_sleep(unsigned int);
    175177
    176178#endif
  • uspace/lib/posix/source/time.c

    r134e3f1 r9a99aa5  
    4545#include "posix/assert.h"
    4646
     47#include "libc/fibril_synch.h"
    4748#include "libc/malloc.h"
    4849#include "libc/task.h"
     
    5051#include "libc/stdbool.h"
    5152#include "libc/stddef.h"
    52 #include "libc/thread.h"
    5353#include "libc/sys/time.h"
    5454
     
    315315                        // TODO: interruptible sleep
    316316                        if (rqtp->tv_sec != 0) {
    317                                 thread_sleep(rqtp->tv_sec);
     317                                fibril_sleep(rqtp->tv_sec);
    318318                        }
    319319                        if (rqtp->tv_nsec != 0) {
    320                                 thread_usleep(rqtp->tv_nsec / 1000);
     320                                fibril_usleep(rqtp->tv_nsec / 1000);
    321321                        }
    322322                        return 0;
Note: See TracChangeset for help on using the changeset viewer.