فهرست منبع

Adds support for pthread_cond_timedwait on iOS
Calculates relative time and calls pthread_cond_timedwait_relative_np

Richard Gale 10 سال پیش
والد
کامیت
74f0cf9b0f
1فایلهای تغییر یافته به همراه24 افزوده شده و 3 حذف شده
  1. 24 3
      include/bx/sem.h

+ 24 - 3
include/bx/sem.h

@@ -83,14 +83,35 @@ namespace bx
 			int result = pthread_mutex_lock(&m_mutex);
 			int result = pthread_mutex_lock(&m_mutex);
 			BX_CHECK(0 == result, "pthread_mutex_lock %d", result);
 			BX_CHECK(0 == result, "pthread_mutex_lock %d", result);
 
 
-#		if BX_PLATFORM_NACL || BX_PLATFORM_OSX || BX_PLATFORM_IOS
+#		if BX_PLATFORM_NACL || BX_PLATFORM_OSX
 			BX_UNUSED(_msecs);
 			BX_UNUSED(_msecs);
-			BX_CHECK(-1 == _msecs, "NaCl, iOS and OSX don't support pthread_cond_timedwait at this moment.");
+			BX_CHECK(-1 == _msecs, "NaCl and OSX don't support pthread_cond_timedwait at this moment.");
 			while (0 == result
 			while (0 == result
-			&&     0 >= m_count)
+			&&	 0 >= m_count)
 			{
 			{
 				result = pthread_cond_wait(&m_cond, &m_mutex);
 				result = pthread_cond_wait(&m_cond, &m_mutex);
 			}
 			}
+#		elif BX_PLATFORM_IOS
+			if (-1 == _msecs)
+			{
+				while (0 == result
+				&&     0 >= m_count)
+				{
+					result = pthread_cond_wait(&m_cond, &m_mutex);
+				}
+			}
+			else
+			{
+				timespec ts;
+				ts.tv_sec = _msecs/1000;
+				ts.tv_nsec = (_msecs%1000)*1000;
+
+				while (0 == result
+				&&     0 >= m_count)
+				{
+					result = pthread_cond_timedwait_relative_np(&m_cond, &m_mutex, &ts);
+				}
+			}
 #		else
 #		else
 			timespec ts;
 			timespec ts;
 			clock_gettime(CLOCK_REALTIME, &ts);
 			clock_gettime(CLOCK_REALTIME, &ts);