From 2f17f4d2fb9e14d0308b805454e3e27d1dd188f7 Mon Sep 17 00:00:00 2001 From: Karl Lehenbauer Date: Fri, 13 Jan 2017 05:44:49 +0000 Subject: [PATCH] factor a function, zootcl_queue_null_event, and use it --- generic/zookeepertcl.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/generic/zookeepertcl.c b/generic/zookeepertcl.c index 4f8dbb2..eb54e7c 100644 --- a/generic/zookeepertcl.c +++ b/generic/zookeepertcl.c @@ -452,6 +452,29 @@ zootcl_stat_completion_callback (int rc, const struct Stat *stat, const void *co Tcl_ThreadAlert (evPtr->zo->threadId); } +/* + *-------------------------------------------------------------- + * + * zootcl_queue_null_event -- queue a "no op" event to wake + * up the event loop, but the event doesn't actually do anything. + * + * this helps our pseudo-synchronous functions to work. + * + *-------------------------------------------------------------- + */ +void +zootcl_queue_null_event (zootcl_syncCallbackContext *zsc) +{ + zootcl_callbackEvent *evPtr; + + evPtr = ckalloc (sizeof (zootcl_callbackEvent)); + evPtr->event.proc = zootcl_EventProc; + evPtr->callbackType = NULL_CALLBACK; + Tcl_ThreadQueueEvent (zsc->zo->threadId, (Tcl_Event *)evPtr, TCL_QUEUE_TAIL); + Tcl_ThreadAlert (zsc->zo->threadId); +} + + /* *-------------------------------------------------------------- * @@ -463,7 +486,6 @@ void zootcl_sync_stat_completion_callback (int rc, const struct Stat *stat, const void *context) { zootcl_syncCallbackContext *zsc = (zootcl_syncCallbackContext *)context; - zootcl_callbackEvent *evPtr; zsc->rc = rc; if (stat == NULL) { zsc->haveStat = 0; @@ -473,11 +495,7 @@ zootcl_sync_stat_completion_callback (int rc, const struct Stat *stat, const voi } zsc->syncDone = 1; printf("zootcl_sync_stat_completion_callback: done\n"); - evPtr = ckalloc (sizeof (zootcl_callbackEvent)); - evPtr->event.proc = zootcl_EventProc; - evPtr->callbackType = NULL_CALLBACK; - Tcl_ThreadQueueEvent (zsc->zo->threadId, (Tcl_Event *)evPtr, TCL_QUEUE_TAIL); - Tcl_ThreadAlert (zsc->zo->threadId); + zootcl_queue_null_event (zsc); } /* @@ -490,13 +508,8 @@ printf("zootcl_sync_stat_completion_callback: done\n"); void zootcl_sync_data_completion_callback (int rc, const char *value, int valueLen, const struct Stat *stat, const void *context) { - zootcl_callbackEvent *evPtr; zootcl_syncCallbackContext *zsc = (zootcl_syncCallbackContext *)context; - evPtr = ckalloc (sizeof (zootcl_callbackEvent)); - evPtr->event.proc = zootcl_EventProc; - evPtr->callbackType = NULL_CALLBACK; - zsc->rc = rc; zsc->syncDone = 1; @@ -516,8 +529,7 @@ zootcl_sync_data_completion_callback (int rc, const char *value, int valueLen, c zsc->stat = *stat; } - Tcl_ThreadQueueEvent (zsc->zo->threadId, (Tcl_Event *)evPtr, TCL_QUEUE_TAIL); - Tcl_ThreadAlert (zsc->zo->threadId); + zootcl_queue_null_event (zsc); } /*