Skip to content
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

legacy TIMEDWAIT declarations missing from Unified Headers #423

Closed
alexcohn opened this issue Jun 15, 2017 · 15 comments
Closed

legacy TIMEDWAIT declarations missing from Unified Headers #423

alexcohn opened this issue Jun 15, 2017 · 15 comments
Assignees
Labels
Milestone

Comments

@alexcohn
Copy link

alexcohn commented Jun 15, 2017

Description

This surfaced in WebRTC compilation on r15 (see e.g. event_timer_posix.c:99).

platform headers for android-9 till android-19 define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC. It is not defined in unified headers, but simply adding this with condition __ANDROID_API__ < 21 does not help; we also need to declare pthread_cond_timedwait_monotonic_np() and her kin.

Workaround:

I have added the file pthread.h high on our includes search path:

#include_next <pthread.h>

// workaround a bug with Unified Headers in NDK r.15 (see https:/android-ndk/ndk/issues/423)

#if defined __ANDROID_API__ && (__ANDROID_API__ < 21)

#ifdef __cplusplus
extern "C" {
#endif

/* BIONIC: same as pthread_cond_timedwait, except the 'abstime' given refers
 *         to the CLOCK_MONOTONIC clock instead, to avoid any problems when
 *         the wall-clock time is changed brutally
 */
int pthread_cond_timedwait_monotonic_np(pthread_cond_t         *cond,
                                        pthread_mutex_t        *mutex,
                                        const struct timespec  *abstime);

/* BIONIC: DEPRECATED. same as pthread_cond_timedwait_monotonic_np()
 * unfortunately pthread_cond_timedwait_monotonic has shipped already
 */
int pthread_cond_timedwait_monotonic(pthread_cond_t         *cond,
                                     pthread_mutex_t        *mutex,
                                     const struct timespec  *abstime);

#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1

/* BIONIC: same as pthread_cond_timedwait, except the 'reltime' given refers
 *         is relative to the current time.
 */
int pthread_cond_timedwait_relative_np(pthread_cond_t         *cond,
                                     pthread_mutex_t        *mutex,
                                     const struct timespec  *reltime);

#define HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE 1



int pthread_cond_timeout_np(pthread_cond_t *cond,
                            pthread_mutex_t * mutex,
                            unsigned msecs);

/* same as pthread_mutex_lock(), but will wait up to 'msecs' milli-seconds
 * before returning. same return values than pthread_mutex_trylock though, i.e.
 * returns EBUSY if the lock could not be acquired after the timeout
 * expired.
 */
int pthread_mutex_lock_timeout_np(pthread_mutex_t *mutex, unsigned msecs);

#ifdef __cplusplus
}
#endif

#endif

Environment Details

Not all of these will be relevant to every bug, but please provide as much
information as you can.

  • NDK Version: 15.0.4075724.
  • Build system: ndk-build
  • Host OS: Mac
  • Compiler: Clang
  • ABI: armeabi-v7a and others
  • STL: -
  • NDK API level: android-14
  • Device API level: n/a
@alexcohn
Copy link
Author

actually, it's duplicate of #420

@alexcohn alexcohn changed the title legacy TIMEDWAIT declarations missing form Unified Headers legacy TIMEDWAIT declarations missing from Unified Headers Jun 15, 2017
alexcohn referenced this issue in aosp-mirror/platform_bionic Jun 16, 2017
The proper API for this isn't available until L, so expose this for
API levels earlier than that.

Test: make checkbuild
Bug: android/ndk#420
Change-Id: I382b8f557be9530f3e13aaae353b4a6e7f9301ab
@alexcohn
Copy link
Author

@DanAlbert did you set 'invalid' because it's duplicate?

@DanAlbert
Copy link
Member

Yep, my mistake.

@DanAlbert
Copy link
Member

Crap, I actually missed the list of other missing things. I'm going to get these added now.

@DanAlbert DanAlbert self-assigned this Jun 22, 2017
@DanAlbert
Copy link
Member

https://android-review.googlesource.com/c/420945/ sorry about that!

@DanAlbert
Copy link
Member

Oh, I didn't put back the HAVE_BLAH defines though. I don't want us to overlap with autoconf and cause macro redefinition warnings. Those checks can be written in terms of __ANDROID_API__ for people not using configure.

@alexcohn
Copy link
Author

@DanAlbert Do you expect people to migrate their code, e.g. WebRTC to use

#if (__ANDROID_API__ < 21)

in event_timer_posix.cc:99? I would rather keep it the way it is today (anyway, WebRTC still ships with NDK r.11). People who will try to use autoconf may need some adaptations, but at least don't force projects that are tuned for NDK already to change: their natural path will be to stay stuck with old NDK as long as possible.

@enh
Copy link
Contributor

enh commented Jun 23, 2017

as far as we're concerned, the sooner everyone's on the same codepath, the better. the pthread_cond_timedwait codepath they need for LP64 works fine for LP32 too. for us, failing the HAVE_BLAH check seems like a feature.

@DanAlbert
Copy link
Member

The fallback behavior actually doesn't work pre-21, because we didn't have pthread_condattr_setclock until 21, so the clock won't be monotonic.

@enh
Copy link
Contributor

enh commented Jun 23, 2017

yeah, i was thinking of HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE. now you're making me distinguish the two cases, yes, the argument for HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC is much stronger because pthread_condattr_setclock was a late addition.

hubot pushed a commit to aosp-mirror/platform_bionic that referenced this issue Jun 29, 2017
Test: make checkbuild
Bug: android/ndk#423
Bug: https://stackoverflow.com/q/44580542/632035
Change-Id: Ibf52a969afffbfcdf6793a0bf8b0e10bbdd1f32c
@enh enh added this to the r15c milestone Jul 18, 2017
@alexcohn
Copy link
Author

This fix missed

#define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC 1

and thus WebRTC breaks for webrtc/system_wrappers/source/event_timer_posix.cc when built with ANDROID_API < 21.

@enh
Copy link
Contributor

enh commented Jan 10, 2018

yeah, polluting the global namespace with HAVE_ macros seems unreasonable.

@alexcohn
Copy link
Author

@enh, do you suggest to open a ticket for WebRTC to switch this check to __ANDROID_API__ < 21 ?

@enh
Copy link
Contributor

enh commented Jan 11, 2018

yeah, that sounds like the right fix.

@alexcohn
Copy link
Author

They have chosen to define HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC, see https://chromium.googlesource.com/chromium/src/build/+/master/config/android/BUILD.gn#96

They have a bug for sdk level=20, but it's purely theoretical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants