X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Flock.c;h=a860459d12153ab23017ce64ddebd293e081311c;hb=633351a9c79940c871ce6ed4d182844239c1ef72;hp=5c14fa3a3ef85c59d993166a065d75a64df1d800;hpb=b5e2473ba6261543c2808f17dea46dc32da83412;p=gnulib.git diff --git a/lib/lock.c b/lib/lock.c index 5c14fa3a3..a860459d1 100644 --- a/lib/lock.c +++ b/lib/lock.c @@ -32,6 +32,43 @@ /* Use the POSIX threads library. */ +# if PTHREAD_IN_USE_DETECTION_HARD + +/* The function to be executed by a dummy thread. */ +static void * +dummy_thread_func (void *arg) +{ + return arg; +} + +int +glthread_in_use (void) +{ + static int tested; + static int result; /* 1: linked with -lpthread, 0: only with libc */ + + if (!tested) + { + pthread_t thread; + + if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0) + /* Thread creation failed. */ + result = 0; + else + { + /* Thread creation works. */ + void *retval; + if (pthread_join (thread, &retval) != 0) + abort (); + result = 1; + } + tested = 1; + } + return result; +} + +# endif + /* -------------------------- gl_lock_t datatype -------------------------- */ /* ------------------------- gl_rwlock_t datatype ------------------------- */