Piotr Caban : msvcr100: Use scoped_lock internal buffer when locking critical_section.

Alexandre Julliard julliard at winehq.org
Sun Mar 3 13:21:28 CST 2019


Module: wine
Branch: oldstable
Commit: 50ec64a0cf4f24aa1c3213b0a59dbf5a305df4b0
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=50ec64a0cf4f24aa1c3213b0a59dbf5a305df4b0

Author: Piotr Caban <piotr at 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 at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit f042c4ea4a3bcf211288fe69ed6014687995e1de)
Signed-off-by: Michael Stefaniuc <mstefani at 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 2e0865d..61cbc46 100644
--- a/dlls/msvcrt/lock.c
+++ b/dlls/msvcrt/lock.c
@@ -357,32 +357,38 @@ static inline void cs_set_head(critical_section *cs, cs_queue *q)
     cs->head = &cs->unk_active;
 }
 
-/* ?lock at critical_section@Concurrency@@QAEXXZ */
-/* ?lock at 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 at critical_section@Concurrency@@QAEXXZ */
+/* ?lock at 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 at critical_section@Concurrency@@QAE_NXZ */
 /* ?try_lock at critical_section@Concurrency@@QEAA_NXZ */
 DEFINE_THISCALL_WRAPPER(critical_section_try_lock, 4)
@@ -502,8 +508,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 at critical_section@Concurrency@@QAE at AAV12@@Z */
@@ -514,7 +525,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;
 }
 




More information about the wine-cvs mailing list