From: Martin Quinson Date: Mon, 27 Jun 2011 11:57:37 +0000 (+0200) Subject: make sure that if semaphore are not usable, we detect it and complain as we should X-Git-Tag: v3_6_1~4 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/b3141365cdcea8da7c4af506703ae369c3948bf8 make sure that if semaphore are not usable, we detect it and complain as we should --- diff --git a/buildtools/Cmake/CompleteInFiles.cmake b/buildtools/Cmake/CompleteInFiles.cmake index 94271ab18b..c5883acdc4 100644 --- a/buildtools/Cmake/CompleteInFiles.cmake +++ b/buildtools/Cmake/CompleteInFiles.cmake @@ -88,6 +88,7 @@ endif(enable_ns3) # Checks for header libraries functions. CHECK_LIBRARY_EXISTS(pthread pthread_create "" pthread) CHECK_LIBRARY_EXISTS(pthread sem_init "" HAVE_SEM_INIT_LIB) +CHECK_LIBRARY_EXISTS(pthread sem_open "" HAVE_SEM_OPEN_LIB) CHECK_LIBRARY_EXISTS(pthread sem_timedwait "" HAVE_SEM_TIMEDWAIT_LIB) CHECK_LIBRARY_EXISTS(pthread pthread_mutex_timedlock "" HAVE_MUTEX_TIMEDLOCK_LIB) CHECK_LIBRARY_EXISTS(rt clock_gettime "" HAVE_POSIX_GETTIME) @@ -205,18 +206,47 @@ elseif(pthread) endif(pthread) if(pthread) - ### HAVE_SEM_INIT + ### Test that we have a way to create semaphores + if(HAVE_SEM_OPEN_LIB) + exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_open.c -o testprog" + OUTPUT_VARIABLE HAVE_SEM_OPEN_run) + if(HAVE_SEM_OPEN_run) + set(HAVE_SEM_OPEN 0) + else(HAVE_SEM_OPEN_run) + exec_program("./testprog" RETURN_VALUE HAVE_SEM_OPEN_run2) + if(HAVE_SEM_OPEN_run2) + set(HAVE_SEM_OPEN 0) + else(HAVE_SEM_OPEN_run2) + set(HAVE_SEM_OPEN 1) + endif(HAVE_SEM_OPEN_run2) + endif(HAVE_SEM_OPEN_run) + else(HAVE_SEM_OPEN_LIB) + set(HAVE_SEM_OPEN 0) + endif(HAVE_SEM_OPEN_LIB) + if(HAVE_SEM_INIT_LIB) - exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c" OUTPUT_VARIABLE HAVE_SEM_INIT_run) + exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_init.c -o testprog" + OUTPUT_VARIABLE HAVE_SEM_INIT_run) if(HAVE_SEM_INIT_run) set(HAVE_SEM_INIT 0) else(HAVE_SEM_INIT_run) - set(HAVE_SEM_INIT 1) + exec_program("./testprog" RETURN_VALUE HAVE_SEM_INIT_run) + if(HAVE_SEM_INIT_run) + set(HAVE_SEM_INIT 0) + else(HAVE_SEM_INIT_run) + set(HAVE_SEM_INIT 1) + endif(HAVE_SEM_INIT_run) endif(HAVE_SEM_INIT_run) + else(HAVE_SEM_INIT_LIB) + set(HAVE_SEM_INIT 0) endif(HAVE_SEM_INIT_LIB) - ### HAVE_SEM_TIMEDWAIT + if(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT) + message(FATAL_ERROR "Semaphores are not usable, but they are mandatory to threads (you may need to mount /dev).") + endif(NOT HAVE_SEM_OPEN AND NOT HAVE_SEM_INIT) + + ### Test that we have a way to timewait for semaphores if(HAVE_SEM_TIMEDWAIT_LIB) exec_program("${CMAKE_C_COMPILER} -lpthread ${CMAKE_HOME_DIRECTORY}/buildtools/Cmake/test_prog/prog_sem_timedwait.c" OUTPUT_VARIABLE HAVE_SEM_TIMEDWAIT_run) diff --git a/buildtools/Cmake/test_prog/prog_sem_open.c b/buildtools/Cmake/test_prog/prog_sem_open.c new file mode 100644 index 0000000000..4679c32f1b --- /dev/null +++ b/buildtools/Cmake/test_prog/prog_sem_open.c @@ -0,0 +1,23 @@ +/* Copyright (c) 2010. The SimGrid Team. + * All rights reserved. */ + +/* This program is free software; you can redistribute it and/or modify it + * under the terms of the license (GNU LGPL) which comes with this package. */ + +#include +#include +#include +#include +#include + +int main(void) { + sem_t * s; + + s = sem_open("/0", O_CREAT, 0644, 10); + if (s == SEM_FAILED){ +// printf("sem_open failed\n"); + return 1; + } +// printf("sem_open succeeded\n"); + return 0; +}