this patch will get compile error on Windows XP, please ignore this.<br><br>On Sunday, April 3, 2016, Ximing Cheng <<a href="mailto:chengximing1989@foxmail.com">chengximing1989@foxmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Ximing Cheng <<a href="javascript:;" onclick="_e(event, 'cvml', 'ximingcheng@tencent.com')">ximingcheng@tencent.com</a>><br>
# Date 1459684811 -28800<br>
#      Sun Apr 03 20:00:11 2016 +0800<br>
# Node ID 1071a3c92f2be6fcf0e5178266a3382458690429<br>
# Parent  601877ef465c549efe24063afa0479a39e369010<br>
threading: add RWLock and RWScopedLock<br>
<br>
diff -r 601877ef465c -r 1071a3c92f2b source/common/threading.h<br>
--- a/source/common/threading.h Sun Apr 03 16:29:59 2016 +0800<br>
+++ b/source/common/threading.h Sun Apr 03 20:00:11 2016 +0800<br>
@@ -131,6 +131,41 @@<br>
     CRITICAL_SECTION handle;<br>
 };<br>
<br>
+#if _WIN32_WINNT >= _WIN32_WINNT_VISTA<br>
+class RWLock<br>
+{<br>
+public:<br>
+<br>
+    RWLock()<br>
+    {<br>
+        InitializeSRWLock(&rwlock);<br>
+    }<br>
+<br>
+    void acquireR()<br>
+    {<br>
+        AcquireSRWLockShared(&rwlock);<br>
+    }<br>
+<br>
+    void acquireW()<br>
+    {<br>
+        AcquireSRWLockExclusive(&rwlock);<br>
+    }<br>
+<br>
+    void releaseR()<br>
+    {<br>
+        ReleaseSRWLockShared(&rwlock);<br>
+    }<br>
+<br>
+    void releaseW()<br>
+    {<br>
+        ReleaseSRWLockExclusive(&rwlock);<br>
+    }<br>
+<br>
+protected:<br>
+    SRWLOCK rwlock;<br>
+};<br>
+#endif<br>
+<br>
 class Event<br>
 {<br>
 public:<br>
@@ -192,7 +227,7 @@<br>
     ~ThreadSafeInteger()<br>
     {<br>
         /* SRW locks do not need to be explicitly destroyed */<br>
-#if defined(_WIN32_WINNT) && _WIN32_WINNT < _WIN32_WINNT_VISTA<br>
+#if _WIN32_WINNT < _WIN32_WINNT_VISTA<br>
         DeleteCriticalSection(&m_cs);<br>
 #endif<br>
         XP_CONDITION_VAR_FREE(&m_cv);<br>
@@ -332,6 +367,44 @@<br>
     pthread_mutex_t handle;<br>
 };<br>
<br>
+class RWLock<br>
+{<br>
+public:<br>
+<br>
+    RWLock()<br>
+    {<br>
+        pthread_rwlock_init(&rwlock, NULL);<br>
+    }<br>
+<br>
+    ~RWLock()<br>
+    {<br>
+        pthread_rwlock_destroy(&rwlock);<br>
+    }<br>
+<br>
+    void acquireR()<br>
+    {<br>
+        pthread_rwlock_rdlock(&rwlock);<br>
+    }<br>
+<br>
+    void acquireW()<br>
+    {<br>
+        pthread_rwlock_wrlock(&rwlock);<br>
+    }<br>
+<br>
+    void releaseR()<br>
+    {<br>
+        pthread_rwlock_unlock(&rwlock);<br>
+    }<br>
+<br>
+    void releaseW()<br>
+    {<br>
+        pthread_rwlock_unlock(&rwlock);<br>
+    }<br>
+<br>
+protected:<br>
+    pthread_rwlock_t rwlock;<br>
+};<br>
+<br>
 class Event<br>
 {<br>
 public:<br>
@@ -574,6 +647,28 @@<br>
     Lock &inst;<br>
 };<br>
<br>
+#if !(defined(_WIN32_WINNT) && _WIN32_WINNT < _WIN32_WINNT_VISTA)<br>
+class RWScopedLock<br>
+{<br>
+public:<br>
+<br>
+    RWScopedLock(RWLock &instance) : inst(instance)<br>
+    {<br>
+        this->inst.acquireW();<br>
+    }<br>
+<br>
+    ~RWScopedLock()<br>
+    {<br>
+        this->inst.releaseW();<br>
+    }<br>
+<br>
+protected:<br>
+    RWScopedLock &operator =(const RWScopedLock &);<br>
+<br>
+    RWLock &inst;<br>
+};<br>
+#endif<br>
+<br>
 // Utility class which adds elapsed time of the scope of the object into the<br>
 // accumulator provided to the constructor<br>
 struct ScopedElapsedTime<br>
diff -r 601877ef465c -r 1071a3c92f2b source/encoder/frameencoder.cpp<br>
--- a/source/encoder/frameencoder.cpp   Sun Apr 03 16:29:59 2016 +0800<br>
+++ b/source/encoder/frameencoder.cpp   Sun Apr 03 20:00:11 2016 +0800<br>
@@ -895,7 +895,11 @@<br>
     tld.analysis.m_param = m_param;<br>
     if (m_param->bEnableWavefront)<br>
     {<br>
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < _WIN32_WINNT_VISTA<br>
         ScopedLock self(curRow.lock);<br>
+#else<br>
+        RWScopedLock self(curRow.lock);<br>
+#endif<br>
         if (!curRow.active)<br>
             /* VBV restart is in progress, exit out */<br>
             return;<br>
@@ -1131,7 +1135,7 @@<br>
                         if (r != row)<br>
                         {<br>
                             /* if row was active (ready to be run) clear active bit and bitmap bit for this row */<br>
-                            stopRow.lock.acquire();<br>
+                            stopRow.lock.acquireW();<br>
                             while (stopRow.active)<br>
                             {<br>
                                 if (dequeueRow(r * 2))<br>
@@ -1139,19 +1143,19 @@<br>
                                 else<br>
                                 {<br>
                                     /* we must release the row lock to allow the thread to exit */<br>
-                                    stopRow.lock.release();<br>
+                                    stopRow.lock.releaseW();<br>
                                     GIVE_UP_TIME();<br>
-                                    stopRow.lock.acquire();<br>
+                                    stopRow.lock.acquireW();<br>
                                 }<br>
                             }<br>
-                            stopRow.lock.release();<br>
+                            stopRow.lock.releaseW();<br>
<br>
                             bool bRowBusy = true;<br>
                             do<br>
                             {<br>
-                                stopRow.lock.acquire();<br>
+                                stopRow.lock.acquireR();<br>
                                 bRowBusy = stopRow.busy;<br>
-                                stopRow.lock.release();<br>
+                                stopRow.lock.releaseR();<br>
<br>
                                 if (bRowBusy)<br>
                                 {<br>
@@ -1181,7 +1185,11 @@<br>
             (!m_bAllRowsStop || intRow + 1 < m_vbvResetTriggerRow))<br>
         {<br>
             /* activate next row */<br>
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < _WIN32_WINNT_VISTA<br>
             ScopedLock below(m_rows[row + 1].lock);<br>
+#else<br>
+            RWScopedLock below(m_rows[row + 1].lock);<br>
+#endif<br>
             if (m_rows[row + 1].active == false &&<br>
                 m_rows[row + 1].completed + 2 <= curRow.completed)<br>
             {<br>
@@ -1191,7 +1199,11 @@<br>
             }<br>
         }<br>
<br>
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < _WIN32_WINNT_VISTA<br>
         ScopedLock self(curRow.lock);<br>
+#else<br>
+        RWScopedLock self(curRow.lock);<br>
+#endif<br>
         if ((m_bAllRowsStop && intRow > m_vbvResetTriggerRow) ||<br>
             (row > 0 && ((curRow.completed < numCols - 1) || (m_rows[row - 1].completed < numCols)) && m_rows[row - 1].completed < m_rows[row].completed + 2))<br>
         {<br>
diff -r 601877ef465c -r 1071a3c92f2b source/encoder/frameencoder.h<br>
--- a/source/encoder/frameencoder.h     Sun Apr 03 16:29:59 2016 +0800<br>
+++ b/source/encoder/frameencoder.h     Sun Apr 03 20:00:11 2016 +0800<br>
@@ -79,7 +79,11 @@<br>
     /* Threading variables */<br>
<br>
     /* This lock must be acquired when reading or writing m_active or m_busy */<br>
+#if defined(_WIN32_WINNT) && _WIN32_WINNT < _WIN32_WINNT_VISTA<br>
     Lock              lock;<br>
+#else<br>
+    RWLock            lock;<br>
+#endif<br>
<br>
     /* row is ready to run, has no neighbor dependencies. The row may have<br>
      * external dependencies (reference frame pixels) that prevent it from being<br>
<br>
<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'x265-devel@videolan.org')">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote>