add set-priority and get-priority

add clear_err_no and check-errno for dealing with get-priority
db4
Doug Coleman 2008-03-21 14:53:11 -05:00
parent 17356ece95
commit 9c745c44d3
7 changed files with 37 additions and 1 deletions

View File

@ -0,0 +1,5 @@
USING: io.backend kernel ;
IN: io.priority
HOOK: get-priority io-backend ( -- n )
HOOK: set-priority io-backend ( n -- )

View File

@ -72,6 +72,9 @@ M: mx unregister-io-task ( task mx -- )
: (io-error) ( -- * ) err_no strerror throw ; : (io-error) ( -- * ) err_no strerror throw ;
: check-errno ( -- )
err_no dup zero? [ drop ] [ strerror throw ] if ;
: check-null ( n -- ) zero? [ (io-error) ] when ; : check-null ( n -- ) zero? [ (io-error) ] when ;
: io-error ( n -- ) 0 < [ (io-error) ] when ; : io-error ( n -- ) 0 < [ (io-error) ] when ;

View File

@ -0,0 +1,21 @@
USING: alien.syntax kernel io.priority io.unix.backend
unix ;
IN: io.unix.priority
: PRIO_PROCESS 0 ; inline
: PRIO_PGRP 1 ; inline
: PRIO_USER 2 ; inline
: PRIO_MIN -20 ; inline
: PRIO_MAX 20 ; inline
! which/who = 0 for current process
FUNCTION: int getpriority ( int which, int who ) ;
FUNCTION: int setpriority ( int which, int who, int prio ) ;
M: unix-io get-priority ( -- n )
clear_err_no
0 0 getpriority dup -1 = [ check-errno ] when ;
M: unix-io set-priority ( n -- )
0 0 rot setpriority io-error ;

View File

@ -1,5 +1,5 @@
USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts USING: io.unix.backend io.unix.files io.unix.sockets io.timeouts
io.unix.launcher io.unix.mmap io.backend io.unix.launcher io.unix.mmap io.backend io.priority
combinators namespaces system vocabs.loader sequences ; combinators namespaces system vocabs.loader sequences ;
"io.unix." os append require "io.unix." os append require

View File

@ -27,6 +27,7 @@ TYPEDEF: ulong size_t
! ! ! Unix functions ! ! ! Unix functions
LIBRARY: factor LIBRARY: factor
FUNCTION: int err_no ( ) ; FUNCTION: int err_no ( ) ;
FUNCTION: void clear_err_no ( ) ;
LIBRARY: libc LIBRARY: libc

View File

@ -194,3 +194,8 @@ int err_no(void)
{ {
return errno; return errno;
} }
void clear_err_no(void)
{
errno = 0;
}

View File

@ -1,6 +1,7 @@
void init_c_io(void); void init_c_io(void);
void io_error(void); void io_error(void);
int err_no(void); int err_no(void);
void clear_err_no(void);
DECLARE_PRIMITIVE(fopen); DECLARE_PRIMITIVE(fopen);
DECLARE_PRIMITIVE(fgetc); DECLARE_PRIMITIVE(fgetc);