Module: sems
Branch: master
Commit: 7251ef541603bcfda31ab6402cf98b2e4893bca6
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=7251ef541603bcfda31ab6402cf98b2e4893bca6

Author: Stefan Sayer <[email protected]>
Committer: Stefan Sayer <[email protected]>
Date:   Fri Jul 15 13:14:10 2011 +0200

b/f:ivr: release GIL on blocking file I/O

patch by Robert Szokovacs

---

 apps/ivr/IvrAudio.cpp |   27 ++++++++++++++++++++++-----
 1 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/apps/ivr/IvrAudio.cpp b/apps/ivr/IvrAudio.cpp
index 90b6c40..8522f25 100644
--- a/apps/ivr/IvrAudio.cpp
+++ b/apps/ivr/IvrAudio.cpp
@@ -92,7 +92,11 @@ static PyObject* IvrAudioFile_open(IvrAudioFile* self, 
PyObject* args)
     return NULL;
   }
 
-  if(self->af->open(filename,open_mode,is_tmp)){
+  int i;
+  Py_BEGIN_ALLOW_THREADS;
+  i = self->af->open(filename,open_mode,is_tmp);
+  Py_END_ALLOW_THREADS;
+  if(i){
     PyErr_SetString(PyExc_IOError,"Could not open file");
     return NULL;
   }
@@ -130,7 +134,11 @@ static PyObject* IvrAudioFile_fpopen(IvrAudioFile* self, 
PyObject* args)
     return NULL;
   }
 
-  if(self->af->fpopen(filename,open_mode,fp)){
+  int i;
+  Py_BEGIN_ALLOW_THREADS;
+  i = self->af->fpopen(filename,open_mode,fp);
+  Py_END_ALLOW_THREADS;
+  if(i){
     PyErr_SetString(PyExc_IOError,"Could not open file");
     return NULL;
   }
@@ -150,10 +158,12 @@ static PyObject* IvrAudioFile_rewind(IvrAudioFile* self, 
PyObject* args)
   if(!PyArg_ParseTuple(args,"|i",&rew_time))
     return NULL;
 
+  Py_BEGIN_ALLOW_THREADS;
   if (rew_time != 0)
     self->af->rewind(rew_time);
   else
     self->af->rewind();
+  Py_END_ALLOW_THREADS;
 
   Py_INCREF(Py_None);
   return Py_None;
@@ -181,8 +191,12 @@ static PyObject* IvrAudioFile_tts(PyObject* cls, PyObject* 
args)
   *self->filename = string(TTS_CACHE_PATH) + AmSession::getNewId() + 
string(".wav");
   self->del_file = true;
   flite_text_to_speech(text,self->tts_voice,self->filename->c_str());
-    
-  if(self->af->open(self->filename->c_str(),AmAudioFile::Read)){
+
+  int i;
+  Py_BEGIN_ALLOW_THREADS;
+  i=self->af->open(self->filename->c_str(),AmAudioFile::Read);
+  Py_END_ALLOW_THREADS;
+  if(i){
     Py_DECREF(tts_file);
     PyErr_SetString(PyExc_IOError,"could not open TTS file");
     return NULL;
@@ -194,7 +208,9 @@ static PyObject* IvrAudioFile_tts(PyObject* cls, PyObject* 
args)
     
 static PyObject* IvrAudioFile_close(IvrAudioFile* self, PyObject*)
 {
+  Py_BEGIN_ALLOW_THREADS;
   self->af->close();
+  Py_END_ALLOW_THREADS;
   Py_INCREF(Py_None);
   return Py_None;
 }
@@ -218,11 +234,12 @@ static PyObject* IvrAudioFile_setRecordTime(IvrAudioFile* 
self, PyObject* args)
 
 static PyObject* IvrAudioFile_exportRaw(IvrAudioFile* self, PyObject*)
 {
+  Py_BEGIN_ALLOW_THREADS;
   if(self->af->getMode() == AmAudioFile::Write)
     self->af->on_close();
     
   self->af->rewind();
-
+  Py_END_ALLOW_THREADS;
   return PyFile_FromFile(self->af->getfp(),(char*)"",(char*)"rwb",NULL);
 }
 

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to