[Python-checkins] python/dist/src/Modules ossaudiodev.c,1.26,1.27

gward@users.sourceforge.net gward@users.sourceforge.net
Thu, 22 May 2003 18:50:40 -0700


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1:/tmp/cvs-serv31065

Modified Files:
	ossaudiodev.c 
Log Message:
Release the GIL around read(), write(), and select() calls.
Bug spotted by Joerg Lehmann <joerg@luga.de>.


Index: ossaudiodev.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/ossaudiodev.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -C2 -d -r1.26 -r1.27
*** ossaudiodev.c	4 Apr 2003 01:47:42 -0000	1.26
--- ossaudiodev.c	23 May 2003 01:50:37 -0000	1.27
***************
*** 386,390 ****
          return NULL;
      cp = PyString_AS_STRING(rv);
!     if ((count = read(self->fd, cp, size)) < 0) {
          PyErr_SetFromErrno(PyExc_IOError);
          Py_DECREF(rv);
--- 386,395 ----
          return NULL;
      cp = PyString_AS_STRING(rv);
! 
!     Py_BEGIN_ALLOW_THREADS
!     count = read(self->fd, cp, size);
!     Py_END_ALLOW_THREADS
! 
!     if (count < 0) {
          PyErr_SetFromErrno(PyExc_IOError);
          Py_DECREF(rv);
***************
*** 405,409 ****
          return NULL;
      }
!     if ((rv = write(self->fd, cp, size)) == -1) {
          return PyErr_SetFromErrno(PyExc_IOError);
      } else {
--- 410,419 ----
          return NULL;
      }
! 
!     Py_BEGIN_ALLOW_THREADS
!     rv = write(self->fd, cp, size);
!     Py_END_ALLOW_THREADS
! 
!     if (rv == -1) {
          return PyErr_SetFromErrno(PyExc_IOError);
      } else {
***************
*** 436,445 ****
--- 446,459 ----
  
      while (size > 0) {
+         Py_BEGIN_ALLOW_THREADS
          select_rv = select(self->fd+1, NULL, &write_set_fds, NULL, NULL);
+         Py_END_ALLOW_THREADS
          assert(select_rv != 0);         /* no timeout, can't expire */
          if (select_rv == -1)
              return PyErr_SetFromErrno(PyExc_IOError);
  
+         Py_BEGIN_ALLOW_THREADS
          rv = write(self->fd, cp, size);
+         Py_END_ALLOW_THREADS
          if (rv == -1) {
              if (errno == EAGAIN) {      /* buffer is full, try again */