Opened 8 years ago

Closed 8 years ago

#11035 closed Bugs (fixed)

BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE not defined for Android

Reported by: kervala@… Owned by: viboes
Milestone: Boost 1.58.0 Component: thread
Version: Boost 1.57.0 Severity: Problem
Keywords: android recursive_mutex Cc:

Description

I'm using boost::recursive_mutex under Android and I noticed they don't work as expected, they are working like standard mutex.

After further investigation, I noticed BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE and BOOST_PTHREAD_HAS_TIMEDLOCK were not defined for Android because Android NDK don't declare _POSIX_TIMEOUTS neither _XOPEN_SOURCE that are checked in boost. So boost::recursive_mutex are not recursive at all under Android :(

Also pthread_mutex_timedlock signature changed since Android 5.0 (API 21), the version with the const struct is used from API 21 while previous versions were using the same without the const.

from API 3 to 20: int pthread_mutex_timedlock(pthread_mutex_t *mutex, struct timespec* ts);

from API 21: int pthread_mutex_timedlock(pthread_mutex_t*, const struct timespec*) nonnull((1, 2));

I have some patches to fix these issues :)

Attachments (3)

boost_recursive_mutex.patch (2.6 KB ) - added by kervala@… 8 years ago.
boost::recursive_mutex fix for Android
boost_recursive_mutex.2.patch (2.6 KB ) - added by Cédric OCHS <kervala@…> 8 years ago.
Fix of the patch
boost_recursive_mutex.3.patch (1.9 KB ) - added by Cédric OCHS <kervala@…> 8 years ago.

Download all attachments as: .zip

Change History (13)

by kervala@…, 8 years ago

Attachment: boost_recursive_mutex.patch added

boost::recursive_mutex fix for Android

by Cédric OCHS <kervala@…>, 8 years ago

Fix of the patch

comment:1 by Cédric OCHS <kervala@…>, 8 years ago

Please ignore the first patch, I forgot to remove a #endif

by Cédric OCHS <kervala@…>, 8 years ago

comment:2 by Cédric OCHS <kervala@…>, 8 years ago

Summary: BOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE and BOOST_PTHREAD_HAS_TIMEDLOCK not defined for AndroidBOOST_HAS_PTHREAD_MUTEXATTR_SETTYPE not defined for Android

I'm sorry, I didn't notice pthread_mutex_timedlock wasn't implemented in bionic before Android API 21, although it was defined in oldest ARM headers (a Google bug in this case).

So I updated my patch for a 3rd time :)

comment:3 by viboes, 8 years ago

Owner: changed from Anthony Williams to Niall Douglas

Since which version of Android the 3rd patch is valid?

comment:4 by Cédric OCHS <kervala@…>, 8 years ago

Thanks for your reply :)

It's valid since Android API 3 (Android 1.5).

I checked all pthread.h header from all Android versions supported by NDK.

comment:5 by Niall Douglas, 8 years ago

Just for the record, I don't think Boost should support Android before v2. But thanks for the patch, this stuff is exactly why my client funded getting a regular CI going for Android.

comment:6 by Cédric OCHS <kervala@…>, 8 years ago

You're welcome :)

comment:7 by viboes, 8 years ago

@Niall: if V2 is the minimal version, could this restriction be encoded on the config.hpp file.

comment:8 by viboes, 8 years ago

Owner: changed from Niall Douglas to viboes
Status: newassigned

You should create a ticket and a patch for Boost Config (boost/config/posix_features.hpp).

I will fix this soon.

comment:10 by viboes, 8 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.