summaryrefslogtreecommitdiffstats
path: root/ctdb/libctdb
diff options
context:
space:
mode:
authorRonnie Sahlberg <ronniesahlberg@gmail.com>2010-06-04 14:20:17 +1000
committerRonnie Sahlberg <ronniesahlberg@gmail.com>2010-06-04 14:20:17 +1000
commit29c43d556c50f84a5a944bfd030f49e8a3775119 (patch)
tree9d19917ab2e01a102c4d8a9dd3b9e3ad906f79d0 /ctdb/libctdb
parent94df6f322d511fc338a1684e4a3d7e80ddeb8476 (diff)
downloadsamba-29c43d556c50f84a5a944bfd030f49e8a3775119.tar.gz
samba-29c43d556c50f84a5a944bfd030f49e8a3775119.tar.xz
samba-29c43d556c50f84a5a944bfd030f49e8a3775119.zip
remove the global rrl_cb_called from the libctdb example
and psss it through the callback via private_data. add a comment that the callback may sometimes have already been invoked when the ctdb_readrecordlock_async() call returns and that the application can use *private_data IF the application needs to know if the callback has already triggered or not. (This used to be ctdb commit 0ba458a91ba510215a9c8770286a68e19911515f)
Diffstat (limited to 'ctdb/libctdb')
-rw-r--r--ctdb/libctdb/tst.c19
1 files changed, 15 insertions, 4 deletions
diff --git a/ctdb/libctdb/tst.c b/ctdb/libctdb/tst.c
index 090b26da3a..f1a8e3d41b 100644
--- a/ctdb/libctdb/tst.c
+++ b/ctdb/libctdb/tst.c
@@ -81,15 +81,15 @@ static void rm_cb(struct ctdb_connection *ctdb,
*
* Pure read, or pure write are just special cases of this cycle.
*/
-static bool rrl_cb_called;
-
static void rrl_cb(struct ctdb_db *ctdb_db,
struct ctdb_lock *lock, TDB_DATA outdata, void *private)
{
TDB_DATA data;
char tmp[256];
+ bool *rrl_cb_called = private;
+
+ *rrl_cb_called = true;
- rrl_cb_called = true;
if (!lock) {
printf("rrl_cb returned error\n");
return;
@@ -134,6 +134,8 @@ int main(int argc, char *argv[])
uint32_t recmaster;
int ret;
TDB_DATA msg;
+ bool rrl_cb_called = false;
+
ctdb_connection = ctdb_connect("/tmp/ctdb.socket");
if (!ctdb_connection)
@@ -194,8 +196,17 @@ int main(int argc, char *argv[])
exit(10);
}
+ /* In the non-contended case the callback might be invoked
+ * immediately, before ctdb_readrecordlock_async() returns.
+ * In the contended case the callback will be invoked later.
+ *
+ * Normally an application would not care whether the callback
+ * has already been invoked here or not, but if the application
+ * needs to know, it can use the *private_data pointer
+ * to pass data through to the callback and back.
+ */
if (!ctdb_readrecordlock_async(ctdb_db_context, key,
- rrl_cb, ctdb_db_context)) {
+ rrl_cb, &rrl_cb_called)) {
printf("Failed to send READRECORDLOCK\n");
exit(10);
}