diff options
Diffstat (limited to 'src/messenger/testing_messenger_barrier.c')
-rw-r--r-- | src/messenger/testing_messenger_barrier.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/src/messenger/testing_messenger_barrier.c b/src/messenger/testing_messenger_barrier.c index 60d1fc0fe..ecebe1582 100644 --- a/src/messenger/testing_messenger_barrier.c +++ b/src/messenger/testing_messenger_barrier.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2021 GNUnet e.V. | 3 | Copyright (C) 2021, 2023 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -35,7 +35,7 @@ struct GNUNET_BarrierHandle | |||
35 | struct GNUNET_BarrierWaitHandle *head; | 35 | struct GNUNET_BarrierWaitHandle *head; |
36 | struct GNUNET_BarrierWaitHandle *tail; | 36 | struct GNUNET_BarrierWaitHandle *tail; |
37 | 37 | ||
38 | struct GNUNET_SCHEDULER_Task* task; | 38 | struct GNUNET_SCHEDULER_Task *task; |
39 | }; | 39 | }; |
40 | 40 | ||
41 | struct GNUNET_BarrierHandle* | 41 | struct GNUNET_BarrierHandle* |
@@ -46,9 +46,10 @@ GNUNET_init_barrier (unsigned int requirement, | |||
46 | if (0 == requirement) | 46 | if (0 == requirement) |
47 | return NULL; | 47 | return NULL; |
48 | 48 | ||
49 | struct GNUNET_BarrierHandle *barrier = GNUNET_new(struct GNUNET_BarrierHandle); | 49 | struct GNUNET_BarrierHandle *barrier = GNUNET_new (struct |
50 | GNUNET_BarrierHandle); | ||
50 | 51 | ||
51 | if (!barrier) | 52 | if (! barrier) |
52 | return NULL; | 53 | return NULL; |
53 | 54 | ||
54 | barrier->requirement = requirement; | 55 | barrier->requirement = requirement; |
@@ -61,6 +62,7 @@ GNUNET_init_barrier (unsigned int requirement, | |||
61 | return barrier; | 62 | return barrier; |
62 | } | 63 | } |
63 | 64 | ||
65 | |||
64 | static void | 66 | static void |
65 | exit_status (struct GNUNET_BarrierHandle *barrier, | 67 | exit_status (struct GNUNET_BarrierHandle *barrier, |
66 | int status); | 68 | int status); |
@@ -71,21 +73,24 @@ cancel_barrier (void *cls) | |||
71 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_SYSERR); | 73 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_SYSERR); |
72 | } | 74 | } |
73 | 75 | ||
76 | |||
74 | static void | 77 | static void |
75 | complete_barrier (void *cls) | 78 | complete_barrier (void *cls) |
76 | { | 79 | { |
77 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_OK); | 80 | exit_status ((struct GNUNET_BarrierHandle*) cls, GNUNET_OK); |
78 | } | 81 | } |
79 | 82 | ||
83 | |||
80 | void | 84 | void |
81 | GNUNET_cancel_barrier (struct GNUNET_BarrierHandle *barrier) | 85 | GNUNET_cancel_barrier (struct GNUNET_BarrierHandle *barrier) |
82 | { | 86 | { |
83 | if ((!barrier) || (barrier->task)) | 87 | if ((! barrier) || (barrier->task)) |
84 | return; | 88 | return; |
85 | 89 | ||
86 | barrier->task = GNUNET_SCHEDULER_add_now(cancel_barrier, barrier); | 90 | barrier->task = GNUNET_SCHEDULER_add_now (cancel_barrier, barrier); |
87 | } | 91 | } |
88 | 92 | ||
93 | |||
89 | struct GNUNET_BarrierWaitHandle | 94 | struct GNUNET_BarrierWaitHandle |
90 | { | 95 | { |
91 | GNUNET_BarrierWaitStatusCallback cb; | 96 | GNUNET_BarrierWaitStatusCallback cb; |
@@ -107,31 +112,33 @@ exit_status (struct GNUNET_BarrierHandle *barrier, | |||
107 | struct GNUNET_BarrierWaitHandle *current = waiting; | 112 | struct GNUNET_BarrierWaitHandle *current = waiting; |
108 | 113 | ||
109 | if (current->cb) | 114 | if (current->cb) |
110 | current->cb(current->cls, current, status); | 115 | current->cb (current->cls, current, status); |
111 | 116 | ||
112 | waiting = waiting->next; | 117 | waiting = waiting->next; |
113 | 118 | ||
114 | GNUNET_CONTAINER_DLL_remove(barrier->head, barrier->tail, current); | 119 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, current); |
115 | GNUNET_free(current); | 120 | GNUNET_free (current); |
116 | } | 121 | } |
117 | 122 | ||
118 | if (barrier->cb) | 123 | if (barrier->cb) |
119 | barrier->cb(barrier->cls, barrier, status); | 124 | barrier->cb (barrier->cls, barrier, status); |
120 | 125 | ||
121 | GNUNET_free(barrier); | 126 | GNUNET_free (barrier); |
122 | } | 127 | } |
123 | 128 | ||
129 | |||
124 | struct GNUNET_BarrierWaitHandle* | 130 | struct GNUNET_BarrierWaitHandle* |
125 | GNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, | 131 | GNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, |
126 | GNUNET_BarrierWaitStatusCallback cb, | 132 | GNUNET_BarrierWaitStatusCallback cb, |
127 | void *cb_cls) | 133 | void *cb_cls) |
128 | { | 134 | { |
129 | if ((!barrier) || (0 == barrier->requirement)) | 135 | if ((! barrier) || (0 == barrier->requirement)) |
130 | return NULL; | 136 | return NULL; |
131 | 137 | ||
132 | struct GNUNET_BarrierWaitHandle *waiting = GNUNET_new(struct GNUNET_BarrierWaitHandle); | 138 | struct GNUNET_BarrierWaitHandle *waiting = GNUNET_new (struct |
139 | GNUNET_BarrierWaitHandle); | ||
133 | 140 | ||
134 | if (!waiting) | 141 | if (! waiting) |
135 | return NULL; | 142 | return NULL; |
136 | 143 | ||
137 | waiting->cb = cb; | 144 | waiting->cb = cb; |
@@ -140,34 +147,35 @@ GNUNET_wait_barrier (struct GNUNET_BarrierHandle *barrier, | |||
140 | waiting->next = NULL; | 147 | waiting->next = NULL; |
141 | waiting->barrier = barrier; | 148 | waiting->barrier = barrier; |
142 | 149 | ||
143 | GNUNET_CONTAINER_DLL_insert_tail(barrier->head, barrier->tail, waiting); | 150 | GNUNET_CONTAINER_DLL_insert_tail (barrier->head, barrier->tail, waiting); |
144 | barrier->requirement--; | 151 | barrier->requirement--; |
145 | 152 | ||
146 | if ((barrier->requirement == 0) && (!barrier->task)) | 153 | if ((barrier->requirement == 0) && (! barrier->task)) |
147 | barrier->task = GNUNET_SCHEDULER_add_now(complete_barrier, barrier); | 154 | barrier->task = GNUNET_SCHEDULER_add_now (complete_barrier, barrier); |
148 | 155 | ||
149 | return waiting; | 156 | return waiting; |
150 | } | 157 | } |
151 | 158 | ||
159 | |||
152 | void | 160 | void |
153 | GNUNET_cancel_wait_barrier (struct GNUNET_BarrierWaitHandle *waiting) | 161 | GNUNET_cancel_wait_barrier (struct GNUNET_BarrierWaitHandle *waiting) |
154 | { | 162 | { |
155 | if (!waiting) | 163 | if (! waiting) |
156 | return; | 164 | return; |
157 | 165 | ||
158 | struct GNUNET_BarrierHandle *barrier = waiting->barrier; | 166 | struct GNUNET_BarrierHandle *barrier = waiting->barrier; |
159 | 167 | ||
160 | if (!barrier) | 168 | if (! barrier) |
161 | return; | 169 | return; |
162 | 170 | ||
163 | if ((barrier->requirement == 0) && (barrier->task)) | 171 | if ((barrier->requirement == 0) && (barrier->task)) |
164 | { | 172 | { |
165 | GNUNET_SCHEDULER_cancel(barrier->task); | 173 | GNUNET_SCHEDULER_cancel (barrier->task); |
166 | barrier->task = NULL; | 174 | barrier->task = NULL; |
167 | } | 175 | } |
168 | 176 | ||
169 | barrier->requirement++; | 177 | barrier->requirement++; |
170 | GNUNET_CONTAINER_DLL_remove(barrier->head, barrier->tail, waiting); | 178 | GNUNET_CONTAINER_DLL_remove (barrier->head, barrier->tail, waiting); |
171 | 179 | ||
172 | GNUNET_free(waiting); | 180 | GNUNET_free (waiting); |
173 | } | 181 | } |