-
Notifications
You must be signed in to change notification settings - Fork 874
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: disable pthread_condattr_setclock on lower versions of Android #3138
base: master
Are you sure you want to change the base?
Conversation
I have a feeling this check should better be done by CMake, somewhere here Or here |
change test_requires_clock_gettime ? |
Hm, sorry, I got confused. You define |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems like
pthread_condattr_setclock(&CondAttribs, CLOCK_MONOTONIC)
won't be called to configure a CV to use MONOTONIC clock.
But there will still be calls to clock_gettime(CLOCK_MONOTONIC, &timeout)
to get the target timeout, while the CV won't probably use monotonic clock to wait...
So timeout will be with monotonic clock base, but CV will use system clock internally to wait...
timeout = us_to_timespec(now_us + count_microseconds(rel_time));
return pthread_cond_timedwait(&m_cv, &lock.mutex()->ref(), &timeout) != ETIMEDOUT;
It seems that we forgot to call |
May I suggest to modify
I'm not sure about the changes made to |
Good idea. I have already made the changes. |
That error message should rather advice compiling with C++11, as compiling without monotonic clock is dangerous. |
So the modification that should be made here is, if both |
Well, it could be quite complicated and "reinventing" if we set default C++11 for Android in this case, so my stance on it is that:
|
BTW These last CI builds on Travis fail on the configuration level, but weirdly I see only the general error at the end of cmake, but no error message during configuration. |
…he configuration.
cc? I have already made the changes. |
Look at sync.h#L30-L45 here. The platform and |
@lilinxiong you are right. 1. CLOCK_MONOTONICSRT uses The SRT_SYNC_CLOCK is defined in sync.h as follows: // Defile clock type to use
#ifdef IA32
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_IA32_RDTSC
#define SRT_SYNC_CLOCK_STR "IA32_RDTSC"
#elif defined(IA64)
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_IA64_ITC
#define SRT_SYNC_CLOCK_STR "IA64_ITC"
#elif defined(AMD64)
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_AMD64_RDTSC
#define SRT_SYNC_CLOCK_STR "AMD64_RDTSC"
#elif defined(_WIN32)
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_WINQPC
#define SRT_SYNC_CLOCK_STR "WINQPC"
#elif TARGET_OS_MAC
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_MACH_ABSTIME
#define SRT_SYNC_CLOCK_STR "MACH_ABSTIME"
#elif defined(ENABLE_MONOTONIC_CLOCK)
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_GETTIME_MONOTONIC
#define SRT_SYNC_CLOCK_STR "GETTIME_MONOTONIC"
#else
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY
#define SRT_SYNC_CLOCK_STR "POSIX_GETTIMEOFDAY"
#endif
2.
|
@maxsharabayko Sure, I totally agree with what you said. However, I have another question. // Defile clock type to use
#ifdef IA32 // platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_IA32_RDTSC
#define SRT_SYNC_CLOCK_STR "IA32_RDTSC"
#elif defined(IA64) // platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_IA64_ITC
#define SRT_SYNC_CLOCK_STR "IA64_ITC"
#elif defined(AMD64) // platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_AMD64_RDTSC
#define SRT_SYNC_CLOCK_STR "AMD64_RDTSC"
#elif defined(_WIN32) // platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_WINQPC
#define SRT_SYNC_CLOCK_STR "WINQPC"
#elif TARGET_OS_MAC // platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_MACH_ABSTIME
#define SRT_SYNC_CLOCK_STR "MACH_ABSTIME"
#elif defined(ENABLE_MONOTONIC_CLOCK) // this is not platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_GETTIME_MONOTONIC
#define SRT_SYNC_CLOCK_STR "GETTIME_MONOTONIC"
#else
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY
#define SRT_SYNC_CLOCK_STR "POSIX_GETTIMEOFDAY"
#endif Regarding the definition here, could we possibly make some modifications, such as changing it to the following: ...
#elif TARGET_OS_MAC // platform
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_MACH_ABSTIME
#define SRT_SYNC_CLOCK_STR "MACH_ABSTIME"
#elif defined(__ANDROID__) // platform
#if defined(ENABLE_MONOTONIC_CLOCK)
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_GETTIME_MONOTONIC
#define SRT_SYNC_CLOCK_STR "GETTIME_MONOTONIC"
#endif
#else
#define SRT_SYNC_CLOCK SRT_SYNC_CLOCK_POSIX_GETTIMEOFDAY
#define SRT_SYNC_CLOCK_STR "POSIX_GETTIMEOFDAY"
#endif Because here, the priority of the platform is higher than our self-defined Or to put it another way, in our check pthread_condattr_setclock So I’ve made a temporary adjustment to only check for the pthread_condattr_setclock symbol on Android. From 68b598ddede64632a149dcee8c8b2f1d5de335e2 Mon Sep 17 00:00:00 2001
From: lilinxiong <[email protected]>
Date: Thu, 13 Mar 2025 17:57:23 +0800
Subject: [PATCH] only check Android platforom
---
CMakeLists.txt | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b83b316..2035526 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -142,7 +142,11 @@ elseif (POSIX)
test_requires_clock_gettime(ENABLE_MONOTONIC_CLOCK_DEFAULT MONOTONIC_CLOCK_LINKLIB)
endif()
-if (ENABLE_MONOTONIC_CLOCK_DEFAULT)
+# If current platform is android both ENABLE_MONOTONIC_CLOCK_DEFAULT is ON so check
+# todo: This is not a very good approach, but in the current project,
+# todo: the platform is not defined independently, and there is a mix of platform and ENABLE_MONOTONIC_CLOCK in src/core/sync.h,
+# todo: which should not be used together. Therefore, for now, we have to write it this way.
+if (ANDROID AND ENABLE_MONOTONIC_CLOCK_DEFAULT)
message(STATUS "because enable monotonic clock so start check needed symbol.")
list(PREPEND CMAKE_REQUIRED_LIBRARIES "${CMAKE_THREAD_LIBS_INIT}")
check_symbol_exists(pthread_condattr_setclock "pthread.h" HAVE_PTHREAD_CONDATTR_SETCLOCK)
--
2.45.2 However, this is not very elegant because now only Android is being checked, and none of the others. The reason is that in the current CMakeLists.txt, I seem to be unable to predict on which platform ENABLE_MONOTONIC_CLOCK will be used, because in the CMakeLists.txt, MacOS also belongs to POSIX. Its definition is here: ...
set_if(POSIX LINUX OR DARWIN OR BSD OR SUNOS OR ANDROID OR (CYGWIN AND CYGWIN_USE_POSIX) OR GNU_OS)
... ConclusionFor the definition of |
if (POSIX) | ||
# If current platform is POSIX, need check ENABLE_MONOTONIC_CLOCK is ON or ENABLE_STDCXX_SYNC ON | ||
if (NOT ENABLE_STDCXX_SYNC AND NOT ENABLE_MONOTONIC_CLOCK) | ||
message(FATAL_ERROR "Both ENABLE_STDCXX_SYNC and ENABLE_MONOTONIC_CLOCK are OFF. Exiting. pls Open ENABLE_STDCXX_SYNC ENABLE_MONOTONIC_CLOCK=OFF is DANGEROUS!!") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message is not comprehensible.
The idea is:
- if ENABLE_STDXCC_SYNC is ON, don't check for ENABLE_MONOTONIC_CLOCK presence nor availability of symbol
- if ENABLE_STDCXX_SYNC is OFF, default ENABLE_MONOTONIC_CLOCK should be ON.
- if ENABLE_MONOTONIC_CLOCK is ON, and the symbol is not available, issue a fatal error.
if (pthread_condattr_setclock(&CondAttribs, CLOCK_MONOTONIC) != 0) | ||
{ | ||
pthread_condattr_destroy(&CondAttribs); | ||
LOGC(inlog.Warn, log << "pthread_condattr_setclock failed!"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that if that call failed, it means that we don't have the monotonic clock set up for the CV. I think such a thing should be reported as Fatal (not Warn).
LOGC(inlog.Warn, log << "pthread_condattr_setclock failed!"); | |
LOGC(inlog.Fatal, log << "IPE: pthread_condattr_setclock failed to set up a monotonic clock for a CV"); |
On Android OS versions equal to or less than 21,

pthread_condattr_setclock
is not available, so we need to disable it to prevent compilation failures.