From d6c01bce648eee3582c3111baa841fda261efa1a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Tue, 21 Sep 2010 06:40:41 +0000 Subject: [PATCH] [LWIP] - Don't call KeSetEvent while holding a spin lock (thanks to lassy for pointing it out) - Don't advance to the next list entry because we are using ExInterlockedRemoveHeadList - A couple more small code improvements svn path=/branches/tcp-rewrite-branch/; revision=48841 --- lib/drivers/lwip/src/sys_arch.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/drivers/lwip/src/sys_arch.c b/lib/drivers/lwip/src/sys_arch.c index 3692b2cefcb..d5767a7f28b 100755 --- a/lib/drivers/lwip/src/sys_arch.c +++ b/lib/drivers/lwip/src/sys_arch.c @@ -58,12 +58,14 @@ sys_arch_decl_protect(sys_prot_t *lev) sys_sem_t sys_sem_new(u8_t count) { - sys_sem_t sem = ExAllocatePool(NonPagedPool, sizeof(KEVENT)); - if (!sem) - return SYS_SEM_NULL; + sys_sem_t sem; ASSERT(count == 0 || count == 1); + sem = ExAllocatePool(NonPagedPool, sizeof(KEVENT)); + if (!sem) + return SYS_SEM_NULL; + /* It seems lwIP uses the semaphore implementation as either a completion event or a lock * so I optimize for this case by using a synchronization event and setting its initial state * to signalled for a lock and non-signalled for a completion event */ @@ -155,19 +157,17 @@ void sys_mbox_post(sys_mbox_t mbox, void *msg) { PLWIP_MESSAGE_CONTAINER Container; - KIRQL OldIrql; Container = ExAllocatePool(NonPagedPool, sizeof(*Container)); ASSERT(Container); Container->Message = msg; - KeAcquireSpinLock(&mbox->Lock, &OldIrql); - InsertTailList(&mbox->ListHead, - &Container->ListEntry); + ExInterlockedInsertTailList(&mbox->ListHead, + &Container->ListEntry, + &mbox->Lock); KeSetEvent(&mbox->Event, IO_NO_INCREMENT, FALSE); - KeReleaseSpinLock(&mbox->Lock, OldIrql); } u32_t @@ -201,13 +201,13 @@ sys_arch_mbox_fetch(sys_mbox_t mbox, void **msg, u32_t timeout) ASSERT(Entry); if (IsListEmpty(&mbox->ListHead)) KeClearEvent(&mbox->Event); - Container = CONTAINING_RECORD(Entry, LWIP_MESSAGE_CONTAINER, ListEntry); KeReleaseSpinLock(&mbox->Lock, OldIrql); KeQuerySystemTime(&PostWaitTime); TimeDiff = PostWaitTime.QuadPart - PreWaitTime.QuadPart; TimeDiff /= 10000; + Container = CONTAINING_RECORD(Entry, LWIP_MESSAGE_CONTAINER, ListEntry); Message = Container->Message; ExFreePool(Container); @@ -374,7 +374,5 @@ sys_shutdown(void) ZwClose(Container->Handle); } - - CurrentEntry = CurrentEntry->Flink; } }