diff --git a/CMakeLists.txt b/CMakeLists.txt index a2740783..4118a5eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,7 +150,6 @@ include_directories(${ZLIB_INCLUDE_DIRS}) ####################################################################### if (USE_GUI) - set(CMAKE_THREAD_PREFER_PTHREAD ON) find_package(TCL 8.5) find_package(Threads REQUIRED) if(APPLE) @@ -163,7 +162,6 @@ if (USE_GUI) find_package(X11 REQUIRED) endif(APPLE) find_package(OpenGL REQUIRED) - find_library(LIBPTHREAD NAMES pthread HINTS ${MY_LIB_DIR} ) add_definitions(-DTCL -DOPENGL) include_directories(${TCL_INCLUDE_PATH}) diff --git a/libsrc/general/parthreads.hpp b/libsrc/general/parthreads.hpp index 4a7a9d66..0fe578b0 100644 --- a/libsrc/general/parthreads.hpp +++ b/libsrc/general/parthreads.hpp @@ -26,36 +26,20 @@ public: void UnLock () { ; } }; - #else -#ifdef _MSC_VER - -#ifdef MSVC_EXPRESS -// #include - - -class NgMutex -{ - pthread_mutex_t mut; -public: - NgMutex () - { - pthread_mutex_init (&mut, NULL); - } - friend class NgLock; -}; +typedef std::mutex NgMutex; class NgLock { - pthread_mutex_t & mut; + NgMutex & mut; bool locked; public: NgLock (NgMutex & ngmut, bool lock = false) - : mut (ngmut.mut) + : mut (ngmut) { if (lock) - pthread_mutex_lock (&mut); + mut.lock(); locked = lock; }; @@ -63,127 +47,27 @@ public: ~NgLock() { if (locked) - pthread_mutex_unlock (&mut); + mut.unlock(); } void Lock () { - pthread_mutex_lock (&mut); + mut.lock(); locked = true; } void UnLock () { - pthread_mutex_unlock (&mut); + mut.unlock(); locked = false; } /* int TryLock () { - return pthread_mutex_trylock (&mut); + return mut.try_lock(); } */ }; -#else // Using MS VC++ Standard / Enterprise / Professional edition... - - -class NgMutex -{ - CCriticalSection cs; - -public: - NgMutex () - { ; } - friend class NgLock; -}; - -class NgLock -{ - CSingleLock sl; - bool locked; -public: - NgLock (NgMutex & mut, bool lock = 0) - : sl(&mut.cs) - { - if (lock) sl.Lock(); - locked = lock; - } - - ~NgLock () - { - if (locked) sl.Unlock(); - } - - void Lock () - { - sl.Lock(); - locked = 1; - } - - void UnLock () - { - sl.Unlock(); - locked = 0; - } -}; - -#endif // MSVC_EXPRESS - -#else - - -// #include - -class NgMutex -{ - pthread_mutex_t mut; -public: - NgMutex () - { - pthread_mutex_init (&mut, NULL); - } - friend class NgLock; -}; - -class NgLock -{ - pthread_mutex_t & mut; - bool locked; -public: - NgLock (NgMutex & ngmut, bool lock = false) - : mut (ngmut.mut) - { - if (lock) - pthread_mutex_lock (&mut); - - locked = lock; - }; - - ~NgLock() - { - if (locked) - pthread_mutex_unlock (&mut); - } - - void Lock () - { - pthread_mutex_lock (&mut); - locked = true; - } - void UnLock () - { - pthread_mutex_unlock (&mut); - locked = false; - } - /* - int TryLock () - { - return pthread_mutex_trylock (&mut); - } - */ -}; - -#endif #endif diff --git a/libsrc/include/mystdlib.h b/libsrc/include/mystdlib.h index 7f672e6c..5cbaca61 100644 --- a/libsrc/include/mystdlib.h +++ b/libsrc/include/mystdlib.h @@ -48,11 +48,6 @@ namespace metis { extern "C" { */ -#ifndef NO_PARALLEL_THREADS -#ifndef WIN32 -#include -#endif -#endif #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -64,7 +59,6 @@ namespace metis { extern "C" { # define WIN32_LEAN_AND_MEAN # ifndef NO_PARALLEL_THREADS # ifdef MSVC_EXPRESS -# include # else # include # include @@ -76,9 +70,6 @@ namespace metis { extern "C" { #else // Not using MC VC++ -# ifndef NO_PARALLEL_THREADS -# include -# endif #endif diff --git a/libsrc/interface/nginterface.cpp b/libsrc/interface/nginterface.cpp index af39eab8..e520bf9b 100644 --- a/libsrc/interface/nginterface.cpp +++ b/libsrc/interface/nginterface.cpp @@ -13,66 +13,13 @@ // #include -#ifdef _MSC_VER -// Philippose - 30/01/2009 -// MSVC Express Edition Support -#ifdef MSVC_EXPRESS - -// #include -namespace netgen -{ - DLL_HEADER MeshingParameters mparam; -} - -static pthread_t meshingthread; -void RunParallel ( void * (*fun)(void *), void * in) -{ - if (netgen::mparam.parthread) // && (ntasks == 1) ) - { - pthread_attr_t attr; - pthread_attr_init (&attr); - // the following call can be removed if not available: - pthread_attr_setstacksize(&attr, 1000000); - //pthread_create (&meshingthread, &attr, fun, NULL); - pthread_create (&meshingthread, &attr, fun, in); - } - else - fun (in); -} - -#else // Using MS VC++ Standard / Enterprise / Professional edition - -// Afx - Threads need different return - value: - -static void* (*sfun)(void *); -unsigned int fun2 (void * val) -{ - sfun (val); - return 0; -} - -void RunParallel ( void* (*fun)(void *), void * in) -{ - sfun = fun; - if (netgen::mparam.parthread) - AfxBeginThread (fun2, in); - //AfxBeginThread (fun2, NULL); - else - fun (in); -} - -#endif // #ifdef MSVC_EXPRESS - -#else // For #ifdef _MSC_VER - -// #include namespace netgen { - MeshingParameters mparam; + DLL_HEADER MeshingParameters mparam; } -static pthread_t meshingthread; +static std::thread meshingthread; void RunParallel ( void * (*fun)(void *), void * in) { bool parthread = netgen::mparam.parthread; @@ -87,19 +34,12 @@ void RunParallel ( void * (*fun)(void *), void * in) if (parthread) { - pthread_attr_t attr; - pthread_attr_init (&attr); - // the following call can be removed if not available: - pthread_attr_setstacksize(&attr, 1000000); - //pthread_create (&meshingthread, &attr, fun, NULL); - pthread_create (&meshingthread, &attr, fun, in); + meshingthread = std::thread(fun, in); } else fun (in); } -#endif // #ifdef _MSC_VER - diff --git a/ng/ngpkg.cpp b/ng/ngpkg.cpp index a62775d9..169717e8 100644 --- a/ng/ngpkg.cpp +++ b/ng/ngpkg.cpp @@ -1777,7 +1777,6 @@ namespace netgen biopt.refinementfilename = argv[1]; - // pthread_create (&meshingthread, NULL, &BisectDummy, NULL); BisectDummy (0); /* diff --git a/nglib/CMakeLists.txt b/nglib/CMakeLists.txt index 79967a46..85636332 100644 --- a/nglib/CMakeLists.txt +++ b/nglib/CMakeLists.txt @@ -24,7 +24,7 @@ if(NOT WIN32) target_link_libraries( nglib mesh stlvis stl geom2dvis interface geom2d csg stl visual csgvis ) endif(NOT WIN32) -target_link_libraries( nglib ${LIBPTHREAD} ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) +target_link_libraries( nglib ${OCC_LIBRARIES} ${MPI_CXX_LIBRARIES} ${OPENGL_LIBRARIES} ${TK_LIBRARY} ${TCL_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${X11_Xmu_LIB} ${JPEG_LIBRARIES} ${MKL_LIBRARIES} ${ZLIB_LIBRARIES} ) if(USE_OCC) target_link_libraries(nglib occ)