From: John Hodge Date: Fri, 18 May 2012 09:24:12 +0000 (+0800) Subject: Kernel/VFS - Added timeouts to select X-Git-Tag: rel0.15~611^2~100^2~3 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=a0876f497f430c5addfef746f6f8e9a22259097e;p=tpg%2Facess2.git Kernel/VFS - Added timeouts to select --- diff --git a/KernelLand/Kernel/drv/vterm_font_8x16.h b/KernelLand/Kernel/drv/vterm_font_8x16.h index 7c613325..b3ff127a 100644 --- a/KernelLand/Kernel/drv/vterm_font_8x16.h +++ b/KernelLand/Kernel/drv/vterm_font_8x16.h @@ -1,5 +1,6 @@ /* * Taken from http://cvs.savannah.gnu.org/viewvc/vgabios/vgafonts.h?root=vgabios&view=markup + * Font is public domain * Altered for Acess2 */ #define FONT_WIDTH 8 diff --git a/KernelLand/Kernel/vfs/select.c b/KernelLand/Kernel/vfs/select.c index d2ef8082..c34700c8 100644 --- a/KernelLand/Kernel/vfs/select.c +++ b/KernelLand/Kernel/vfs/select.c @@ -16,6 +16,7 @@ #include #include #include +#include // === CONSTANTS === #define NUM_THREADS_PER_ALLOC 4 @@ -83,16 +84,25 @@ int VFS_SelectNode(tVFS_Node *Node, int TypeFlags, tTime *Timeout, const char *N } } - // - Fast return for polling - if( Timeout && *Timeout == 0 ) return 0; - // Wait for things - if( !Timeout || *Timeout > 0 ) + if( !Timeout ) { LOG("Semaphore_Wait()"); // TODO: Actual timeout Threads_WaitEvents( THREAD_EVENT_VFS ); } + else if( *Timeout > 0 ) + { + tTimer *t = Time_AllocateTimer(NULL, NULL); + // Clear timer event + Threads_ClearEvent( THREAD_EVENT_TIMER ); + // TODO: Convert *Timeout? + LOG("Timeout %lli ms", *Timeout); + Time_ScheduleTimer( t, *Timeout ); + // Wait for the timer or a VFS event + Threads_WaitEvents( THREAD_EVENT_VFS|THREAD_EVENT_TIMER ); + Time_FreeTimer(t); + } // Get return value ret = 0; @@ -106,6 +116,9 @@ int VFS_SelectNode(tVFS_Node *Node, int TypeFlags, tTime *Timeout, const char *N VFS_int_Select_RemThread(*list, thisthread); ret = ret || *flag == wanted; } + + Threads_ClearEvent( THREAD_EVENT_VFS ); + Threads_ClearEvent( THREAD_EVENT_TIMER ); LEAVE('i', ret); return ret; @@ -142,23 +155,35 @@ int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set LEAVE('i', ret); return ret; } - - // TODO: Implement timeout - LOG("Timeout = %p", Timeout); - - // Wait (only if there is no timeout, or it is greater than zero - if( !Timeout || *Timeout > 0 ) + + // Wait for things + if( !Timeout ) { - // TODO: Timeout - // TODO: Allow extra events to be waited upon + LOG("Semaphore_Wait()"); + // TODO: Actual timeout Threads_WaitEvents( THREAD_EVENT_VFS|ExtraEvents ); } - + else if( *Timeout > 0 ) + { + tTimer *t = Time_AllocateTimer(NULL, NULL); + // Clear timer event + Threads_ClearEvent( THREAD_EVENT_TIMER ); + // TODO: Convert *Timeout? + LOG("Timeout %lli ms", *Timeout); + Time_ScheduleTimer( t, *Timeout ); + // Wait for the timer or a VFS event + Threads_WaitEvents( THREAD_EVENT_VFS|THREAD_EVENT_TIMER|ExtraEvents ); + Time_FreeTimer(t); + } // Fill output (modify *Handles) // - Also, de-register ret = VFS_int_Select_Deregister(thisthread, MaxHandle, ReadHandles, 0, IsKernel); ret += VFS_int_Select_Deregister(thisthread, MaxHandle, WriteHandles, 1, IsKernel); ret += VFS_int_Select_Deregister(thisthread, MaxHandle, ErrHandles, 2, IsKernel); + + Threads_ClearEvent( THREAD_EVENT_VFS ); + Threads_ClearEvent( THREAD_EVENT_TIMER ); + LEAVE('i', ret); return ret; }