aboutsummaryrefslogtreecommitdiff
path: root/src/util/scheduler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-01 21:12:17 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-01 21:12:17 +0000
commit64c442461b84953230d3dc4e78cb649db6c54abc (patch)
tree49ec875b32ce171aac2bbae1b5fcaad516a94cf6 /src/util/scheduler.c
parent0413c7690e087a0514447a87bc8118b2a244c902 (diff)
downloadgnunet-64c442461b84953230d3dc4e78cb649db6c54abc.tar.gz
gnunet-64c442461b84953230d3dc4e78cb649db6c54abc.zip
changing scheduler priorities to revert to DEFAULT instead of inheriting parent-task priority unless something else is explicitly specified
Diffstat (limited to 'src/util/scheduler.c')
-rw-r--r--src/util/scheduler.c129
1 files changed, 82 insertions, 47 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 1acc9a6d6..5f91ffbbc 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -1054,10 +1054,12 @@ GNUNET_SCHEDULER_cancel (GNUNET_SCHEDULER_TaskIdentifier task)
1054 * @param task main function of the task 1054 * @param task main function of the task
1055 * @param task_cls closure for 'main' 1055 * @param task_cls closure for 'main'
1056 * @param reason reason for task invocation 1056 * @param reason reason for task invocation
1057 * @param priority priority to use for the task
1057 */ 1058 */
1058void 1059void
1059GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls, 1060GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_Task task, void *task_cls,
1060 enum GNUNET_SCHEDULER_Reason reason) 1061 enum GNUNET_SCHEDULER_Reason reason,
1062 enum GNUNET_SCHEDULER_Priority priority)
1061{ 1063{
1062 struct Task *t; 1064 struct Task *t;
1063 1065
@@ -1083,7 +1085,7 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1083 t->start_time = GNUNET_TIME_absolute_get (); 1085 t->start_time = GNUNET_TIME_absolute_get ();
1084#endif 1086#endif
1085 t->reason = reason; 1087 t->reason = reason;
1086 t->priority = current_priority; 1088 t->priority = priority;
1087 t->lifeness = current_lifeness; 1089 t->lifeness = current_lifeness;
1088#if DEBUG_TASKS 1090#if DEBUG_TASKS
1089 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id, 1091 LOG (GNUNET_ERROR_TYPE_DEBUG, "Adding continuation task: %llu / %p\n", t->id,
@@ -1093,11 +1095,28 @@ GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1093} 1095}
1094 1096
1095 1097
1098/**
1099 * Continue the current execution with the given function. This is
1100 * similar to the other "add" functions except that there is no delay
1101 * and the reason code can be specified.
1102 *
1103 * @param task main function of the task
1104 * @param task_cls closure for 'main'
1105 * @param reason reason for task invocation
1106 */
1107void
1108GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_Task task, void *task_cls,
1109 enum GNUNET_SCHEDULER_Reason reason)
1110{
1111 GNUNET_SCHEDULER_add_continuation_with_priority (task, task_cls,
1112 reason,
1113 GNUNET_SCHEDULER_PRIORITY_DEFAULT);
1114}
1115
1096 1116
1097/** 1117/**
1098 * Schedule a new task to be run after the specified prerequisite task 1118 * Schedule a new task to be run after the specified prerequisite task
1099 * has completed. It will be run with the priority of the calling 1119 * has completed. It will be run with the DEFAULT priority.
1100 * task.
1101 * 1120 *
1102 * @param prerequisite_task run this task after the task with the given 1121 * @param prerequisite_task run this task after the task with the given
1103 * task identifier completes (and any of our other 1122 * task identifier completes (and any of our other
@@ -1114,7 +1133,7 @@ GNUNET_SCHEDULER_TaskIdentifier
1114GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task, 1133GNUNET_SCHEDULER_add_after (GNUNET_SCHEDULER_TaskIdentifier prerequisite_task,
1115 GNUNET_SCHEDULER_Task task, void *task_cls) 1134 GNUNET_SCHEDULER_Task task, void *task_cls)
1116{ 1135{
1117 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1136 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1118 prerequisite_task, GNUNET_TIME_UNIT_ZERO, 1137 prerequisite_task, GNUNET_TIME_UNIT_ZERO,
1119 NULL, NULL, task, task_cls); 1138 NULL, NULL, task, task_cls);
1120} 1139}
@@ -1142,22 +1161,21 @@ GNUNET_SCHEDULER_add_with_priority (enum GNUNET_SCHEDULER_Priority prio,
1142 1161
1143/** 1162/**
1144 * Schedule a new task to be run with a specified delay. The task 1163 * Schedule a new task to be run with a specified delay. The task
1145 * will be scheduled for execution once the delay has expired. It 1164 * will be scheduled for execution once the delay has expired.
1146 * will be run with the priority of the calling task.
1147 * 1165 *
1148 * @param delay when should this operation time out? Use 1166 * @param delay when should this operation time out? Use
1149 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1167 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1168 * @param priority priority to use for the task
1150 * @param task main function of the task 1169 * @param task main function of the task
1151 * @param task_cls closure of task 1170 * @param task_cls closure of task
1152 * @return unique task identifier for the job 1171 * @return unique task identifier for the job
1153 * only valid until "task" is started! 1172 * only valid until "task" is started!
1154 */ 1173 */
1155GNUNET_SCHEDULER_TaskIdentifier 1174GNUNET_SCHEDULER_TaskIdentifier
1156GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay, 1175GNUNET_SCHEDULER_add_delayed_with_priority (struct GNUNET_TIME_Relative delay,
1157 GNUNET_SCHEDULER_Task task, void *task_cls) 1176 enum GNUNET_SCHEDULER_Priority priority,
1177 GNUNET_SCHEDULER_Task task, void *task_cls)
1158{ 1178{
1159#if 1
1160 /* new, optimized version */
1161 struct Task *t; 1179 struct Task *t;
1162 struct Task *pos; 1180 struct Task *pos;
1163 struct Task *prev; 1181 struct Task *prev;
@@ -1183,7 +1201,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1183 t->start_time = GNUNET_TIME_absolute_get (); 1201 t->start_time = GNUNET_TIME_absolute_get ();
1184#endif 1202#endif
1185 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1203 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1186 t->priority = current_priority; 1204 t->priority = priority;
1187 t->lifeness = current_lifeness; 1205 t->lifeness = current_lifeness;
1188 /* try tail first (optimization in case we are 1206 /* try tail first (optimization in case we are
1189 * appending to a long list of tasks with timeouts) */ 1207 * appending to a long list of tasks with timeouts) */
@@ -1227,20 +1245,34 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1227 t->backtrace_strings[i]); 1245 t->backtrace_strings[i]);
1228#endif 1246#endif
1229 return t->id; 1247 return t->id;
1230
1231#else
1232 /* unoptimized version */
1233 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP,
1234 GNUNET_SCHEDULER_NO_TASK, delay, NULL,
1235 NULL, task, task_cls);
1236#endif
1237} 1248}
1238 1249
1239 1250
1251/**
1252 * Schedule a new task to be run with a specified delay. The task
1253 * will be scheduled for execution once the delay has expired. It
1254 * will be run with the DEFAULT priority.
1255 *
1256 * @param delay when should this operation time out? Use
1257 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
1258 * @param task main function of the task
1259 * @param task_cls closure of task
1260 * @return unique task identifier for the job
1261 * only valid until "task" is started!
1262 */
1263GNUNET_SCHEDULER_TaskIdentifier
1264GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1265 GNUNET_SCHEDULER_Task task, void *task_cls)
1266{
1267 return GNUNET_SCHEDULER_add_delayed_with_priority (delay,
1268 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1269 task, task_cls);
1270}
1271
1240 1272
1241/** 1273/**
1242 * Schedule a new task to be run as soon as possible. The task 1274 * Schedule a new task to be run as soon as possible. The task
1243 * will be run with the priority of the calling task. 1275 * will be run with the DEFAULT priority.
1244 * 1276 *
1245 * @param task main function of the task 1277 * @param task main function of the task
1246 * @param task_cls closure of task 1278 * @param task_cls closure of task
@@ -1250,10 +1282,7 @@ GNUNET_SCHEDULER_add_delayed (struct GNUNET_TIME_Relative delay,
1250GNUNET_SCHEDULER_TaskIdentifier 1282GNUNET_SCHEDULER_TaskIdentifier
1251GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls) 1283GNUNET_SCHEDULER_add_now (GNUNET_SCHEDULER_Task task, void *task_cls)
1252{ 1284{
1253 return GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1285 return GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_ZERO, task, task_cls);
1254 GNUNET_SCHEDULER_NO_TASK,
1255 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1256 task_cls);
1257} 1286}
1258 1287
1259 1288
@@ -1279,7 +1308,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1279 GNUNET_SCHEDULER_TaskIdentifier ret; 1308 GNUNET_SCHEDULER_TaskIdentifier ret;
1280 1309
1281 ret = 1310 ret =
1282 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_KEEP, 1311 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1283 GNUNET_SCHEDULER_NO_TASK, 1312 GNUNET_SCHEDULER_NO_TASK,
1284 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task, 1313 GNUNET_TIME_UNIT_ZERO, NULL, NULL, task,
1285 task_cls); 1314 task_cls);
@@ -1289,8 +1318,6 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1289} 1318}
1290 1319
1291 1320
1292
1293
1294/** 1321/**
1295 * Schedule a new task to be run with a specified delay or when any of 1322 * Schedule a new task to be run with a specified delay or when any of
1296 * the specified file descriptor sets is ready. The delay can be used 1323 * the specified file descriptor sets is ready. The delay can be used
@@ -1310,6 +1337,7 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1310 * 1337 *
1311 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever", 1338 * @param delay how long should we wait? Use GNUNET_TIME_UNIT_FOREVER_REL for "forever",
1312 * which means that the task will only be run after we receive SIGTERM 1339 * which means that the task will only be run after we receive SIGTERM
1340 * @param priority priority to use
1313 * @param rfd file descriptor we want to read (can be -1) 1341 * @param rfd file descriptor we want to read (can be -1)
1314 * @param wfd file descriptors we want to write (can be -1) 1342 * @param wfd file descriptors we want to write (can be -1)
1315 * @param task main function of the task 1343 * @param task main function of the task
@@ -1319,7 +1347,9 @@ GNUNET_SCHEDULER_add_now_with_lifeness (int lifeness,
1319 */ 1347 */
1320#ifndef MINGW 1348#ifndef MINGW
1321static GNUNET_SCHEDULER_TaskIdentifier 1349static GNUNET_SCHEDULER_TaskIdentifier
1322add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd, 1350add_without_sets (struct GNUNET_TIME_Relative delay,
1351 enum GNUNET_SCHEDULER_Priority priority,
1352 int rfd, int wfd,
1323 GNUNET_SCHEDULER_Task task, void *task_cls) 1353 GNUNET_SCHEDULER_Task task, void *task_cls)
1324{ 1354{
1325 struct Task *t; 1355 struct Task *t;
@@ -1381,7 +1411,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1381#endif 1411#endif
1382 t->prereq_id = GNUNET_SCHEDULER_NO_TASK; 1412 t->prereq_id = GNUNET_SCHEDULER_NO_TASK;
1383 t->timeout = GNUNET_TIME_relative_to_absolute (delay); 1413 t->timeout = GNUNET_TIME_relative_to_absolute (delay);
1384 t->priority = check_priority (current_priority); 1414 t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority);
1385 t->lifeness = current_lifeness; 1415 t->lifeness = current_lifeness;
1386 t->next = pending; 1416 t->next = pending;
1387 pending = t; 1417 pending = t;
@@ -1408,8 +1438,7 @@ add_without_sets (struct GNUNET_TIME_Relative delay, int rfd, int wfd,
1408 * specified file descriptor is ready for reading. The delay can be 1438 * specified file descriptor is ready for reading. The delay can be
1409 * used as a timeout on the socket being ready. The task will be 1439 * used as a timeout on the socket being ready. The task will be
1410 * scheduled for execution once either the delay has expired or the 1440 * scheduled for execution once either the delay has expired or the
1411 * socket operation is ready. It will be run with the priority of 1441 * socket operation is ready. It will be run with the DEFAULT priority.
1412 * the calling task.
1413 * 1442 *
1414 * @param delay when should this operation time out? Use 1443 * @param delay when should this operation time out? Use
1415 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1444 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -1432,13 +1461,15 @@ GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
1432 rs = GNUNET_NETWORK_fdset_create (); 1461 rs = GNUNET_NETWORK_fdset_create ();
1433 GNUNET_NETWORK_fdset_set (rs, rfd); 1462 GNUNET_NETWORK_fdset_set (rs, rfd);
1434 ret = 1463 ret =
1435 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1464 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1436 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, 1465 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1437 task, task_cls); 1466 task, task_cls);
1438 GNUNET_NETWORK_fdset_destroy (rs); 1467 GNUNET_NETWORK_fdset_destroy (rs);
1439 return ret; 1468 return ret;
1440#else 1469#else
1441 return add_without_sets (delay, GNUNET_NETWORK_get_fd (rfd), -1, task, 1470 return add_without_sets (delay,
1471 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1472 GNUNET_NETWORK_get_fd (rfd), -1, task,
1442 task_cls); 1473 task_cls);
1443#endif 1474#endif
1444} 1475}
@@ -1473,14 +1504,16 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1473 ws = GNUNET_NETWORK_fdset_create (); 1504 ws = GNUNET_NETWORK_fdset_create ();
1474 GNUNET_NETWORK_fdset_set (ws, wfd); 1505 GNUNET_NETWORK_fdset_set (ws, wfd);
1475 ret = 1506 ret =
1476 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1507 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1477 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, 1508 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1478 task, task_cls); 1509 task, task_cls);
1479 GNUNET_NETWORK_fdset_destroy (ws); 1510 GNUNET_NETWORK_fdset_destroy (ws);
1480 return ret; 1511 return ret;
1481#else 1512#else
1482 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0); 1513 GNUNET_assert (GNUNET_NETWORK_get_fd (wfd) >= 0);
1483 return add_without_sets (delay, -1, GNUNET_NETWORK_get_fd (wfd), task, 1514 return add_without_sets (delay,
1515 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1516 -1, GNUNET_NETWORK_get_fd (wfd), task,
1484 task_cls); 1517 task_cls);
1485#endif 1518#endif
1486} 1519}
@@ -1491,8 +1524,7 @@ GNUNET_SCHEDULER_add_write_net (struct GNUNET_TIME_Relative delay,
1491 * specified file descriptor is ready for reading. The delay can be 1524 * specified file descriptor is ready for reading. The delay can be
1492 * used as a timeout on the socket being ready. The task will be 1525 * used as a timeout on the socket being ready. The task will be
1493 * scheduled for execution once either the delay has expired or the 1526 * scheduled for execution once either the delay has expired or the
1494 * socket operation is ready. It will be run with the priority of 1527 * socket operation is ready. It will be run with the DEFAULT priority.
1495 * the calling task.
1496 * 1528 *
1497 * @param delay when should this operation time out? Use 1529 * @param delay when should this operation time out? Use
1498 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1530 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -1515,7 +1547,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1515 rs = GNUNET_NETWORK_fdset_create (); 1547 rs = GNUNET_NETWORK_fdset_create ();
1516 GNUNET_NETWORK_fdset_handle_set (rs, rfd); 1548 GNUNET_NETWORK_fdset_handle_set (rs, rfd);
1517 ret = 1549 ret =
1518 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1550 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1519 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL, 1551 GNUNET_SCHEDULER_NO_TASK, delay, rs, NULL,
1520 task, task_cls); 1552 task, task_cls);
1521 GNUNET_NETWORK_fdset_destroy (rs); 1553 GNUNET_NETWORK_fdset_destroy (rs);
@@ -1524,7 +1556,9 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1524 int fd; 1556 int fd;
1525 1557
1526 GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int)); 1558 GNUNET_DISK_internal_file_handle_ (rfd, &fd, sizeof (int));
1527 return add_without_sets (delay, fd, -1, task, task_cls); 1559 return add_without_sets (delay,
1560 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1561 fd, -1, task, task_cls);
1528 1562
1529#endif 1563#endif
1530} 1564}
@@ -1535,8 +1569,7 @@ GNUNET_SCHEDULER_add_read_file (struct GNUNET_TIME_Relative delay,
1535 * specified file descriptor is ready for writing. The delay can be 1569 * specified file descriptor is ready for writing. The delay can be
1536 * used as a timeout on the socket being ready. The task will be 1570 * used as a timeout on the socket being ready. The task will be
1537 * scheduled for execution once either the delay has expired or the 1571 * scheduled for execution once either the delay has expired or the
1538 * socket operation is ready. It will be run with the priority of 1572 * socket operation is ready. It will be run with the DEFAULT priority.
1539 * the calling task.
1540 * 1573 *
1541 * @param delay when should this operation time out? Use 1574 * @param delay when should this operation time out? Use
1542 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown" 1575 * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
@@ -1559,7 +1592,7 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1559 ws = GNUNET_NETWORK_fdset_create (); 1592 ws = GNUNET_NETWORK_fdset_create ();
1560 GNUNET_NETWORK_fdset_handle_set (ws, wfd); 1593 GNUNET_NETWORK_fdset_handle_set (ws, wfd);
1561 ret = 1594 ret =
1562 GNUNET_SCHEDULER_add_select (check_priority (current_priority), 1595 GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1563 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws, 1596 GNUNET_SCHEDULER_NO_TASK, delay, NULL, ws,
1564 task, task_cls); 1597 task, task_cls);
1565 GNUNET_NETWORK_fdset_destroy (ws); 1598 GNUNET_NETWORK_fdset_destroy (ws);
@@ -1569,7 +1602,9 @@ GNUNET_SCHEDULER_add_write_file (struct GNUNET_TIME_Relative delay,
1569 1602
1570 GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int)); 1603 GNUNET_DISK_internal_file_handle_ (wfd, &fd, sizeof (int));
1571 GNUNET_assert (fd >= 0); 1604 GNUNET_assert (fd >= 0);
1572 return add_without_sets (delay, -1, fd, task, task_cls); 1605 return add_without_sets (delay,
1606 GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1607 -1, fd, task, task_cls);
1573 1608
1574#endif 1609#endif
1575} 1610}