Module: wine Branch: master Commit: f042c4ea4a3bcf211288fe69ed6014687995e1de URL: https://source.winehq.org/git/wine.git/?a=commit;h=f042c4ea4a3bcf211288fe69e...
Author: Piotr Caban piotr@codeweavers.com Date: Fri Feb 2 16:36:18 2018 +0100
msvcr100: Use scoped_lock internal buffer when locking critical_section.
Signed-off-by: Piotr Caban piotr@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/msvcrt/lock.c | 49 ++++++++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/dlls/msvcrt/lock.c b/dlls/msvcrt/lock.c index 4b862b6..6bcd66a 100644 --- a/dlls/msvcrt/lock.c +++ b/dlls/msvcrt/lock.c @@ -358,32 +358,38 @@ static inline void cs_set_head(critical_section *cs, cs_queue *q) cs->head = &cs->unk_active; }
-/* ?lock@critical_section@Concurrency@@QAEXXZ */ -/* ?lock@critical_section@Concurrency@@QEAAXXZ */ -DEFINE_THISCALL_WRAPPER(critical_section_lock, 4) -void __thiscall critical_section_lock(critical_section *this) +static inline void cs_lock(critical_section *cs, cs_queue *q) { - cs_queue q, *last; - - TRACE("(%p)\n", this); + cs_queue *last;
- if(this->unk_thread_id == GetCurrentThreadId()) + if(cs->unk_thread_id == GetCurrentThreadId()) throw_exception(EXCEPTION_IMPROPER_LOCK, 0, "Already locked");
- memset(&q, 0, sizeof(q)); - last = InterlockedExchangePointer(&this->tail, &q); + memset(q, 0, sizeof(*q)); + last = InterlockedExchangePointer(&cs->tail, q); if(last) { - last->next = &q; - NtWaitForKeyedEvent(keyed_event, &q, 0, NULL); + last->next = q; + NtWaitForKeyedEvent(keyed_event, q, 0, NULL); }
- cs_set_head(this, &q); - if(InterlockedCompareExchangePointer(&this->tail, &this->unk_active, &q) != &q) { - spin_wait_for_next_cs(&q); - this->unk_active.next = q.next; + cs_set_head(cs, q); + if(InterlockedCompareExchangePointer(&cs->tail, &cs->unk_active, q) != q) { + spin_wait_for_next_cs(q); + cs->unk_active.next = q->next; } }
+/* ?lock@critical_section@Concurrency@@QAEXXZ */ +/* ?lock@critical_section@Concurrency@@QEAAXXZ */ +DEFINE_THISCALL_WRAPPER(critical_section_lock, 4) +void __thiscall critical_section_lock(critical_section *this) +{ + cs_queue q; + + TRACE("(%p)\n", this); + cs_lock(this, &q); +} + /* ?try_lock@critical_section@Concurrency@@QAE_NXZ */ /* ?try_lock@critical_section@Concurrency@@QEAA_NXZ */ DEFINE_THISCALL_WRAPPER(critical_section_try_lock, 4) @@ -503,8 +509,13 @@ MSVCRT_bool __thiscall critical_section_try_lock_for( typedef struct { critical_section *cs; - void *unknown[4]; - int unknown2[2]; + union { + cs_queue q; + struct { + void *unknown[4]; + int unknown2[2]; + } unknown; + } lock; } critical_section_scoped_lock;
/* ??0scoped_lock@critical_section@Concurrency@@QAE@AAV12@@Z */ @@ -515,7 +526,7 @@ critical_section_scoped_lock* __thiscall critical_section_scoped_lock_ctor( { TRACE("(%p %p)\n", this, cs); this->cs = cs; - critical_section_lock(this->cs); + cs_lock(this->cs, &this->lock.q); return this; }