From 2b713729a87355a8a76887b7a7eb9b7d0397d9d8 Mon Sep 17 00:00:00 2001
From: Dan Kegel <dank@kegel.com>
Date: Mon, 15 Oct 2012 21:09:56 -0700
Subject: [PATCH 6/7] vcomp: better stubs for _vcomp_sections_init,
 _vcomp_sections_next

---
 dlls/vcomp/tests/work.c    |   33 +++++++++++++++++++++++++++++++++
 dlls/vcomp/vcomp.spec      |    4 ++--
 dlls/vcomp/vcomp_private.h |    4 ++++
 dlls/vcomp/work.c          |   18 ++++++++++++++++++
 4 files changed, 57 insertions(+), 2 deletions(-)

diff --git a/dlls/vcomp/tests/work.c b/dlls/vcomp/tests/work.c
index 0962397..3d34d93 100644
--- a/dlls/vcomp/tests/work.c
+++ b/dlls/vcomp/tests/work.c
@@ -20,12 +20,15 @@
 
 #include "wine/test.h"
 
+static void WINAPIV (*p_vcomp_barrier)(void);
 static void WINAPIV (*p_vcomp_fork)(DWORD parallel, int nargs, void *helper, ...);
 static void CDECL (*p_vcomp_for_dynamic_init)(int flags, int first, int last, int mystep, int chunksize);
 static int CDECL (*p_vcomp_for_dynamic_next)(int *pcounter, int *pchunklimit);
 static void CDECL (*p_vcomp_for_static_end)(void);
 static void CDECL (*p_vcomp_for_static_init)(int first, int last, int mystep, int chunksize, int *pnloops, int *pfirst, int *plast, int *pchunksize, int *pfinalchunkstart);
 static void CDECL (*p_vcomp_for_static_simple_init)(int first, int last, int mystep, int step, int *pfirst, int *plast);
+static void CDECL (*p_vcomp_sections_init)(int n);
+static int CDECL (*p_vcomp_sections_next)(void);
 
 #define GETFUNC(x) do { p##x = (void*)GetProcAddress(vcomp, #x); ok(p##x != NULL, "Export '%s' not found\n", #x); } while(0)
 
@@ -41,12 +44,15 @@ static BOOL init(void)
         return FALSE;
     }
 
+    GETFUNC(_vcomp_barrier);
     GETFUNC(_vcomp_fork);
     GETFUNC(_vcomp_for_dynamic_init);
     GETFUNC(_vcomp_for_dynamic_next);
     GETFUNC(_vcomp_for_static_end);
     GETFUNC(_vcomp_for_static_init);
     GETFUNC(_vcomp_for_static_simple_init);
+    GETFUNC(_vcomp_sections_init);
+    GETFUNC(_vcomp_sections_next);
 
     return TRUE;
 }
@@ -176,6 +182,32 @@ static void test_vcomp_for_static_simple_init(void)
     ok(nsum == 6*13, "expected sum 6*13, got %d\n", nsum);
 }
 
+int section_calls[3];
+
+static void CDECL _test_vcomp_sections_worker(void)
+{
+    p_vcomp_sections_init(3);
+
+    while (1) {
+        int i = p_vcomp_sections_next();
+        if (i < 0 || i >= 3) break;
+        section_calls[i]++;
+    }
+
+    p_vcomp_barrier();
+}
+
+static void test_vcomp_sections(void)
+{
+    section_calls[0] = 0;
+    section_calls[1] = 0;
+    section_calls[2] = 0;
+    p_vcomp_fork(1, 0, _test_vcomp_sections_worker);
+    ok(section_calls[0] == 1, "section 0 not called once\n");
+    ok(section_calls[1] == 1, "section 1 not called once\n");
+    ok(section_calls[2] == 1, "section 2 not called once\n");
+}
+
 START_TEST(work)
 {
     if (!init())
@@ -184,4 +216,5 @@ START_TEST(work)
     test_vcomp_for_dynamic();
     test_vcomp_for_static_init();
     test_vcomp_for_static_simple_init();
+    test_vcomp_sections();
 }
diff --git a/dlls/vcomp/vcomp.spec b/dlls/vcomp/vcomp.spec
index ddd3f61..f36a8ca 100644
--- a/dlls/vcomp/vcomp.spec
+++ b/dlls/vcomp/vcomp.spec
@@ -83,8 +83,8 @@
 @ stub _vcomp_reduction_u2
 @ stub _vcomp_reduction_u4
 @ stub _vcomp_reduction_u8
-@ stub _vcomp_sections_init
-@ stub _vcomp_sections_next
+@ cdecl _vcomp_sections_init(long)
+@ cdecl _vcomp_sections_next()
 @ cdecl _vcomp_set_num_threads(long)
 @ cdecl _vcomp_single_begin(long)
 @ cdecl _vcomp_single_end()
diff --git a/dlls/vcomp/vcomp_private.h b/dlls/vcomp/vcomp_private.h
index 903a78a..34b261d 100644
--- a/dlls/vcomp/vcomp_private.h
+++ b/dlls/vcomp/vcomp_private.h
@@ -31,6 +31,10 @@ struct vcomp_team {
             int chunksize;
             int flags;
         } dyn_for;
+        struct {
+            int counter;
+            int nsect;
+        } sections;
     } work;
 };
 
diff --git a/dlls/vcomp/work.c b/dlls/vcomp/work.c
index 2aaf1c5..199b9f2 100644
--- a/dlls/vcomp/work.c
+++ b/dlls/vcomp/work.c
@@ -92,3 +92,21 @@ void CDECL _vcomp_for_static_end(void)
 {
     TRACE("stub\n");
 }
+
+void CDECL _vcomp_sections_init(int n)
+{
+    struct vcomp_team *pt = vcomp_get_team();
+    TRACE("(%d): stub\n", n);
+    pt->work.sections.counter = 0;
+    pt->work.sections.nsect = n;
+}
+
+int CDECL _vcomp_sections_next(void)
+{
+    struct vcomp_team *pt = vcomp_get_team();
+    int i = pt->work.sections.counter++;
+    if (i >= pt->work.sections.nsect)
+        i = -1;
+    TRACE("stub; returning %d\n", i);
+    return i;
+}
-- 
1.7.9.5

