Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset d9ece1cb in mainline


Ignore:
Timestamp:
2009-12-01T20:08:32Z (11 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
Children:
d359e227
Parents:
d52b82ad
Message:

Introduce SYS_THREAD_USLEEP and use it to implement usleep() in uspace.

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/include/proc/thread.h

    rd52b82ad rd9ece1cb  
    263263extern unative_t sys_thread_exit(int);
    264264extern unative_t sys_thread_get_id(thread_id_t *);
     265extern unative_t sys_thread_usleep(uint32_t);
    265266
    266267#endif
  • kernel/generic/include/syscall/syscall.h

    rd52b82ad rd9ece1cb  
    4343        SYS_THREAD_EXIT,
    4444        SYS_THREAD_GET_ID,
     45        SYS_THREAD_USLEEP,
    4546       
    4647        SYS_TASK_GET_ID,
  • kernel/generic/src/proc/thread.c

    rd52b82ad rd9ece1cb  
    812812}
    813813
     814/** Syscall wrapper for sleeping. */
     815unative_t sys_thread_usleep(uint32_t usec)
     816{
     817        thread_usleep(usec);   
     818        return 0;
     819}
     820
    814821/** @}
    815822 */
  • kernel/generic/src/syscall/syscall.c

    rd52b82ad rd9ece1cb  
    111111        (syshandler_t) sys_thread_exit,
    112112        (syshandler_t) sys_thread_get_id,
     113        (syshandler_t) sys_thread_usleep,
    113114       
    114115        (syshandler_t) sys_task_get_id,
  • uspace/lib/libc/generic/time.c

    rd52b82ad rd9ece1cb  
    4040#include <unistd.h>
    4141#include <atomic.h>
    42 #include <futex.h>
    4342#include <sysinfo.h>
    4443#include <ipc/services.h>
     44#include <libc.h>
    4545
    4646#include <sysinfo.h>
     
    191191int usleep(unsigned long usec)
    192192{
    193         atomic_t futex = FUTEX_INITIALIZER;
    194 
    195         futex_initialize(&futex, 0);
    196         futex_down_timeout(&futex, usec, 0);
     193        (void) __SYSCALL1(SYS_THREAD_USLEEP, usec);     
    197194        return 0;
    198195}
     
    201198unsigned int sleep(unsigned int seconds)
    202199{
    203         atomic_t futex = FUTEX_INITIALIZER;
    204 
    205         futex_initialize(&futex, 0);
    206        
    207200        /* Sleep in 1000 second steps to support
    208201           full argument range */
     
    210203                unsigned int period = (seconds > 1000) ? 1000 : seconds;
    211204       
    212                 futex_down_timeout(&futex, period * 1000000, 0);
     205                usleep(period * 1000000);
    213206                seconds -= period;
    214207        }
Note: See TracChangeset for help on using the changeset viewer.