Ticket #137: pythreads.patch

File pythreads.patch, 1.6 KB (added by Olly Betts, 17 years ago)

Patch xapian_wrap.cc to use pythreads

  • .cc

    old new  
    28082808# endif
    28092809#endif
    28102810
    2811 /* simple thread abstraction for pthreads on win32 */
    28122811#ifdef __THREAD__
    2813 # define __PTHREAD__
    2814 # if defined(_WIN32) || defined(__WIN32__)
    2815 #  define pthread_mutex_lock EnterCriticalSection
    2816 #  define pthread_mutex_unlock LeaveCriticalSection
    2817 #  define pthread_mutex_t CRITICAL_SECTION
    2818 #  define SWIG_MUTEX_INIT(var) var
    2819 # else
    2820 #  include <pthread.h>
    2821 #  define SWIG_MUTEX_INIT(var) var = PTHREAD_MUTEX_INITIALIZER
    2822 # endif
    2823 #endif
    2824 
    2825 #ifdef  __PTHREAD__
    2826   struct Guard
     2812# include "pythread.h"
     2813  class Guard
    28272814  {
    2828     pthread_mutex_t *_mutex;
     2815    PyThread_type_lock & mutex_;
    28292816   
    2830     Guard(pthread_mutex_t &mutex) : _mutex(&mutex)
     2817  public:
     2818    Guard(PyThread_type_lock & mutex) : mutex_(mutex)
    28312819    {
    2832       pthread_mutex_lock(_mutex);
     2820      PyThread_acquire_lock(mutex_, WAIT_LOCK);
    28332821    }
    28342822   
    28352823    ~Guard()
    28362824    {
    2837       pthread_mutex_unlock(_mutex);
     2825      PyThread_free_lock(mutex_);
    28382826    }
    28392827  };
    28402828# define SWIG_GUARD(mutex) Guard _guard(mutex)
     
    29052893  private:
    29062894    typedef std::map<void*, GCItem_var> ownership_map;
    29072895    mutable ownership_map owner;
    2908 #ifdef __PTHREAD__
    2909     static pthread_mutex_t swig_mutex_own;
     2896#ifdef __THREAD__
     2897    static PyThread_type_lock swig_mutex_own;
    29102898#endif
    29112899
    29122900  public:
     
    29512939    }
    29522940  };
    29532941
    2954 #ifdef __PTHREAD__
    2955   pthread_mutex_t SWIG_MUTEX_INIT(Director::swig_mutex_own);
     2942#ifdef __THREAD__
     2943  PyThread_type_lock Director::swig_mutex_own = PyThread_allocate_lock();
    29562944#endif
    29572945}
    29582946