Back to index

courier  0.68.2
threadlib.c
Go to the documentation of this file.
00001 /* Multithreading primitives.
00002    Copyright (C) 2005-2009 Free Software Foundation, Inc.
00003 
00004    This program is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU Library General Public License as published
00006    by the Free Software Foundation; either version 2, or (at your option)
00007    any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public
00015    License along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
00017    USA.  */
00018 
00019 /* Written by Bruno Haible <bruno@clisp.org>, 2005.  */
00020 
00021 #include <config.h>
00022 
00023 /* ========================================================================= */
00024 
00025 #if USE_POSIX_THREADS
00026 
00027 /* Use the POSIX threads library.  */
00028 
00029 # include <pthread.h>
00030 # include <stdlib.h>
00031 
00032 # if PTHREAD_IN_USE_DETECTION_HARD
00033 
00034 /* The function to be executed by a dummy thread.  */
00035 static void *
00036 dummy_thread_func (void *arg)
00037 {
00038   return arg;
00039 }
00040 
00041 int
00042 glthread_in_use (void)
00043 {
00044   static int tested;
00045   static int result; /* 1: linked with -lpthread, 0: only with libc */
00046 
00047   if (!tested)
00048     {
00049       pthread_t thread;
00050 
00051       if (pthread_create (&thread, NULL, dummy_thread_func, NULL) != 0)
00052         /* Thread creation failed.  */
00053         result = 0;
00054       else
00055         {
00056           /* Thread creation works.  */
00057           void *retval;
00058           if (pthread_join (thread, &retval) != 0)
00059             abort ();
00060           result = 1;
00061         }
00062       tested = 1;
00063     }
00064   return result;
00065 }
00066 
00067 # endif
00068 
00069 #endif
00070 
00071 /* ========================================================================= */
00072 
00073 /* This declaration is solely to ensure that after preprocessing
00074    this file is never empty.  */
00075 typedef int dummy;