[osg-submissions] OpenThreads configury and hostspecific parts

Mathias Froehlich M.Froehlich at science-computing.de
Thu Sep 27 01:29:35 PDT 2007


Hi Robert,

the long promised patch to implement the sched_setaffinity in a way that 
matches the system it is compiled on.
That is there is a cmake configure test to make sure we use the version 
available on the system

There are also various improovements to other system specific methods for less 
common architectures.

The attached files arebased on rev 7491. The CMakeLists.txt file is the one in 
src/OpenThreads/pthreads/CMakeLists.txt

Please apply

     thanks

         Mathias

-- 
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511
-- 
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Florian Geyer,
Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Prof. Dr. Hanns Ruder
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196 

-------------- next part --------------
# This file should only be included when using Pthreads

INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)
INCLUDE (CheckSymbolExists)
INCLUDE (CheckCXXSourceCompiles)

SET(LIB_NAME OpenThreads)
SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS})

ADD_LIBRARY(${LIB_NAME}
    ${OPENTHREADS_USER_DEFINED_DYNAMIC_OR_STATIC}
    ${LIB_PUBLIC_HEADERS}
	PThread.c++
	PThreadBarrier.c++
	PThreadBarrierPrivateData.h
	PThreadCondition.c++
	PThreadConditionPrivateData.h
	PThreadMutex.c++
	PThreadMutexPrivateData.h
	PThreadPrivateData.h
	../common/Version.cpp
)

IF(OPENTHREADS_SONAMES)
  SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${OPENTHREADS_VERSION} SOVERSION ${OPENTHREADS_SOVERSION})
ENDIF(OPENTHREADS_SONAMES)

SET(CMAKE_REQUIRED_LIBRARIES_SAFE "${CMAKE_REQUIRED_LIBRARIES}")
SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}")

CHECK_FUNCTION_EXISTS(pthread_yield HAVE_PTHREAD_YIELD)
IF(HAVE_PTHREAD_YIELD)
  ADD_DEFINITIONS(-DHAVE_PTHREAD_YIELD)
ELSE(HAVE_PTHREAD_YIELD)
  # sched_yield appears not in libc, pthreads or whatever on some systems
  CHECK_FUNCTION_EXISTS(sched_yield HAVE_SCHED_YIELD)
  IF(NOT HAVE_SCHED_YIELD)
    CHECK_LIBRARY_EXISTS(rt sched_yield "" HAVE_SCHED_YIELD)
    IF(HAVE_SCHED_YIELD)
      SET(CMAKE_THREAD_LIBS_INIT "${CMAKE_THREAD_LIBS_INIT} -lrt")
    ENDIF(HAVE_SCHED_YIELD)
  ENDIF(NOT HAVE_SCHED_YIELD)
  IF(HAVE_SCHED_YIELD)
    ADD_DEFINITIONS(-DHAVE_SCHED_YIELD)
  ENDIF(HAVE_SCHED_YIELD)
ENDIF(HAVE_PTHREAD_YIELD)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  # need to have that for pthread_setaffinity_np on linux
  ADD_DEFINITIONS(-D_GNU_SOURCE)
  SET(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} -D_GNU_SOURCE")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

CHECK_FUNCTION_EXISTS(pthread_setconcurrency HAVE_PTHREAD_SETCONCURRENCY)
IF(HAVE_PTHREAD_SETCONCURRENCY)
  ADD_DEFINITIONS(-DHAVE_PTHREAD_SETCONCURRENCY)
ENDIF(HAVE_PTHREAD_SETCONCURRENCY)

CHECK_FUNCTION_EXISTS(pthread_getconcurrency HAVE_PTHREAD_GETCONCURRENCY)
IF(HAVE_PTHREAD_GETCONCURRENCY)
  ADD_DEFINITIONS(-DHAVE_PTHREAD_GETCONCURRENCY)
ENDIF(HAVE_PTHREAD_GETCONCURRENCY)

CHECK_FUNCTION_EXISTS(pthread_setaffinity_np HAVE_PTHREAD_SETAFFINITY_NP)
IF(HAVE_PTHREAD_SETAFFINITY_NP)
  ADD_DEFINITIONS(-DHAVE_PTHREAD_SETAFFINITY_NP)
ELSE(HAVE_PTHREAD_SETAFFINITY_NP)
  CHECK_CXX_SOURCE_COMPILES("
#include <sched.h>
int main() {
  cpu_set_t cpumask;
  sched_setaffinity( 0, sizeof(cpumask), &cpumask );
  return 0;
}" HAVE_THREE_PARAM_SCHED_SETAFFINITY)
  IF(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
    ADD_DEFINITIONS(-DHAVE_THREE_PARAM_SCHED_SETAFFINITY)
  ELSE(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
    CHECK_CXX_SOURCE_COMPILES("
#include <sched.h>
int main() {
  cpu_set_t cpumask;
  sched_setaffinity( 0, &cpumask );
  return 0;
}" HAVE_TWO_PARAM_SCHED_SETAFFINITY)
    IF(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
      ADD_DEFINITIONS(-DHAVE_TWO_PARAM_SCHED_SETAFFINITY)
    ENDIF(HAVE_TWO_PARAM_SCHED_SETAFFINITY)
  ENDIF(HAVE_THREE_PARAM_SCHED_SETAFFINITY)
ENDIF(HAVE_PTHREAD_SETAFFINITY_NP)

SET(CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES_SAFE}")

TARGET_LINK_LIBRARIES(${LIB_NAME}
	${CMAKE_THREAD_LIBS_INIT}
)

# Since we're building different platforms binaries in 
# their respective directories, we need to set the 
# link directory so it can find this location.
LINK_DIRECTORIES(
	${CMAKE_CURRENT_BINARY_DIR}
)

INSTALL(
	TARGETS OpenThreads
	ARCHIVE DESTINATION lib${LIB_POSTFIX}
	LIBRARY DESTINATION lib${LIB_POSTFIX}
	RUNTIME DESTINATION bin
)
INSTALL(
	FILES ${OpenThreads_PUBLIC_HEADERS}
	DESTINATION include/OpenThreads
)

#commented out# INCLUDE(ModuleInstall OPTIONAL)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PThread.c++
Type: text/x-c++src
Size: 23415 bytes
Desc: not available
Url : http://lists.openscenegraph.org/pipermail/osg-submissions-openscenegraph.org/attachments/20070927/917896af/attachment-0001.c++ 


More information about the osg-submissions mailing list