then :
printf "%s\n" "#define HAVE_GETRUSAGE 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "gettid" "ac_cv_func_gettid"
+if test "x$ac_cv_func_gettid" = xyes
+then :
+ printf "%s\n" "#define HAVE_GETTID 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "jrand48" "ac_cv_func_jrand48"
if test "x$ac_cv_func_jrand48" = xyes
then :
printf "%s\n" "#define HAVE_PTHREAD_SETNAME_NP 1" >>confdefs.h
+fi
+ac_fn_c_check_func "$LINENO" "pthread_threadid_np" "ac_cv_func_pthread_threadid_np"
+if test "x$ac_cv_func_pthread_threadid_np" = xyes
+then :
+ printf "%s\n" "#define HAVE_PTHREAD_THREADID_NP 1" >>confdefs.h
+
fi
ac_fn_c_check_func "$LINENO" "qsort_r" "ac_cv_func_qsort_r"
if test "x$ac_cv_func_qsort_r" = xyes
getrandom
getrlimit
getrusage
+ gettid
jrand48
keyctl
llistxattr
pread64
pwrite64
pthread_setname_np
+ pthread_threadid_np
qsort_r
secure_getenv
setmntent
/* Define if the GNU gettext() function is already present or preinstalled. */
#undef HAVE_GETTEXT
+/* Define to 1 if you have the 'gettid' function. */
+#undef HAVE_GETTID
+
/* Define to 1 if you have the GNU-style 'qsort_r' function. */
#undef HAVE_GNU_QSORT_R
/* Define to 1 if you have the 'pthread_setname_np' function. */
#undef HAVE_PTHREAD_SETNAME_NP
+/* Define to 1 if you have the 'pthread_threadid_np' function. */
+#undef HAVE_PTHREAD_THREADID_NP
+
/* Define to 1 if you have the 'pwrite' function. */
#undef HAVE_PWRITE
quotaio.o \
quotaio_v2.o \
quotaio_tree.o \
+ thread.o \
dict.o \
devname.o
$(srcdir)/quotaio.c \
$(srcdir)/quotaio_tree.c \
$(srcdir)/quotaio_v2.c \
+ $(srcdir)/thread.c \
$(srcdir)/dict.c \
$(srcdir)/devname.c
$(Q) $(CC) -o test_cstring -DDEBUG_PROGRAM $(srcdir)/cstring.c \
$(ALL_CFLAGS)
+test_thread: $(srcdir)/thread.c
+ $(E) " CC $@"
+ $(Q) $(CC) -o test_thread -DDEBUG_PROGRAM $(srcdir)/thread.c \
+ $(ALL_CFLAGS)
+
clean::
$(RM) -f \#* *.s *.o *.a *~ *.bak core profiled/* \
../libsupport.a ../libsupport_p.a $(SMANPAGES) \
- prof_err.c prof_err.h test_profile test_cstring
+ prof_err.c prof_err.h test_profile test_cstring test_thread
#fullcheck check:: tst_uuid
# LD_LIBRARY_PATH=$(LIB) DYLD_LIBRARY_PATH=$(LIB) ./tst_uuid
argv_parse.o: $(srcdir)/argv_parse.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/argv_parse.h
bthread.o: $(srcdir)/bthread.c $(top_builddir)/lib/config.h \
- $(srcdir)/bthread.h
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/bthread.h
cstring.o: $(srcdir)/cstring.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/cstring.h
mkquota.o: $(srcdir)/mkquota.c $(top_builddir)/lib/config.h \
$(top_srcdir)/lib/ext2fs/ext2_ext_attr.h $(top_srcdir)/lib/ext2fs/hashmap.h \
$(top_srcdir)/lib/ext2fs/bitops.h $(srcdir)/dqblk_v2.h \
$(srcdir)/quotaio_tree.h
+thread.o: $(srcdir)/thread.c $(top_builddir)/lib/config.h \
+ $(top_builddir)/lib/dirpaths.h $(srcdir)/thread.h
dict.o: $(srcdir)/dict.c $(top_builddir)/lib/config.h \
$(top_builddir)/lib/dirpaths.h $(srcdir)/dict.h
devname.o: $(srcdir)/devname.c $(top_builddir)/lib/config.h \
--- /dev/null
+/*
+ * thread.c - utility functions for Posix threads
+ */
+
+#include "config.h"
+#ifdef HAVE_PTHREAD
+#include <pthread.h>
+#endif
+#include <stdint.h>
+#include <stdio.h>
+#include <unistd.h>
+
+#include "support/thread.h"
+
+uint64_t get_thread_id(void)
+{
+#if defined(HAVE_GETTID)
+ return gettid();
+#elif defined(HAVE_PTHREAD_THREADID_NP)
+ uint64_t tid;
+
+ if (pthread_threadid_np(NULL, &tid))
+ return tid;
+#elif defined(HAVE_PTHREAD)
+ return (__u64)(uintptr_t) pthread_self();
+#endif
+ return getpid();
+}
+
+#ifdef DEBUG_PROGRAM
+int main(int argc, char **argv)
+{
+ printf("Thread id: %llu\n", get_thread_id());
+ return 0;
+}
+#endif
--- /dev/null
+/*
+ * thread.h -- header file for thread utilities
+ */
+
+uint64_t get_thread_id(void);
#include "ext2fs/ext2_fs.h"
#include "ext2fs/ext2fsP.h"
#include "support/bthread.h"
+#include "support/thread.h"
#if FUSE_VERSION >= FUSE_MAKE_VERSION(3, 0)
# define FUSE_PLATFORM_OPTS ""
#else
#define dbg_printf(fuse2fs, format, ...) \
while ((fuse2fs)->debug) { \
- printf("FUSE2FS (%s): tid=%d " format, (fuse2fs)->shortdev, gettid(), ##__VA_ARGS__); \
+ printf("FUSE2FS (%s): tid=%llu " format, (fuse2fs)->shortdev, get_thread_id(), ##__VA_ARGS__); \
fflush(stdout); \
break; \
}