Skip to contentSkip to conversation

Dont link pthread on Android

PATCH New Charles Briere 2 participants 7 messages Nov 27, 2013 4 messages not in the archive Kbuild

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 2/5 Dont link pthread on Android

On Android, pthread is already part of libc
called Bionic and doesn't have an external
library to link with.

---
 Makefile.am                  | 5 ++++-
 tests/benchmark/Makefile.am  | 4 +++-
 tests/regression/Makefile.am | 4 +++-
 tests/unit/Makefile.am       | 4 +++-
 4 files changed, 13 insertions(+), 4 deletions(-)
Makefile.am +4 -1
index e09778f..baac8b9 100644
@@ -4,7 +4,10 @@ INCLUDES = -I$(top_builddir)/urcu
 
 #Add the -version-info directly here since we are only building
 # library that use the version-info
-AM_LDFLAGS=-lpthread -version-info $(URCU_LIBRARY_VERSION)
+AM_LDFLAGS=-version-info $(URCU_LIBRARY_VERSION)
+if !TARGET_IS_ANDROID
+AM_LDFLAGS += -lpthread
+endif
 AM_CFLAGS=-Wall
 
 SUBDIRS = . doc tests
tests/benchmark/Makefile.am +3 -1
index e071034..91ba1da 100644
@@ -1,4 +1,6 @@
-AM_LDFLAGS=-lpthread
+if !TARGET_IS_ANDROID
+AM_LDFLAGS += -lpthread
+endif
 AM_CFLAGS=-I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/tests/common -g
 
 noinst_PROGRAMS = test_urcu test_urcu_dynamic_link test_urcu_timing \
tests/regression/Makefile.am +3 -1
index 2c0542f..2cefa33 100644
@@ -1,4 +1,6 @@
-AM_LDFLAGS=-lpthread
+if !TARGET_IS_ANDROID
+AM_LDFLAGS += -lpthread
+endif
 AM_CFLAGS=-I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/tests/common -g
 
 noinst_PROGRAMS = test_urcu_fork \
tests/unit/Makefile.am +3 -1
index 1fa8b71..85860e2 100644
@@ -1,4 +1,6 @@
-AM_LDFLAGS=-lpthread
+if !TARGET_IS_ANDROID
+AM_LDFLAGS += -lpthread
+endif
 AM_CFLAGS=-I$(top_srcdir) -I$(top_builddir) -I$(top_srcdir)/tests/common -g
 
 noinst_PROGRAMS = test_uatomic \
Signature · 1 line
1.8.4.2
#2 lore raw

PATCH 3/5 Added a compat layer for 'syscall.h'

In reply to a message not in the archive

From: Pierre-Luc St-Charles <[email protected]>

Path to include syscall.h is different on Android

---
 Makefile.am              |  2 +-
 tests/common/thread-id.h |  5 ++---
 urcu.c                   |  2 +-
 urcu/futex.h             |  2 +-
 urcu/syscall-compat.h    | 34 ++++++++++++++++++++++++++++++++++
 5 files changed, 39 insertions(+), 6 deletions(-)
 create mode 100644 urcu/syscall-compat.h
Makefile.am +1 -1
index baac8b9..64073a1 100644
@@ -20,7 +20,7 @@ nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h urcu/list.h \
 		urcu/wfqueue.h urcu/rculfstack.h urcu/rculfqueue.h \
 		urcu/ref.h urcu/cds.h urcu/urcu_ref.h urcu/urcu-futex.h \
 		urcu/uatomic_arch.h urcu/rculfhash.h urcu/wfcqueue.h \
-		urcu/lfstack.h \
+		urcu/lfstack.h urcu/syscall-compat.h \
 		$(top_srcdir)/urcu/map/*.h \
 		$(top_srcdir)/urcu/static/*.h \
 		urcu/tls-compat.h
tests/common/thread-id.h +2 -3
index 9378edc..bad3006 100644
@@ -17,9 +17,8 @@
  * provided the above notices are retained, and a notice that the code was
  * modified is included with the above copyright notice.
  */
-
-#ifdef __linux__
-# include <syscall.h>
+#ifdef __Linux__
+# include <urcu/syscall-compat.h>
 
 # if defined(_syscall0)
 _syscall0(pid_t, gettid)
urcu.c +1 -1
index 759b94b..69ebcaa 100644
@@ -66,7 +66,7 @@
  * RCU_MEMBARRIER is only possibly available on Linux.
  */
 #if defined(RCU_MEMBARRIER) && defined(__linux__)
-#include <syscall.h>
+#include <urcu/syscall-compat.h>
 #endif
 
 /* If the headers do not support SYS_membarrier, fall back on RCU_MB */
urcu/futex.h +1 -1
index cdaa430..bb270c2 100644
@@ -45,7 +45,7 @@ extern "C" {
  */
 
 #ifdef CONFIG_RCU_HAVE_FUTEX
-#include <syscall.h>
+#include <urcu/syscall-compat.h>
 #define futex(...)	syscall(__NR_futex, __VA_ARGS__)
 #define futex_noasync(uaddr, op, val, timeout, uaddr2, val3)	\
 		futex(uaddr, op, val, timeout, uaddr2, val3)
urcu/syscall-compat.h new file +34 -0
new file mode 100644
index 0000000..96cfa3a
@@ -0,0 +1,34 @@
+#ifndef _URCU_SYSCALL_COMPAT_H
+#define _URCU_SYSCALL_COMPAT_H
+
+/*
+ * urcu/syscall-compat.h
+ *
+ * Userspace RCU library - Syscall Compatibility Header
+ *
+ * Note: this file is only used to simplify the code required to
+ * include the 'syscall.h' system header across multiple platforms,
+ * which might not always be located at the same place (or needed at all).
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#if defined(__ANDROID__)
+#include <sys/syscall.h>
+#elif defined(__linux__)
+#include <syscall.h>
+#endif
+
+#endif /* _URCU_SYSCALL_COMPAT_H */
Signature · 1 line
1.8.4.2
#3 lore raw

PATCH 4/5 Fix: Do not redefine gettid on Android

In reply to a message not in the archive

Bionic already defines gettid through <unistd.h>

---
 tests/common/thread-id.h | 3 +++
 1 file changed, 3 insertions(+)
tests/common/thread-id.h +3 -0
index bad3006..a2c9e3a 100644
@@ -42,6 +42,9 @@ unsigned long urcu_get_thread_id(void)
 {
 	return (unsigned long) pthread_getthreadid_np();
 }
+#elif defined(__Android__)
+// Do not redefine gettid() as it is already included
+// in bionic through <unistd.h>
 #else
 # warning "use pid as thread ID"
 static inline
Signature · 1 line
1.8.4.2
#4 lore raw

PATCH 5/5 Added implementation for rand_r()

In reply to a message not in the archive

From: Pierre-Luc St-Charles <[email protected]>

stdlib.h doesn't implement rand_r() on Android.

---
 Makefile.am                      |  1 +
 tests/benchmark/test_urcu_hash.h |  1 +
 urcu/rand-compat.h               | 60 ++++++++++++++++++++++++++++++++++++++++
 urcu/static/urcu.h               |  1 +
 4 files changed, 63 insertions(+)
 create mode 100644 urcu/rand-compat.h
Makefile.am +1 -0
index 64073a1..38ff543 100644
@@ -23,6 +23,7 @@ nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h urcu/list.h \
 		urcu/lfstack.h urcu/syscall-compat.h \
 		$(top_srcdir)/urcu/map/*.h \
 		$(top_srcdir)/urcu/static/*.h \
+		urcu/rand-compat.h \
 		urcu/tls-compat.h
 nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic.h urcu/config.h
 
tests/benchmark/test_urcu_hash.h +1 -0
index c0727b7..b35acdb 100644
@@ -37,6 +37,7 @@
 #include <signal.h>
 
 #include <urcu/tls-compat.h>
+#include <urcu/rand-compat.h>
 #include "cpuset.h"
 #include "thread-id.h"
 
urcu/rand-compat.h new file +60 -0

60 lines not on this page · raw message

urcu/static/urcu.h +1 -0
index 53d2610..33545b7 100644
@@ -41,6 +41,7 @@
 #include <urcu/list.h>
 #include <urcu/futex.h>
 #include <urcu/tls-compat.h>
+#include <urcu/rand-compat.h>
 
 #ifdef __cplusplus
 extern "C" {
Signature · 1 line
1.8.4.2

A message that is not in the archive (sent off-list or not yet received): [email protected]

#6 lore raw

Re: [PATCH liburcu 4/5] Fix: Do not redefine gettid on Android

----- Original Message -----

Quoted 18 lines

From: "Charles Briere" <[email protected]>
To: "mathieu desnoyers" <[email protected]>
Cc: [email protected], "Charles Briere" <[email protected]>
Sent: Wednesday, November 27, 2013 12:08:21 AM
Subject: [PATCH liburcu 4/5] Fix: Do not redefine gettid on Android

Bionic already defines gettid through <unistd.h>

---
 tests/common/thread-id.h | 3 +++
 1 file changed, 3 insertions(+)
tests/common/thread-id.h +0 -0
index bad3006..a2c9e3a 100644

tests/common/thread-id.h unsigned long urcu_get_thread_id(void) · line 47

Quoted 6 lines
tests/common/thread-id.h +3 -0
@@ -42,6 +42,9 @@ unsigned long urcu_get_thread_id(void)
 {
 	return (unsigned long) pthread_getthreadid_np();
 }
+#elif defined(__Android__)
+// Do not redefine gettid() as it is already included
+// in bionic through <unistd.h>

Please use

/*
* blah
* blah blah
*/

style comments,

Thanks,

Mathieu

Quoted 7 lines
tests/common/thread-id.h +0 -1
 #else
 # warning "use pid as thread ID"
 static inline
--

1.8.4.2

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#8 lore raw

Re: [PATCH liburcu 3/5] Added a compat layer for 'syscall.h'

----- Original Message -----

Quoted 83 lines

From: "Charles Briere" <[email protected]>
To: "mathieu desnoyers" <[email protected]>
Cc: [email protected], "Pierre-Luc St-Charles" <[email protected]>, "Charles Briere" <[email protected]>
Sent: Wednesday, November 27, 2013 12:08:20 AM
Subject: [PATCH liburcu 3/5] Added a compat layer for 'syscall.h'

From: Pierre-Luc St-Charles <[email protected]>

Path to include syscall.h is different on Android

---
 Makefile.am              |  2 +-
 tests/common/thread-id.h |  5 ++---
 urcu.c                   |  2 +-
 urcu/futex.h             |  2 +-
 urcu/syscall-compat.h    | 34 ++++++++++++++++++++++++++++++++++
 5 files changed, 39 insertions(+), 6 deletions(-)
 create mode 100644 urcu/syscall-compat.h
Makefile.am +1 -1
index baac8b9..64073a1 100644
@@ -20,7 +20,7 @@ nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h
 urcu/list.h \
 		urcu/wfqueue.h urcu/rculfstack.h urcu/rculfqueue.h \
 		urcu/ref.h urcu/cds.h urcu/urcu_ref.h urcu/urcu-futex.h \
 		urcu/uatomic_arch.h urcu/rculfhash.h urcu/wfcqueue.h \
-		urcu/lfstack.h \
+		urcu/lfstack.h urcu/syscall-compat.h \
 		$(top_srcdir)/urcu/map/*.h \
 		$(top_srcdir)/urcu/static/*.h \
Makefile.am +0 -0
 		urcu/tls-compat.h
tests/common/thread-id.h +2 -3
index 9378edc..bad3006 100644
@@ -17,9 +17,8 @@
  * provided the above notices are retained, and a notice that the code was
  * modified is included with the above copyright notice.
  */
-
-#ifdef __linux__
-# include <syscall.h>
+#ifdef __Linux__
+# include <urcu/syscall-compat.h>
 
 # if defined(_syscall0)
 _syscall0(pid_t, gettid)
urcu.c +1 -1
index 759b94b..69ebcaa 100644
@@ -66,7 +66,7 @@
  * RCU_MEMBARRIER is only possibly available on Linux.
  */
 #if defined(RCU_MEMBARRIER) && defined(__linux__)
-#include <syscall.h>
+#include <urcu/syscall-compat.h>
 #endif
 
 /* If the headers do not support SYS_membarrier, fall back on RCU_MB */
urcu/futex.h +1 -1
index cdaa430..bb270c2 100644
@@ -45,7 +45,7 @@ extern "C" {
  */
 
 #ifdef CONFIG_RCU_HAVE_FUTEX
-#include <syscall.h>
+#include <urcu/syscall-compat.h>
 #define futex(...)	syscall(__NR_futex, __VA_ARGS__)
 #define futex_noasync(uaddr, op, val, timeout, uaddr2, val3)	\
 		futex(uaddr, op, val, timeout, uaddr2, val3)
urcu/syscall-compat.h new file +0 -0
new file mode 100644
index 0000000..96cfa3a

urcu/syscall-compat.h line 8

Quoted 8 lines
urcu/syscall-compat.h new file +8 -0
@@ -0,0 +1,34 @@
+#ifndef _URCU_SYSCALL_COMPAT_H
+#define _URCU_SYSCALL_COMPAT_H
+
+/*
+ * urcu/syscall-compat.h
+ *
+ * Userspace RCU library - Syscall Compatibility Header
+ *

Please add your

Copyright - First Last <email>

Line.

Thanks,

Mathieu

Quoted 31 lines
urcu/syscall-compat.h new file +17 -0
+ * Note: this file is only used to simplify the code required to
+ * include the 'syscall.h' system header across multiple platforms,
+ * which might not always be located at the same place (or needed at all).
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301

USA
+ */

urcu/syscall-compat.h new file +8 -1
+
+#if defined(__ANDROID__)
+#include <sys/syscall.h>
+#elif defined(__linux__)
+#include <syscall.h>
+#endif
+
+#endif /* _URCU_SYSCALL_COMPAT_H */
--

1.8.4.2

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#10 lore raw

Re: [PATCH liburcu 5/5] Added implementation for rand_r()

----- Original Message -----

Quoted 53 lines

From: "Charles Briere" <[email protected]>
To: "mathieu desnoyers" <[email protected]>
Cc: [email protected], "Pierre-Luc St-Charles" <[email protected]>, "Charles Briere" <[email protected]>
Sent: Wednesday, November 27, 2013 12:08:22 AM
Subject: [PATCH liburcu 5/5] Added implementation for rand_r()

From: Pierre-Luc St-Charles <[email protected]>

stdlib.h doesn't implement rand_r() on Android.

---
 Makefile.am                      |  1 +
 tests/benchmark/test_urcu_hash.h |  1 +
 urcu/rand-compat.h               | 60
 ++++++++++++++++++++++++++++++++++++++++
 urcu/static/urcu.h               |  1 +
 4 files changed, 63 insertions(+)
 create mode 100644 urcu/rand-compat.h
Makefile.am +1 -0
index 64073a1..38ff543 100644
@@ -23,6 +23,7 @@ nobase_dist_include_HEADERS = urcu/compiler.h urcu/hlist.h
 urcu/list.h \
 		urcu/lfstack.h urcu/syscall-compat.h \
 		$(top_srcdir)/urcu/map/*.h \
 		$(top_srcdir)/urcu/static/*.h \
+		urcu/rand-compat.h \
 		urcu/tls-compat.h
 nobase_nodist_include_HEADERS = urcu/arch.h urcu/uatomic.h urcu/config.h
tests/benchmark/test_urcu_hash.h +1 -0
index c0727b7..b35acdb 100644
@@ -37,6 +37,7 @@
 #include <signal.h>
 
 #include <urcu/tls-compat.h>
+#include <urcu/rand-compat.h>
 #include "cpuset.h"
 #include "thread-id.h"
 
urcu/rand-compat.h new file +0 -0
new file mode 100644
index 0000000..b9545c8

urcu/rand-compat.h line 8

Quoted 8 lines
urcu/rand-compat.h new file +8 -0
@@ -0,0 +1,60 @@
+#ifndef _URCU_RAND_COMPAT_H
+#define _URCU_RAND_COMPAT_H
+
+/*
+ * urcu/rand-compat.h
+ *
+ * Userspace RCU library - rand/rand_r Compatibility Header
+ *

Also missing copyright line. You probably want to put both your own copyright, and the copyright from Ulrich Drepper here.

Thanks,

Mathieu

Quoted 70 lines
urcu/rand-compat.h new file +17 -0
+ * Note: this file is only used to simplify the code required to
+ * use the 'rand_r(...)' system function across multiple platforms,
+ * which might not always be referenced the same way.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301

USA
+ */

urcu/rand-compat.h new file +7 -0
+
+#ifdef __ANDROID__
+/*
+ * Reentrant random function from POSIX.1c.
+ * Copyright (C) 1996, 1999 Free Software Foundation, Inc.
+ * This file is part of the GNU C Library.
+ * Contributed by Ulrich Drepper <[email protected]

<mailto:[email protected]>>, 1996.
+ */

urcu/rand-compat.h new file +26 -0
+static inline int rand_r(unsigned int *seed)
+{
+       unsigned int next = *seed;
+       int result;
+
+       next *= 1103515245;
+       next += 12345;
+       result = (unsigned int) (next / 65536) % 2048;
+
+       next *= 1103515245;
+       next += 12345;
+       result <<= 10;
+       result ^= (unsigned int) (next / 65536) % 1024;
+
+       next *= 1103515245;
+       next += 12345;
+       result <<= 10;
+       result ^= (unsigned int) (next / 65536) % 1024;
+
+       *seed = next;
+
+       return result;
+}
+#endif /* __ANDROID__ */
+
+#endif /* _URCU_RAND_COMPAT_H */
urcu/static/urcu.h +1 -1
index 53d2610..33545b7 100644
@@ -41,6 +41,7 @@
 #include <urcu/list.h>
 #include <urcu/futex.h>
 #include <urcu/tls-compat.h>
+#include <urcu/rand-compat.h>
 
 #ifdef __cplusplus
 extern "C" {
--

1.8.4.2

Signature · 3 lines
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com