コード例 #1
0
ファイル: locks.c プロジェクト: jaw0/osj5
int
sync_tlock(lock_t* p, const char *wname, int timeout){
    if(!wname) wname = "lock";

    while(1){
        asleep( (void*)p, wname );
        if( !sync_lockedp(p) && sync_try_lock(p) ){
            aunsleep();
            return 1;
        }
        int t = await( -1, timeout );
        if( t ) break; /* time out */
    }

    return 0;
}
コード例 #2
0
/* output a char */
int
serial_putchar(FILE *f, char ch){
    /* outputs a char over the serial line */
    int i;
    struct Com *p;
    int plx;

    p = (struct Com*)f->d;
    USART_TypeDef *addr = p->addr;

#ifdef USE_PROC
    if( f->flags & F_NONBLOCK ){
        while(1){
            plx = spltty();
            if( addr->ISR & SR_TXE ) break;
        }
    }else{
        while(1){
            plx = splproc();
            asleep( addr, "com/o" );
            if( addr->ISR & SR_TXE ) break;
            addr->CR1 |= 0x80;	/* enable TXE irq */
            await( -1, 100000 );
            if( addr->ISR & SR_TXE ) break;
        }
        aunsleep();
    }
#else
    while(1){
        plx = spltty();
        if( addr->ISR & SR_TXE ) break;
    }

#endif

    addr->TDR = ch;
    splx(plx);

    return 1;
}