Piotr Caban : msvcp100: Support exceptions while copying object in _Concurrent_queue_base_v4:: _Internal_push.

Alexandre Julliard julliard at winehq.org
Tue Jan 23 16:09:50 CST 2018


Module: wine
Branch: master
Commit: 4e863fa7c721ac5aadb36acb8e033938a8223570
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=4e863fa7c721ac5aadb36acb8e033938a8223570

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Tue Jan 23 17:04:39 2018 +0100

msvcp100: Support exceptions while copying object in _Concurrent_queue_base_v4::_Internal_push.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/msvcp90/misc.c      | 49 +++++++++++++++++++++++++++++++++---------------
 include/wine/exception.h |  2 +-
 2 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/dlls/msvcp90/misc.c b/dlls/msvcp90/misc.c
index b3e546a..d9fe188 100644
--- a/dlls/msvcp90/misc.c
+++ b/dlls/msvcp90/misc.c
@@ -27,6 +27,7 @@
 #include "winbase.h"
 #include "winternl.h"
 #include "wine/debug.h"
+#include "wine/exception.h"
 WINE_DEFAULT_DEBUG_CHANNEL(msvcp);
 
 struct __Container_proxy;
@@ -1397,6 +1398,12 @@ static MSVCP_size_t InterlockedIncrementSizeT(MSVCP_size_t volatile *dest)
 #define InterlockedIncrementSizeT(dest) InterlockedIncrement((LONG*)dest)
 #endif
 
+static void CALLBACK queue_push_finally(BOOL normal, void *ctx)
+{
+    threadsafe_queue *queue = ctx;
+    InterlockedIncrementSizeT(&queue->tail_pos);
+}
+
 static void threadsafe_queue_push(threadsafe_queue *queue, MSVCP_size_t id,
         void *e, _Concurrent_queue_base_v4 *parent, BOOL copy)
 {
@@ -1430,21 +1437,24 @@ static void threadsafe_queue_push(threadsafe_queue *queue, MSVCP_size_t id,
         p = queue->tail;
     }
 
-    /* TODO: Add exception handling */
-    if(copy)
-        call__Concurrent_queue_base_v4__Copy_item(parent, p, id-page_id, e);
-    else
-        call__Concurrent_queue_base_v4__Move_item(parent, p, id-page_id, e);
-    p->_Mask |= 1 << (id - page_id);
-    InterlockedIncrementSizeT(&queue->tail_pos);
+    __TRY
+    {
+        if(copy)
+            call__Concurrent_queue_base_v4__Copy_item(parent, p, id-page_id, e);
+        else
+            call__Concurrent_queue_base_v4__Move_item(parent, p, id-page_id, e);
+        p->_Mask |= 1 << (id - page_id);
+    }
+    __FINALLY_CTX(queue_push_finally, queue);
 }
 
-static void threadsafe_queue_pop(threadsafe_queue *queue, MSVCP_size_t id,
+static BOOL threadsafe_queue_pop(threadsafe_queue *queue, MSVCP_size_t id,
         void *e, _Concurrent_queue_base_v4 *parent)
 {
     MSVCP_size_t page_id = id & ~(parent->alloc_count-1);
     int spin;
     _Page *p;
+    BOOL ret = FALSE;
 
     spin = 0;
     while(queue->tail_pos <= id)
@@ -1455,8 +1465,12 @@ static void threadsafe_queue_pop(threadsafe_queue *queue, MSVCP_size_t id,
         spin_wait(&spin);
 
     p = queue->head;
-    /* TODO: Add exception handling */
-    call__Concurrent_queue_base_v4__Assign_and_destroy_item(parent, e, p, id-page_id);
+    if(p->_Mask & (1 << (id-page_id)))
+    {
+        /* TODO: Add exception handling */
+        call__Concurrent_queue_base_v4__Assign_and_destroy_item(parent, e, p, id-page_id);
+        ret = TRUE;
+    }
 
     if(id == page_id+parent->alloc_count-1)
     {
@@ -1471,7 +1485,9 @@ static void threadsafe_queue_pop(threadsafe_queue *queue, MSVCP_size_t id,
         /* TODO: Add exception handling */
         call__Concurrent_queue_base_v4__Deallocate_page(parent, p);
     }
+
     InterlockedIncrementSizeT(&queue->head_pos);
+    return ret;
 }
 
 /* ?_Internal_push at _Concurrent_queue_base_v4@details at Concurrency@@IAEXPBX at Z */
@@ -1516,11 +1532,14 @@ MSVCP_bool __thiscall _Concurrent_queue_base_v4__Internal_pop_if_present(
 
     do
     {
-        id = this->data->head_pos;
-        if(id == this->data->tail_pos) return FALSE;
-    } while(InterlockedCompareExchangePointer((void**)&this->data->head_pos,
-                (void*)(id+1), (void*)id) != (void*)id);
-    threadsafe_queue_pop(this->data->queues + id % QUEUES_NO, id / QUEUES_NO, e, this);
+        do
+        {
+            id = this->data->head_pos;
+            if(id == this->data->tail_pos) return FALSE;
+        } while(InterlockedCompareExchangePointer((void**)&this->data->head_pos,
+                    (void*)(id+1), (void*)id) != (void*)id);
+    } while(!threadsafe_queue_pop(this->data->queues + id % QUEUES_NO,
+                id / QUEUES_NO, e, this));
     return TRUE;
 }
 
diff --git a/include/wine/exception.h b/include/wine/exception.h
index 8e3f481..3b1a3cf 100644
--- a/include/wine/exception.h
+++ b/include/wine/exception.h
@@ -92,7 +92,7 @@ extern "C" {
 
 #else  /* USE_COMPILER_EXCEPTIONS */
 
-#if defined(__MINGW32__) || defined(__CYGWIN__)
+#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__WINE_SETJMP_H)
 #define sigjmp_buf jmp_buf
 #define sigsetjmp(buf,sigs) setjmp(buf)
 #define siglongjmp(buf,val) longjmp(buf,val)




More information about the wine-cvs mailing list