Merge revision 71222 from trunk: #5615: make it possible to configure --without-threads again.
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 9960dba..fb41c1d 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -204,7 +204,9 @@
        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 @@
 
 /* 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 @@
 
 #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 @@
         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 @@
         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)