diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-04-30 08:17:37 +0000 |
commit | 95f9076a2139f5fb042b944a0658b6cda2fa35db (patch) | |
tree | b0826a2a1dcf812e6b4450fe6b05d47cd53ae49d /src/testbed/gnunet-service-test-barriers.c | |
parent | 7746f68db77b9ca3c4aaca24ab2ce5253461240b (diff) | |
download | gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.tar.gz gnunet-95f9076a2139f5fb042b944a0658b6cda2fa35db.zip |
implementing new scheduler shutdown semantics
Diffstat (limited to 'src/testbed/gnunet-service-test-barriers.c')
-rw-r--r-- | src/testbed/gnunet-service-test-barriers.c | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/testbed/gnunet-service-test-barriers.c b/src/testbed/gnunet-service-test-barriers.c index 281172cbf..ce5249696 100644 --- a/src/testbed/gnunet-service-test-barriers.c +++ b/src/testbed/gnunet-service-test-barriers.c | |||
@@ -39,7 +39,9 @@ | |||
39 | /** | 39 | /** |
40 | * Our barrier wait handle | 40 | * Our barrier wait handle |
41 | */ | 41 | */ |
42 | struct GNUNET_TESTBED_BarrierWaitHandle *wh; | 42 | static struct GNUNET_TESTBED_BarrierWaitHandle *wh; |
43 | |||
44 | static struct GNUNET_SCHEDULER_Task *tt; | ||
43 | 45 | ||
44 | 46 | ||
45 | /** | 47 | /** |
@@ -51,8 +53,15 @@ static void | |||
51 | do_shutdown (void *cls) | 53 | do_shutdown (void *cls) |
52 | { | 54 | { |
53 | if (NULL != wh) | 55 | if (NULL != wh) |
56 | { | ||
54 | GNUNET_TESTBED_barrier_wait_cancel (wh); | 57 | GNUNET_TESTBED_barrier_wait_cancel (wh); |
55 | wh = NULL; | 58 | wh = NULL; |
59 | } | ||
60 | if (NULL != tt) | ||
61 | { | ||
62 | GNUNET_SCHEDULER_cancel (tt); | ||
63 | tt = NULL; | ||
64 | } | ||
56 | } | 65 | } |
57 | 66 | ||
58 | 67 | ||
@@ -63,8 +72,8 @@ do_shutdown (void *cls) | |||
63 | * | 72 | * |
64 | * @param cls NULL | 73 | * @param cls NULL |
65 | * @param name the barrier name | 74 | * @param name the barrier name |
66 | * @param status GNUNET_SYSERR in case of error while waiting for the barrier; | 75 | * @param status #GNUNET_SYSERR in case of error while waiting for the barrier; |
67 | * GNUNET_OK if the barrier is crossed | 76 | * #GNUNET_OK if the barrier is crossed |
68 | */ | 77 | */ |
69 | static void | 78 | static void |
70 | barrier_wait_cb (void *cls, const char *name, int status) | 79 | barrier_wait_cb (void *cls, const char *name, int status) |
@@ -84,12 +93,10 @@ barrier_wait_cb (void *cls, const char *name, int status) | |||
84 | static void | 93 | static void |
85 | do_wait (void *cls) | 94 | do_wait (void *cls) |
86 | { | 95 | { |
87 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 96 | tt = NULL; |
88 | 97 | wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, | |
89 | tc = GNUNET_SCHEDULER_get_task_context (); | 98 | &barrier_wait_cb, |
90 | if (0 != (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)) | 99 | NULL); |
91 | return; | ||
92 | wh = GNUNET_TESTBED_barrier_wait (TEST_BARRIER_NAME, &barrier_wait_cb, NULL); | ||
93 | GNUNET_break (NULL != wh); | 100 | GNUNET_break (NULL != wh); |
94 | } | 101 | } |
95 | 102 | ||
@@ -103,17 +110,18 @@ do_wait (void *cls) | |||
103 | * @param config the configuration file handle | 110 | * @param config the configuration file handle |
104 | */ | 111 | */ |
105 | static void | 112 | static void |
106 | run (void *cls, char *const *args, const char *cfgfile, | 113 | run (void *cls, |
114 | char *const *args, | ||
115 | const char *cfgfile, | ||
107 | const struct GNUNET_CONFIGURATION_Handle *config) | 116 | const struct GNUNET_CONFIGURATION_Handle *config) |
108 | { | 117 | { |
109 | unsigned int rsec; | 118 | unsigned int rsec; |
110 | 119 | ||
111 | rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10); | 120 | rsec = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 10); |
112 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply | 121 | tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
113 | (GNUNET_TIME_UNIT_SECONDS, rsec), | 122 | (GNUNET_TIME_UNIT_SECONDS, rsec), |
114 | &do_wait, NULL); | 123 | &do_wait, NULL); |
115 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | 124 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
116 | &do_shutdown, NULL); | ||
117 | } | 125 | } |
118 | 126 | ||
119 | 127 | ||
@@ -121,7 +129,8 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
121 | /** | 129 | /** |
122 | * Main | 130 | * Main |
123 | */ | 131 | */ |
124 | int main (int argc, char **argv) | 132 | int |
133 | main (int argc, char **argv) | ||
125 | { | 134 | { |
126 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 135 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
127 | GNUNET_GETOPT_OPTION_END | 136 | GNUNET_GETOPT_OPTION_END |