diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-05-05 18:51:21 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-05-05 18:51:21 +0000 |
commit | 201817c66fb0eb1d477085091bb30e3b1e832e9e (patch) | |
tree | 052d32a9a245c76565f59ee2fa1d45950e6bb96e /src/testbed/testbed_api_operations.c | |
parent | aa4d975205a4f8da4a4dcfd9d7274db8138a9d07 (diff) | |
download | gnunet-201817c66fb0eb1d477085091bb30e3b1e832e9e.tar.gz gnunet-201817c66fb0eb1d477085091bb30e3b1e832e9e.zip |
-draft structure for operation queues
Diffstat (limited to 'src/testbed/testbed_api_operations.c')
-rw-r--r-- | src/testbed/testbed_api_operations.c | 122 |
1 files changed, 121 insertions, 1 deletions
diff --git a/src/testbed/testbed_api_operations.c b/src/testbed/testbed_api_operations.c index 621090bd7..c98998bbf 100644 --- a/src/testbed/testbed_api_operations.c +++ b/src/testbed/testbed_api_operations.c | |||
@@ -32,10 +32,127 @@ | |||
32 | */ | 32 | */ |
33 | struct GNUNET_TESTBED_Operation | 33 | struct GNUNET_TESTBED_Operation |
34 | { | 34 | { |
35 | /** | ||
36 | * Function to call when we have the resources to begin the operation. | ||
37 | */ | ||
38 | OperationStart start; | ||
39 | |||
40 | /** | ||
41 | * Function to call to clean up after the operation (which may or may | ||
42 | * not have been started yet). | ||
43 | */ | ||
44 | OperationRelease release; | ||
45 | |||
46 | /** | ||
47 | * Closure for callbacks. | ||
48 | */ | ||
49 | void *cb_cls; | ||
50 | |||
35 | // FIXME! | 51 | // FIXME! |
52 | |||
53 | }; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Queue of operations where we can only support a certain | ||
58 | * number of concurrent operations of a particular type. | ||
59 | */ | ||
60 | struct OperationQueue | ||
61 | { | ||
62 | |||
63 | /** | ||
64 | * Maximum number of operationst that can be concurrently | ||
65 | * active in this queue. | ||
66 | */ | ||
67 | unsigned int max_active; | ||
68 | |||
69 | // FIXME! | ||
70 | |||
36 | }; | 71 | }; |
37 | 72 | ||
38 | 73 | ||
74 | /** | ||
75 | * Create an operation queue. | ||
76 | * | ||
77 | * @param max_active maximum number of operations in this | ||
78 | * queue that can be active in parallel at the same time | ||
79 | * @return handle to the queue | ||
80 | */ | ||
81 | struct OperationQueue * | ||
82 | GNUNET_TESTBED_operation_queue_create_ (unsigned int max_active) | ||
83 | { | ||
84 | struct OperationQueue *queue; | ||
85 | |||
86 | queue = GNUNET_malloc (sizeof (struct OperationQueue)); | ||
87 | queue->max_active = max_active; | ||
88 | return queue; | ||
89 | } | ||
90 | |||
91 | |||
92 | /** | ||
93 | * Destroy an operation queue. The queue MUST be empty | ||
94 | * at this time. | ||
95 | * | ||
96 | * @param queue queue to destroy | ||
97 | */ | ||
98 | void | ||
99 | GNUNET_TESTBED_operation_queue_destroy_ (struct OperationQueue *queue) | ||
100 | { | ||
101 | GNUNET_break (0); | ||
102 | GNUNET_free (queue); | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Add an operation to a queue. An operation can be in multiple | ||
108 | * queues at once. Once all queues permit the operation to become | ||
109 | * active, the operation will be activated. The actual activation | ||
110 | * will occur in a separate task (thus allowing multiple queue | ||
111 | * insertions to be made without having the first one instantly | ||
112 | * trigger the operation if the first queue has sufficient | ||
113 | * resources). | ||
114 | * | ||
115 | * @param queue queue to add the operation to | ||
116 | * @param operation operation to add to the queue | ||
117 | */ | ||
118 | void | ||
119 | GNUNET_TESTBED_operation_queue_insert_ (struct OperationQueue *queue, | ||
120 | struct GNUNET_TESTBED_Operation *operation) | ||
121 | { | ||
122 | GNUNET_break (0); | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Remove an operation from a queue. This can be because the | ||
128 | * oeration was active and has completed (and the resources have | ||
129 | * been released), or because the operation was cancelled and | ||
130 | * thus scheduling the operation is no longer required. | ||
131 | * | ||
132 | * @param queue queue to add the operation to | ||
133 | * @param operation operation to add to the queue | ||
134 | */ | ||
135 | void | ||
136 | GNUNET_TESTBED_operation_queue_remove_ (struct OperationQueue *queue, | ||
137 | struct GNUNET_TESTBED_Operation *operation) | ||
138 | { | ||
139 | GNUNET_break (0); | ||
140 | } | ||
141 | |||
142 | |||
143 | /** | ||
144 | * An operation is 'done' (was cancelled or finished); remove | ||
145 | * it from the queues and release associated resources. | ||
146 | * | ||
147 | * @param operation operation that finished | ||
148 | */ | ||
149 | static void | ||
150 | operation_release (struct GNUNET_TESTBED_Operation *operation) | ||
151 | { | ||
152 | // call operation->release, remove from queues | ||
153 | GNUNET_break (0); | ||
154 | } | ||
155 | |||
39 | 156 | ||
40 | /** | 157 | /** |
41 | * Cancel a pending operation. Releases all resources | 158 | * Cancel a pending operation. Releases all resources |
@@ -49,8 +166,9 @@ struct GNUNET_TESTBED_Operation | |||
49 | void | 166 | void |
50 | GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation) | 167 | GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation) |
51 | { | 168 | { |
169 | // test that operation had not yet generated an event | ||
52 | GNUNET_break (0); | 170 | GNUNET_break (0); |
53 | 171 | operation_release (operation); | |
54 | } | 172 | } |
55 | 173 | ||
56 | 174 | ||
@@ -66,7 +184,9 @@ GNUNET_TESTBED_operation_cancel (struct GNUNET_TESTBED_Operation *operation) | |||
66 | void | 184 | void |
67 | GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) | 185 | GNUNET_TESTBED_operation_done (struct GNUNET_TESTBED_Operation *operation) |
68 | { | 186 | { |
187 | // test that operation was started and had generated an event | ||
69 | GNUNET_break (0); | 188 | GNUNET_break (0); |
189 | operation_release (operation); | ||
70 | } | 190 | } |
71 | 191 | ||
72 | 192 | ||