summaryrefslogtreecommitdiff
path: root/source3/libsmb
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2012-09-21 12:05:04 -0700
committerVolker Lendecke <vl@samba.org>2012-09-23 07:20:20 -0700
commit947520521ed3da2f0787e17a9fe906024fdee7e3 (patch)
tree9859db5b283f8919e60c96a32aa3e57036885da1 /source3/libsmb
parent8e5f30c830c23d8223c38e34669f069e44fee64b (diff)
downloadsamba-947520521ed3da2f0787e17a9fe906024fdee7e3.tar.gz
samba-947520521ed3da2f0787e17a9fe906024fdee7e3.tar.bz2
samba-947520521ed3da2f0787e17a9fe906024fdee7e3.zip
s3-pylibsmb: Factor out py_tevent_cond_wait
Diffstat (limited to 'source3/libsmb')
-rw-r--r--source3/libsmb/pylibsmb.c33
1 files changed, 19 insertions, 14 deletions
diff --git a/source3/libsmb/pylibsmb.c b/source3/libsmb/pylibsmb.c
index d31409cba8..1fab7cf103 100644
--- a/source3/libsmb/pylibsmb.c
+++ b/source3/libsmb/pylibsmb.c
@@ -228,33 +228,30 @@ struct py_tevent_cond {
static void py_tevent_signalme(struct tevent_req *req);
-static int py_tevent_req_wait(struct tevent_context *ev,
- struct tevent_req *req)
+static int py_tevent_cond_wait(struct py_tevent_cond *cond)
{
- struct py_tevent_cond cond;
int ret, result;
- result = pthread_mutex_init(&cond.mutex, NULL);
+ result = pthread_mutex_init(&cond->mutex, NULL);
if (result != 0) {
goto fail;
}
- result = pthread_cond_init(&cond.cond, NULL);
+ result = pthread_cond_init(&cond->cond, NULL);
if (result != 0) {
goto fail_mutex;
}
- cond.is_done = false;
- tevent_req_set_callback(req, py_tevent_signalme, &cond);
-
- result = pthread_mutex_lock(&cond.mutex);
+ result = pthread_mutex_lock(&cond->mutex);
if (result != 0) {
goto fail_cond;
}
- while (!cond.is_done) {
+ cond->is_done = false;
+
+ while (!cond->is_done) {
Py_BEGIN_ALLOW_THREADS
- result = pthread_cond_wait(&cond.cond, &cond.mutex);
+ result = pthread_cond_wait(&cond->cond, &cond->mutex);
Py_END_ALLOW_THREADS
if (result != 0) {
@@ -263,18 +260,26 @@ static int py_tevent_req_wait(struct tevent_context *ev,
}
fail_unlock:
- ret = pthread_mutex_unlock(&cond.mutex);
+ ret = pthread_mutex_unlock(&cond->mutex);
assert(ret == 0);
fail_cond:
- ret = pthread_cond_destroy(&cond.cond);
+ ret = pthread_cond_destroy(&cond->cond);
assert(ret == 0);
fail_mutex:
- ret = pthread_mutex_destroy(&cond.mutex);
+ ret = pthread_mutex_destroy(&cond->mutex);
assert(ret == 0);
fail:
return result;
}
+static int py_tevent_req_wait(struct tevent_context *ev,
+ struct tevent_req *req)
+{
+ struct py_tevent_cond cond;
+ tevent_req_set_callback(req, py_tevent_signalme, &cond);
+ return py_tevent_cond_wait(&cond);
+}
+
static void py_tevent_signalme(struct tevent_req *req)
{
struct py_tevent_cond *cond = (struct py_tevent_cond *)