Merge revision 71222 from trunk: #5615: make it possible to configure --without-threads again.

This commit is contained in:
Georg Brandl 2009-04-05 11:47:34 +00:00
parent 0c0daf059b
commit dfd734429e
4 changed files with 49 additions and 6 deletions

View file

@ -204,7 +204,9 @@ typedef struct {
isn't ready for writing. */
Py_off_t write_end;
#ifdef WITH_THREAD
PyThread_type_lock lock;
#endif
Py_ssize_t buffer_size;
Py_ssize_t buffer_mask;
@ -239,6 +241,7 @@ typedef struct {
/* These macros protect the BufferedObject against concurrent operations. */
#ifdef WITH_THREAD
#define ENTER_BUFFERED(self) \
Py_BEGIN_ALLOW_THREADS \
PyThread_acquire_lock(self->lock, 1); \
@ -246,6 +249,10 @@ typedef struct {
#define LEAVE_BUFFERED(self) \
PyThread_release_lock(self->lock);
#else
#define ENTER_BUFFERED(self)
#define LEAVE_BUFFERED(self)
#endif
#define CHECK_INITIALIZED(self) \
if (self->ok <= 0) { \
@ -305,10 +312,12 @@ BufferedObject_dealloc(BufferedObject *self)
PyMem_Free(self->buffer);
self->buffer = NULL;
}
#ifdef WITH_THREAD
if (self->lock) {
PyThread_free_lock(self->lock);
self->lock = NULL;
}
#endif
Py_CLEAR(self->dict);
Py_TYPE(self)->tp_free((PyObject *)self);
}
@ -565,11 +574,13 @@ _Buffered_init(BufferedObject *self)
PyErr_NoMemory();
return -1;
}
#ifdef WITH_THREAD
self->lock = PyThread_allocate_lock();
if (self->lock == NULL) {
PyErr_SetString(PyExc_RuntimeError, "can't allocate read lock");
return -1;
}
#endif
/* Find out whether buffer_size is a power of 2 */
/* XXX is this optimization useful? */
for (n = self->buffer_size - 1; n & 1; n >>= 1)