aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet.conf.in1
-rw-r--r--src/include/gnunet_scheduler_lib.h45
-rw-r--r--src/util/scheduler.c85
3 files changed, 108 insertions, 23 deletions
diff --git a/src/cadet/cadet.conf.in b/src/cadet/cadet.conf.in
index 88f49fde8..48fd03329 100644
--- a/src/cadet/cadet.conf.in
+++ b/src/cadet/cadet.conf.in
@@ -4,6 +4,7 @@ AUTOSTART = @AUTOSTART@
4@JAVAPORT@PORT = 2096 4@JAVAPORT@PORT = 2096
5HOSTNAME = localhost 5HOSTNAME = localhost
6BINARY = gnunet-service-cadet 6BINARY = gnunet-service-cadet
7# PREFIX = valgrind --leak-check=yes
7ACCEPT_FROM = 127.0.0.1; 8ACCEPT_FROM = 127.0.0.1;
8ACCEPT_FROM6 = ::1; 9ACCEPT_FROM6 = ::1;
9UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-cadet.sock 10UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-cadet.sock
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h
index 1a0438bed..2be1858ce 100644
--- a/src/include/gnunet_scheduler_lib.h
+++ b/src/include/gnunet_scheduler_lib.h
@@ -172,7 +172,7 @@ GNUNET_SCHEDULER_run (GNUNET_SCHEDULER_TaskCallback task,
172 172
173 173
174/** 174/**
175 * Request the shutdown of a scheduler. Marks all tasks 175 * Request the shutdown of a scheduler. Marks all tasks
176 * awaiting shutdown as ready. Note that tasks 176 * awaiting shutdown as ready. Note that tasks
177 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call 177 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
178 * will be delayed until the next shutdown signal. 178 * will be delayed until the next shutdown signal.
@@ -309,7 +309,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
309 * will be scheduled for execution once the delay has expired. It 309 * will be scheduled for execution once the delay has expired. It
310 * will be run with the DEFAULT priority. 310 * will be run with the DEFAULT priority.
311 * 311 *
312 * @param delay when should this operation time out? 312 * @param delay with which the operation should be run
313 * @param task main function of the task 313 * @param task main function of the task
314 * @param task_cls closure of @a task 314 * @param task_cls closure of @a task
315 * @return unique task identifier for the job 315 * @return unique task identifier for the job
@@ -322,10 +322,27 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
322 322
323 323
324/** 324/**
325 * Schedule a new task to be run at the specified time. The task
326 * will be scheduled for execution once specified time has been
327 * reached. It will be run with the DEFAULT priority.
328 *
329 * @param at time at which this operation should run
330 * @param task main function of the task
331 * @param task_cls closure of @a task
332 * @return unique task identifier for the job
333 * only valid until @a task is started!
334 */
335struct GNUNET_SCHEDULER_Task *
336GNUNET_SCHEDULER_add_at (struct GNUNET_TIME_Absolute at,
337 GNUNET_SCHEDULER_TaskCallback task,
338 void *task_cls);
339
340
341/**
325 * Schedule a new task to be run with a specified delay. The task 342 * Schedule a new task to be run with a specified delay. The task
326 * will be scheduled for execution once the delay has expired. 343 * will be scheduled for execution once the delay has expired.
327 * 344 *
328 * @param delay when should this operation time out? 345 * @param delay when should this operation time out?
329 * @param priority priority to use for the task 346 * @param priority priority to use for the task
330 * @param task main function of the task 347 * @param task main function of the task
331 * @param task_cls closure of @a task 348 * @param task_cls closure of @a task
@@ -340,6 +357,24 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
340 357
341 358
342/** 359/**
360 * Schedule a new task to be run at the specified time. The task
361 * will be scheduled for execution at time @a at.
362 *
363 * @param at time when the operation should run
364 * @param priority priority to use for the task
365 * @param task main function of the task
366 * @param task_cls closure of @a task
367 * @return unique task identifier for the job
368 * only valid until @a task is started!
369 */
370struct GNUNET_SCHEDULER_Task *
371GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
372 enum GNUNET_SCHEDULER_Priority priority,
373 GNUNET_SCHEDULER_TaskCallback task,
374 void *task_cls);
375
376
377/**
343 * Schedule a new task to be run with a specified delay or when the 378 * Schedule a new task to be run with a specified delay or when the
344 * specified file descriptor is ready for reading. The delay can be 379 * specified file descriptor is ready for reading. The delay can be
345 * used as a timeout on the socket being ready. The task will be 380 * used as a timeout on the socket being ready. The task will be
@@ -480,7 +515,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
480 * scheduled for execution once either the delay has expired or the 515 * scheduled for execution once either the delay has expired or the
481 * socket operation is ready. 516 * socket operation is ready.
482 * 517 *
483 * @param delay when should this operation time out? 518 * @param delay when should this operation time out?
484 * @param priority priority of the task 519 * @param priority priority of the task
485 * @param fd file-descriptor 520 * @param fd file-descriptor
486 * @param on_read whether to poll the file-descriptor for readability 521 * @param on_read whether to poll the file-descriptor for readability
@@ -516,7 +551,7 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
516 * </code> 551 * </code>
517 * 552 *
518 * @param prio how important is this task? 553 * @param prio how important is this task?
519 * @param delay how long should we wait? 554 * @param delay how long should we wait?
520 * @param rs set of file descriptors we want to read (can be NULL) 555 * @param rs set of file descriptors we want to read (can be NULL)
521 * @param ws set of file descriptors we want to write (can be NULL) 556 * @param ws set of file descriptors we want to write (can be NULL)
522 * @param task main function of the task 557 * @param task main function of the task
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index b016b91b7..409a0942f 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -155,7 +155,7 @@ struct GNUNET_SCHEDULER_Task
155 * Is this task run on shutdown? 155 * Is this task run on shutdown?
156 */ 156 */
157 int on_shutdown; 157 int on_shutdown;
158 158
159 /** 159 /**
160 * Is this task in the ready list? 160 * Is this task in the ready list?
161 */ 161 */
@@ -490,7 +490,7 @@ check_ready (const struct GNUNET_NETWORK_FDSet *rs,
490 490
491 491
492/** 492/**
493 * Request the shutdown of a scheduler. Marks all tasks 493 * Request the shutdown of a scheduler. Marks all tasks
494 * awaiting shutdown as ready. Note that tasks 494 * awaiting shutdown as ready. Note that tasks
495 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call 495 * scheduled with #GNUNET_SCHEDULER_add_shutdown() AFTER this call
496 * will be delayed until the next shutdown signal. 496 * will be delayed until the next shutdown signal.
@@ -534,13 +534,13 @@ destroy_task (struct GNUNET_SCHEDULER_Task *t)
534 * Output stack trace of task @a t. 534 * Output stack trace of task @a t.
535 * 535 *
536 * @param t task to dump stack trace of 536 * @param t task to dump stack trace of
537 */ 537 */
538static void 538static void
539dump_backtrace (struct GNUNET_SCHEDULER_Task *t) 539dump_backtrace (struct GNUNET_SCHEDULER_Task *t)
540{ 540{
541#if EXECINFO 541#if EXECINFO
542 unsigned int i; 542 unsigned int i;
543 543
544 for (i = 0; i < t->num_backtrace_strings; i++) 544 for (i = 0; i < t->num_backtrace_strings; i++)
545 LOG (GNUNET_ERROR_TYPE_DEBUG, 545 LOG (GNUNET_ERROR_TYPE_DEBUG,
546 "Task %p trace %u: %s\n", 546 "Task %p trace %u: %s\n",
@@ -1080,10 +1080,10 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
1080 1080
1081 1081
1082/** 1082/**
1083 * Schedule a new task to be run with a specified delay. The task 1083 * Schedule a new task to be run at the specified time. The task
1084 * will be scheduled for execution once the delay has expired. 1084 * will be scheduled for execution at time @a at.
1085 * 1085 *
1086 * @param delay when should this operation time out? 1086 * @param at time when the operation should run
1087 * @param priority priority to use for the task 1087 * @param priority priority to use for the task
1088 * @param task main function of the task 1088 * @param task main function of the task
1089 * @param task_cls closure of @a task 1089 * @param task_cls closure of @a task
@@ -1091,10 +1091,10 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas
1091 * only valid until @a task is started! 1091 * only valid until @a task is started!
1092 */ 1092 */
1093struct GNUNET_SCHEDULER_Task * 1093struct GNUNET_SCHEDULER_Task *
1094GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay, 1094GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at,
1095 enum GNUNET_SCHEDULER_Priority priority, 1095 enum GNUNET_SCHEDULER_Priority priority,
1096 GNUNET_SCHEDULER_TaskCallback task, 1096 GNUNET_SCHEDULER_TaskCallback task,
1097 void *task_cls) 1097 void *task_cls)
1098{ 1098{
1099 struct GNUNET_SCHEDULER_Task *t; 1099 struct GNUNET_SCHEDULER_Task *t;
1100 struct GNUNET_SCHEDULER_Task *pos; 1100 struct GNUNET_SCHEDULER_Task *pos;
@@ -1110,12 +1110,13 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1110#if PROFILE_DELAYS 1110#if PROFILE_DELAYS
1111 t->start_time = GNUNET_TIME_absolute_get (); 1111 t->start_time = GNUNET_TIME_absolute_get ();
1112#endif 1112#endif
1113 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1113 t->timeout = at;
1114 t->priority = priority; 1114 t->priority = priority;
1115 t->lifeness = current_lifeness; 1115 t->lifeness = current_lifeness;
1116 /* try tail first (optimization in case we are 1116 /* try tail first (optimization in case we are
1117 * appending to a long list of tasks with timeouts) */ 1117 * appending to a long list of tasks with timeouts) */
1118 if (0 == delay.rel_value_us) 1118 if ( (NULL == pending_timeout_head) ||
1119 (at.abs_value_us < pending_timeout_head->timeout.abs_value_us) )
1119 { 1120 {
1120 GNUNET_CONTAINER_DLL_insert (pending_timeout_head, 1121 GNUNET_CONTAINER_DLL_insert (pending_timeout_head,
1121 pending_timeout_tail, 1122 pending_timeout_tail,
@@ -1144,9 +1145,9 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1144 pending_timeout_tail, 1145 pending_timeout_tail,
1145 prev, 1146 prev,
1146 t); 1147 t);
1147 /* finally, update heuristic insertion point to last insertion... */
1148 pending_timeout_last = t;
1149 } 1148 }
1149 /* finally, update heuristic insertion point to last insertion... */
1150 pending_timeout_last = t;
1150 1151
1151 LOG (GNUNET_ERROR_TYPE_DEBUG, 1152 LOG (GNUNET_ERROR_TYPE_DEBUG,
1152 "Adding task: %p\n", 1153 "Adding task: %p\n",
@@ -1157,6 +1158,30 @@ GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1157 1158
1158 1159
1159/** 1160/**
1161 * Schedule a new task to be run with a specified delay. The task
1162 * will be scheduled for execution once the delay has expired.
1163 *
1164 * @param delay when should this operation time out?
1165 * @param priority priority to use for the task
1166 * @param task main function of the task
1167 * @param task_cls closure of @a task
1168 * @return unique task identifier for the job
1169 * only valid until @a task is started!
1170 */
1171struct GNUNET_SCHEDULER_Task *
1172GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1173 enum GNUNET_SCHEDULER_Priority priority,
1174 GNUNET_SCHEDULER_TaskCallback task,
1175 void *task_cls)
1176{
1177 return GNUNET_SCHEDULER_add_at_with_priority (GNUNET_TIME_relative_to_absolute (delay),
1178 priority,
1179 task,
1180 task_cls);
1181}
1182
1183
1184/**
1160 * Schedule a new task to be run with a specified priority. 1185 * Schedule a new task to be run with a specified priority.
1161 * 1186 *
1162 * @param prio how important is the new task? 1187 * @param prio how important is the new task?
@@ -1178,6 +1203,29 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1178 1203
1179 1204
1180/** 1205/**
1206 * Schedule a new task to be run at the specified time. The task
1207 * will be scheduled for execution once specified time has been
1208 * reached. It will be run with the DEFAULT priority.
1209 *
1210 * @param at time at which this operation should run
1211 * @param task main function of the task
1212 * @param task_cls closure of @a task
1213 * @return unique task identifier for the job
1214 * only valid until @a task is started!
1215 */
1216struct GNUNET_SCHEDULER_Task *
1217GNUNET_SCHEDULER_add_at (struct GNUNET_TIME_Absolute at,
1218 GNUNET_SCHEDULER_TaskCallback task,
1219 void *task_cls)
1220{
1221 return GNUNET_SCHEDULER_add_at_with_priority (at,
1222 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1223 task,
1224 task_cls);
1225}
1226
1227
1228/**
1181 * Schedule a new task to be run with a specified delay. The task 1229 * Schedule a new task to be run with a specified delay. The task
1182 * will be scheduled for execution once the delay has expired. It 1230 * will be scheduled for execution once the delay has expired. It
1183 * will be run with the DEFAULT priority. 1231 * will be run with the DEFAULT priority.
@@ -1195,7 +1243,8 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1195{ 1243{
1196 return GNUNET_SCHEDULER_add_delayed_with_priority (delay, 1244 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1197 GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1245 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1198 task, task_cls); 1246 task,
1247 task_cls);
1199} 1248}
1200 1249
1201 1250
@@ -1391,7 +1440,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay,
1391 * scheduled for execution once either the delay has expired or the 1440 * scheduled for execution once either the delay has expired or the
1392 * socket operation is ready. It will be run with the DEFAULT priority. 1441 * socket operation is ready. It will be run with the DEFAULT priority.
1393 * 1442 *
1394 * @param delay when should this operation time out? 1443 * @param delay when should this operation time out?
1395 * @param rfd read file-descriptor 1444 * @param rfd read file-descriptor
1396 * @param task main function of the task 1445 * @param task main function of the task
1397 * @param task_cls closure of @a task 1446 * @param task_cls closure of @a task
@@ -1640,7 +1689,7 @@ GNUNET_SCHEDULER_add_file_with_priority (struct GNUNET_TIME_Relative delay,
1640 * </code> 1689 * </code>
1641 * 1690 *
1642 * @param prio how important is this task? 1691 * @param prio how important is this task?
1643 * @param delay how long should we wait? 1692 * @param delay how long should we wait?
1644 * @param rs set of file descriptors we want to read (can be NULL) 1693 * @param rs set of file descriptors we want to read (can be NULL)
1645 * @param ws set of file descriptors we want to write (can be NULL) 1694 * @param ws set of file descriptors we want to write (can be NULL)
1646 * @param task main function of the task 1695 * @param task main function of the task