swig -python -threads now generates C/C++ code which uses Python's
own threading abstraction (from pythread.h) rather than OS specific code. The old code failed to compile on MS Windows. (See SF patch tracker #1710341). git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9806 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
1c3fec7f2a
commit
4aaf48d650
2 changed files with 18 additions and 23 deletions
|
|
@ -340,33 +340,21 @@ namespace Swig {
|
|||
# endif
|
||||
#endif
|
||||
|
||||
/* simple thread abstraction for pthreads on win32 */
|
||||
#ifdef __THREAD__
|
||||
# define __PTHREAD__
|
||||
# if defined(_WIN32) || defined(__WIN32__)
|
||||
# define pthread_mutex_lock EnterCriticalSection
|
||||
# define pthread_mutex_unlock LeaveCriticalSection
|
||||
# define pthread_mutex_t CRITICAL_SECTION
|
||||
# define SWIG_MUTEX_INIT(var) var
|
||||
# else
|
||||
# include <pthread.h>
|
||||
# define SWIG_MUTEX_INIT(var) var = PTHREAD_MUTEX_INITIALIZER
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __PTHREAD__
|
||||
struct Guard
|
||||
# include "pythread.h"
|
||||
class Guard
|
||||
{
|
||||
pthread_mutex_t *_mutex;
|
||||
PyThread_type_lock & mutex_;
|
||||
|
||||
Guard(pthread_mutex_t &mutex) : _mutex(&mutex)
|
||||
public:
|
||||
Guard(PyThread_type_lock & mutex) : mutex_(mutex)
|
||||
{
|
||||
pthread_mutex_lock(_mutex);
|
||||
PyThread_acquire_lock(mutex_, WAIT_LOCK);
|
||||
}
|
||||
|
||||
~Guard()
|
||||
{
|
||||
pthread_mutex_unlock(_mutex);
|
||||
PyThread_free_lock(mutex_);
|
||||
}
|
||||
};
|
||||
# define SWIG_GUARD(mutex) Guard _guard(mutex)
|
||||
|
|
@ -437,8 +425,8 @@ namespace Swig {
|
|||
private:
|
||||
typedef std::map<void*, GCItem_var> ownership_map;
|
||||
mutable ownership_map owner;
|
||||
#ifdef __PTHREAD__
|
||||
static pthread_mutex_t swig_mutex_own;
|
||||
#ifdef __THREAD__
|
||||
static PyThread_type_lock swig_mutex_own;
|
||||
#endif
|
||||
|
||||
public:
|
||||
|
|
@ -483,8 +471,8 @@ namespace Swig {
|
|||
}
|
||||
};
|
||||
|
||||
#ifdef __PTHREAD__
|
||||
pthread_mutex_t SWIG_MUTEX_INIT(Director::swig_mutex_own);
|
||||
#ifdef __THREAD__
|
||||
PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue