X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;ds=sidebyside;f=Kernel%2Fvfs%2Fselect.c;h=bbca54715d868ef77c77dd407db889c282ad9826;hb=d3359db4d5b4cb6f1c2758dc03e74edf4427a769;hp=22417c882918e0b251fd78fd15eb9a99c63f6631;hpb=54bf151b1a05b74debdb5f3baec02c18406b74d1;p=tpg%2Facess2.git diff --git a/Kernel/vfs/select.c b/Kernel/vfs/select.c index 22417c88..bbca5471 100644 --- a/Kernel/vfs/select.c +++ b/Kernel/vfs/select.c @@ -44,9 +44,9 @@ struct sVFS_SelectThread // int VFS_MarkFull(tVFS_Node *Node, BOOL IsBufferFull); // int VFS_MarkAvaliable(tVFS_Node *Node, BOOL IsDataAvaliable); // int VFS_MarkError(tVFS_Node *Node, BOOL IsErrorState); - int VFS_int_Select_GetType(enum eVFS_SelectTypes Type, tVFS_Node *Node, tVFS_SelectList ***List, int **Flag, int *WantedFlag, int *MaxAllowed); - int VFS_int_Select_Register(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, enum eVFS_SelectTypes Type, BOOL IsKernel); - int VFS_int_Select_Deregister(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, enum eVFS_SelectTypes Type, BOOL IsKernel); + int VFS_int_Select_GetType(int Type, tVFS_Node *Node, tVFS_SelectList ***List, int **Flag, int *WantedFlag, int *MaxAllowed); + int VFS_int_Select_Register(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, int Type, BOOL IsKernel); + int VFS_int_Select_Deregister(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, int Type, BOOL IsKernel); int VFS_int_Select_AddThread(tVFS_SelectList *List, tVFS_SelectThread *Thread, int MaxAllowed); void VFS_int_Select_RemThread(tVFS_SelectList *List, tVFS_SelectThread *Thread); void VFS_int_Select_SignalAll(tVFS_SelectList *List); @@ -54,40 +54,47 @@ void VFS_int_Select_SignalAll(tVFS_SelectList *List); // === GLOBALS === // === FUNCTIONS === -int VFS_SelectNode(tVFS_Node *Node, enum eVFS_SelectTypes Type, tTime *Timeout, const char *Name) +int VFS_SelectNode(tVFS_Node *Node, int TypeFlags, tTime *Timeout, const char *Name) { tVFS_SelectThread *thread_info; - tVFS_SelectList **list; - int *flag, wanted, maxAllowed; - - ENTER("pNode iType pTimeout", Node, Type, Timeout); + int ret, type; - if( VFS_int_Select_GetType(Type, Node, &list, &flag, &wanted, &maxAllowed) ) { - LEAVE('i', -1); - return -1; - } + ENTER("pNode iTypeFlags pTimeout", Node, TypeFlags, Timeout); thread_info = malloc(sizeof(tVFS_SelectThread)); - if(!thread_info) return -1; - + if(!thread_info) LEAVE_RET('i', -1); + Semaphore_Init(&thread_info->SleepHandle, 0, 0, "VFS_SelectNode()", Name); - LOG("list=%p, flag=%p, wanted=%i, maxAllowed=%i", list, flag, wanted, maxAllowed); + // Initialise + for( type = 0; type < 3; type ++ ) + { + tVFS_SelectList **list; + int *flag, wanted, maxAllowed; + if( !(TypeFlags & (1 << type)) ) continue; + if( VFS_int_Select_GetType(type, Node, &list, &flag, &wanted, &maxAllowed) ) { + free(thread_info); + LEAVE('i', -1); + return -1; + } - // Alloc if needed - if( !*list ) { - *list = calloc(1, sizeof(tVFS_SelectList)); - } + // Alloc if needed + if( !*list ) *list = calloc(1, sizeof(tVFS_SelectList)); - VFS_int_Select_AddThread(*list, thread_info, maxAllowed); - if( *flag == wanted ) - { - VFS_int_Select_RemThread(*list, thread_info); - free(thread_info); - LEAVE('i', 1); - return 1; + VFS_int_Select_AddThread(*list, thread_info, maxAllowed); + if( *flag == wanted ) + { + VFS_int_Select_RemThread(*list, thread_info); + free(thread_info); + LEAVE('i', 1); + return 1; + } } - + + // - Fast return for polling + if( Timeout && *Timeout == 0 ) return 0; + + // Wait for things if( !Timeout || *Timeout > 0 ) { LOG("Semaphore_Wait()"); @@ -95,13 +102,23 @@ int VFS_SelectNode(tVFS_Node *Node, enum eVFS_SelectTypes Type, tTime *Timeout, Semaphore_Wait(&thread_info->SleepHandle, 1); } - LOG("VFS_int_Select_RemThread()"); - VFS_int_Select_RemThread(*list, thread_info); + // Get return value + ret = 0; + for( type = 0; type < 3; type ++ ) + { + tVFS_SelectList **list; + int *flag, wanted, maxAllowed; + if( !(TypeFlags & (1 << type)) ) continue; + VFS_int_Select_GetType(type, Node, &list, &flag, &wanted, &maxAllowed); + LOG("VFS_int_Select_RemThread()"); + VFS_int_Select_RemThread(*list, thread_info); + ret = ret || *flag == wanted; + } free(thread_info); - LEAVE('i', *flag == wanted); - return *flag == wanted; + LEAVE('i', ret); + return ret; } int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set *ErrHandles, tTime *Timeout, BOOL IsKernel) @@ -148,7 +165,7 @@ int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set if( !Timeout || *Timeout > 0 ) { ret = Semaphore_Wait(&thread_info->SleepHandle, 1); - // TODO: Do something with ret + // TODO: Do something with ret? } // Fill output (modify *Handles) @@ -195,7 +212,7 @@ int VFS_MarkError(tVFS_Node *Node, BOOL IsErrorState) } // --- Internal --- -int VFS_int_Select_GetType(enum eVFS_SelectTypes Type, tVFS_Node *Node, tVFS_SelectList ***List, int **Flag, int *WantedFlag, int *MaxAllowed) +int VFS_int_Select_GetType(int Type, tVFS_Node *Node, tVFS_SelectList ***List, int **Flag, int *WantedFlag, int *MaxAllowed) { // Get the type of the listen switch(Type) @@ -228,7 +245,7 @@ int VFS_int_Select_GetType(enum eVFS_SelectTypes Type, tVFS_Node *Node, tVFS_Sel /** * \return Number of files with an action */ -int VFS_int_Select_Register(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, enum eVFS_SelectTypes Type, BOOL IsKernel) +int VFS_int_Select_Register(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, int Type, BOOL IsKernel) { int i, numFlagged = 0; tVFS_SelectList **list; @@ -290,7 +307,7 @@ int VFS_int_Select_Register(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Ha /** * \return Number of files with an action */ -int VFS_int_Select_Deregister(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, enum eVFS_SelectTypes Type, BOOL IsKernel) +int VFS_int_Select_Deregister(tVFS_SelectThread *Thread, int MaxHandle, fd_set *Handles, int Type, BOOL IsKernel) { int i, numFlagged = 0; tVFS_SelectList **list; @@ -413,7 +430,7 @@ int VFS_int_Select_AddThread(tVFS_SelectList *List, tVFS_SelectThread *Thread, i void VFS_int_Select_RemThread(tVFS_SelectList *List, tVFS_SelectThread *Thread) { int i; - tVFS_SelectListEnt *block, *prev; + tVFS_SelectListEnt *block, *prev = NULL; ENTER("pList pThread", List, Thread); @@ -486,9 +503,9 @@ void VFS_int_Select_SignalAll(tVFS_SelectList *List) { for( i = 0; i < NUM_THREADS_PER_ALLOC; i ++ ) { - LOG("block->Threads[i] = %p", block->Threads[i]); if( block->Threads[i] ) { + LOG("block(%p)->Threads[%i] = %p", block, i, block->Threads[i]); Semaphore_Signal( &block->Threads[i]->SleepHandle, 1 ); } }