Changeset 22e6802 in mainline


Ignore:
Timestamp:
2009-12-03T17:49:01Z (14 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
65c1778, fbcfc4da
Parents:
4924675
Message:

fix kernel thread_sleep() not to overflow thread_usleep()
introduce useconds_t
unify arguments names, cstyle

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    r4924675 r22e6802  
    501501void thread_sleep(uint32_t sec)
    502502{
    503         thread_usleep(sec * 1000000);
     503        /* Sleep in 1000 second steps to support
     504           full argument range */
     505        while (sec > 0) {
     506                uint32_t period = (sec > 1000) ? 1000 : sec;
     507       
     508                thread_usleep(period * 1000000);
     509                sec -= period;
     510        }
    504511}
    505512
     
    575582{
    576583        waitq_t wq;
    577                                  
     584       
    578585        waitq_initialize(&wq);
    579 
     586       
    580587        (void) waitq_sleep_timeout(&wq, usec, SYNCH_FLAGS_NON_BLOCKING);
    581588}
     
    815822unative_t sys_thread_usleep(uint32_t usec)
    816823{
    817         thread_usleep(usec);   
     824        thread_usleep(usec);
    818825        return 0;
    819826}
  • uspace/lib/libc/generic/time.c

    r4924675 r22e6802  
    3131 */
    3232/** @file
    33  */ 
     33 */
    3434
    3535#include <sys/time.h>
     
    189189
    190190/** Wait unconditionally for specified number of microseconds */
    191 int usleep(unsigned long usec)
    192 {
    193         (void) __SYSCALL1(SYS_THREAD_USLEEP, usec);     
     191int usleep(useconds_t usec)
     192{
     193        (void) __SYSCALL1(SYS_THREAD_USLEEP, usec);
    194194        return 0;
    195195}
    196196
    197197/** Wait unconditionally for specified number of seconds */
    198 unsigned int sleep(unsigned int seconds)
     198unsigned int sleep(unsigned int sec)
    199199{
    200200        /* Sleep in 1000 second steps to support
    201201           full argument range */
    202         while (seconds > 0) {
    203                 unsigned int period = (seconds > 1000) ? 1000 : seconds;
     202        while (sec > 0) {
     203                unsigned int period = (sec > 1000) ? 1000 : sec;
    204204       
    205205                usleep(period * 1000000);
    206                 seconds -= period;
     206                sec -= period;
    207207        }
    208208        return 0;
  • uspace/lib/libc/include/unistd.h

    r4924675 r22e6802  
    5151#endif
    5252
     53typedef uint32_t useconds_t;
     54
    5355extern int dup2(int oldfd, int newfd);
    5456
     
    6870
    6971extern void _exit(int status) __attribute__ ((noreturn));
    70 extern int usleep(unsigned long usec);
    71 extern unsigned int sleep(unsigned int seconds);
     72extern int usleep(useconds_t uses);
     73extern unsigned int sleep(unsigned int se);
    7274
    7375#endif
Note: See TracChangeset for help on using the changeset viewer.