Properly manage GIL in RunSetCommand
This commit is contained in:
parent
86f6256d3a
commit
74d5f9ac0b
@ -675,13 +675,15 @@ static bool _PylibMC_RunSetCommand(PylibMC_Client* self,
|
|||||||
_PylibMC_SetCommand f, char *fname,
|
_PylibMC_SetCommand f, char *fname,
|
||||||
pylibmc_mset* msets, size_t nkeys,
|
pylibmc_mset* msets, size_t nkeys,
|
||||||
size_t min_compress) {
|
size_t min_compress) {
|
||||||
|
PyGILState_STATE gstate;
|
||||||
memcached_st* mc = self->mc;
|
memcached_st* mc = self->mc;
|
||||||
memcached_return rc = MEMCACHED_SUCCESS;
|
memcached_return rc = MEMCACHED_SUCCESS;
|
||||||
int pos;
|
int pos;
|
||||||
bool error = false;
|
bool error = false;
|
||||||
bool allsuccess = true;
|
bool allsuccess = true;
|
||||||
|
|
||||||
Py_BEGIN_ALLOW_THREADS;
|
gstate = PyGILState_Ensure();
|
||||||
|
PyGILState_Release(gstate);
|
||||||
|
|
||||||
for (pos=0; pos < nkeys && !error; pos++) {
|
for (pos=0; pos < nkeys && !error; pos++) {
|
||||||
pylibmc_mset* mset = &msets[pos];
|
pylibmc_mset* mset = &msets[pos];
|
||||||
@ -694,12 +696,14 @@ static bool _PylibMC_RunSetCommand(PylibMC_Client* self,
|
|||||||
char* compressed_value = NULL;
|
char* compressed_value = NULL;
|
||||||
size_t compressed_len = 0;
|
size_t compressed_len = 0;
|
||||||
|
|
||||||
if(min_compress && value_len >= min_compress) {
|
if (min_compress && value_len >= min_compress) {
|
||||||
|
gstate = PyGILState_Ensure();
|
||||||
_PylibMC_Deflate(value, value_len,
|
_PylibMC_Deflate(value, value_len,
|
||||||
&compressed_value, &compressed_len);
|
&compressed_value, &compressed_len);
|
||||||
|
PyGILState_Release(gstate);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(compressed_value != NULL) {
|
if (compressed_value != NULL) {
|
||||||
/* Will want to change this if this function
|
/* Will want to change this if this function
|
||||||
* needs to get back at the old *value at some point */
|
* needs to get back at the old *value at some point */
|
||||||
value = compressed_value;
|
value = compressed_value;
|
||||||
@ -709,7 +713,7 @@ static bool _PylibMC_RunSetCommand(PylibMC_Client* self,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Finally go and call the actual libmemcached function */
|
/* Finally go and call the actual libmemcached function */
|
||||||
if(mset->key_len == 0) {
|
if (mset->key_len == 0) {
|
||||||
/* Most other implementations ignore zero-length keys, so
|
/* Most other implementations ignore zero-length keys, so
|
||||||
we'll just do that */
|
we'll just do that */
|
||||||
rc = MEMCACHED_NOTSTORED;
|
rc = MEMCACHED_NOTSTORED;
|
||||||
@ -719,12 +723,12 @@ static bool _PylibMC_RunSetCommand(PylibMC_Client* self,
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_ZLIB
|
#ifdef USE_ZLIB
|
||||||
if(compressed_value != NULL) {
|
if (compressed_value != NULL) {
|
||||||
free(compressed_value);
|
free(compressed_value);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
switch(rc) {
|
switch (rc) {
|
||||||
case MEMCACHED_SUCCESS:
|
case MEMCACHED_SUCCESS:
|
||||||
mset->success = true;
|
mset->success = true;
|
||||||
break;
|
break;
|
||||||
@ -745,7 +749,7 @@ static bool _PylibMC_RunSetCommand(PylibMC_Client* self,
|
|||||||
|
|
||||||
} /* end for each mset */
|
} /* end for each mset */
|
||||||
|
|
||||||
Py_END_ALLOW_THREADS;
|
gstate = PyGILState_Ensure();
|
||||||
|
|
||||||
/* We only return the last return value, even for a _multi
|
/* We only return the last return value, even for a _multi
|
||||||
operation, but we do set the success on the mset */
|
operation, but we do set the success on the mset */
|
||||||
|
Reference in New Issue
Block a user