Introduce osmo_gettid() API

This API wraps conventional gettid() linux-specific API, which even in
Linux itself is sometimes not properly supported/announced.

This API also allows future porting to other platforms if needed, and so
far falls back to getpid() if no gettid(9 can be found.

Code ported from osmo-trx.git, see commit 7a07de1efd4eb7cc11c33d3ad25cb2df70aa1ef1.

Related: OS#5027
Change-Id: Id7534beeb22fcd50813dab76dd68818e2ff87ec2
diff --git a/configure.ac b/configure.ac
index 2a6a180..f5af0d0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -134,6 +134,16 @@
 
 CHECK_TM_INCLUDES_TM_GMTOFF
 
+# Check if gettid is available (despite not being documented in glibc doc,
+# it requires __USE_GNU on some systems)
+# C compiler is used since __USE_GNU seems to be always defined for g++.
+save_CPPFLAGS=$CPPFLAGS
+AC_LANG_PUSH(C)
+CPPFLAGS="$CPPFLAGS -D_GNU_SOURCE"
+AC_CHECK_FUNCS([gettid])
+AC_LANG_POP(C)
+CPPFLAGS=$save_CPPFLAGS
+
 dnl Check if We need to apply workaround for TLS bug on ARM platform for GCC < 7.3.0:
 ARG_ENABLE_DETECT_TLS_GCC_ARM_BUG