mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 14:10:34 +05:00
get rid of pthread
This commit is contained in:
parent
938cbbcc1d
commit
8a3e29e624
@ -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})
|
||||
|
@ -26,36 +26,20 @@ public:
|
||||
void UnLock () { ; }
|
||||
};
|
||||
|
||||
|
||||
#else
|
||||
|
||||
#ifdef _MSC_VER
|
||||
|
||||
#ifdef MSVC_EXPRESS
|
||||
// #include <pthread.h>
|
||||
|
||||
|
||||
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 <pthread.h>
|
||||
|
||||
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
|
||||
|
||||
|
@ -48,11 +48,6 @@ namespace metis { extern "C" {
|
||||
*/
|
||||
|
||||
|
||||
#ifndef NO_PARALLEL_THREADS
|
||||
#ifndef WIN32
|
||||
#include <pthread.h>
|
||||
#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 <pthread.h>
|
||||
# else
|
||||
# include <afxwin.h>
|
||||
# include <afxmt.h>
|
||||
@ -76,9 +70,6 @@ namespace metis { extern "C" {
|
||||
|
||||
#else // Not using MC VC++
|
||||
|
||||
# ifndef NO_PARALLEL_THREADS
|
||||
# include <pthread.h>
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -13,66 +13,13 @@
|
||||
// #include <visual.hpp>
|
||||
|
||||
|
||||
#ifdef _MSC_VER
|
||||
// Philippose - 30/01/2009
|
||||
// MSVC Express Edition Support
|
||||
#ifdef MSVC_EXPRESS
|
||||
|
||||
// #include <pthread.h>
|
||||
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 <pthread.h>
|
||||
|
||||
namespace netgen
|
||||
{
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1777,7 +1777,6 @@ namespace netgen
|
||||
biopt.refinementfilename = argv[1];
|
||||
|
||||
|
||||
// pthread_create (&meshingthread, NULL, &BisectDummy, NULL);
|
||||
BisectDummy (0);
|
||||
|
||||
/*
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user