From d9aa13b78d35a9460c5ea1ab260ae3470a551607 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sun, 27 Feb 2011 22:37:54 +0800 Subject: [PATCH] Kernel - Some rational comments to select --- Kernel/vfs/select.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Kernel/vfs/select.c b/Kernel/vfs/select.c index 46d6f39f..3cb0af2f 100644 --- a/Kernel/vfs/select.c +++ b/Kernel/vfs/select.c @@ -58,6 +58,15 @@ int VFS_Select(int MaxHandle, fd_set *ReadHandles, fd_set *WriteHandles, fd_set tVFS_SelectThread thread_info; int ret; + Semaphore_Init(&thread_info.SleepHandle, 0, 0, "VFS_Select()", ""); + + // Notes: The idea is to make sure we onlt enter wait (on the semaphore) + // if we are going to be woken up (either by an event at a later time, + // or by an event that happened while or before we were registering). + // Hence, register must happen _before_ we check the state flag + // (See VFS_int_Select_Register), that way either we pick up the flag, + // or the semaphore is incremeneted (or both, but never none) + // Register with nodes ret = VFS_int_Select_Register(&thread_info, MaxHandle, ReadHandles, 0, IsKernel); ret += VFS_int_Select_Register(&thread_info, MaxHandle, WriteHandles, 1, IsKernel); -- 2.20.1