[Android] Don't use the private bionic symbol __get_thread and pthread_internal_t

Martin Storsjö git at videolan.org
Mon Jun 23 20:12:42 CEST 2014


vlc-ports/android | branch: master | Martin Storsjö <martin at martin.st> | Mon Feb 24 14:25:31 2014 +0200| [bdb584181d2ce1e8170d755ec7f37132880f44fb] | committer: Martin Storsjö

Don't use the private bionic symbol __get_thread and pthread_internal_t

Use pthread_self() for getting a thread ID - pthread_self()
has been available since API level 3.

After android 4.4, the __get_thread symbol has been hidden, and
the pthread_internal_t struct has been changed.

Previously this used the internal pthread_internal_t struct
(which didn't change up until after 4.4) to get the system
global kernel thread id. For the rwlock code, this is overkill -
using a processwide thread ID is enough.

(Note that a pthread_t is defined as long, but writerThreadId
which stores the return value from __get_thread_id is an int,
thus this workaround shouldn't be used on 64 bit builds. But
it's never necessary on 64 bit builds, since all the
rwlock functions always exist there - they're only provided
for compatibility with pre-2.3 android versions.)

This fixes running VLC on devices running current AOSP master,
and quite probably also is required on the next major
android version.

If VLC drops support for pre-2.2 devices, the pthread-condattr.c
and pthread-once.c files can be removed, and once support for
pre-2.3 devices is dropped, all of pthread-rwlocks.c can be
removed.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=bdb584181d2ce1e8170d755ec7f37132880f44fb
---

 vlc-android/jni/pthread-rwlocks.c |   25 +++++--------------------
 1 file changed, 5 insertions(+), 20 deletions(-)

diff --git a/vlc-android/jni/pthread-rwlocks.c b/vlc-android/jni/pthread-rwlocks.c
index 3086fbd..10d12c0 100644
--- a/vlc-android/jni/pthread-rwlocks.c
+++ b/vlc-android/jni/pthread-rwlocks.c
@@ -60,28 +60,13 @@
 #define  RWLOCKATTR_DEFAULT     0
 #define  RWLOCKATTR_SHARED_MASK 0x0010
 
-/* __get_thread and pthread_internal_t didn't change since introduced,
- * up to ics */
-typedef struct pthread_internal_t
-{
-    struct pthread_internal_t*  next;
-    struct pthread_internal_t** pref;
-    pthread_attr_t              attr;
-    pid_t                       kernel_id;
-    pthread_cond_t              join_cond;
-    int                         join_count;
-    void*                       return_value;
-    int                         intern;
-    __pthread_cleanup_t*        cleanup_stack;
-    void**                      tls;         /* thread-local storage area */
-} pthread_internal_t;
-
-extern pthread_internal_t* __get_thread(void);
-
-/* Return a global kernel ID for the current thread */
 static int __get_thread_id(void)
 {
-    return __get_thread()->kernel_id;
+#ifdef __LP64__
+#error Don't build pthread fallbacks for 64 bit, use the proper functions
+#else
+    return pthread_self();
+#endif
 }
 
 int pthread_rwlockattr_init(pthread_rwlockattr_t *attr)



More information about the Android mailing list