diff options
author | lurchi <lurchi@strangeplace.net> | 2017-08-09 22:24:25 +0200 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2017-08-09 22:24:25 +0200 |
commit | 850ba0f677939b740ccff2d4dcaabe028ff5faf2 (patch) | |
tree | 9d872bdf8db47649f25d02884489876b9c86d779 /src | |
parent | b44cf84da67b78b4022009321a01376d74530685 (diff) | |
download | gnunet-850ba0f677939b740ccff2d4dcaabe028ff5faf2.tar.gz gnunet-850ba0f677939b740ccff2d4dcaabe028ff5faf2.zip |
test_scheduler passing; new API function GNUNET_SCHEDULER_check_lifeness
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_scheduler_lib.h | 15 | ||||
-rw-r--r-- | src/util/scheduler.c | 72 |
2 files changed, 30 insertions, 57 deletions
diff --git a/src/include/gnunet_scheduler_lib.h b/src/include/gnunet_scheduler_lib.h index 68a5ac534..dea0a006a 100644 --- a/src/include/gnunet_scheduler_lib.h +++ b/src/include/gnunet_scheduler_lib.h | |||
@@ -383,6 +383,21 @@ typedef int | |||
383 | 383 | ||
384 | 384 | ||
385 | /** | 385 | /** |
386 | * Check if the system has initiated shutdown. This means no tasks | ||
387 | * that prevent shutdown were present and all tasks added with | ||
388 | * #GNUNET_SCHEDULER_add_shutdown were run already. | ||
389 | * | ||
390 | * Can be used by external event loop implementations to decide | ||
391 | * whether to keep running or not. | ||
392 | * | ||
393 | * @return #GNUNET_YES if tasks which prevent shutdown exist | ||
394 | * #GNUNET_NO if the system has initiated shutdown | ||
395 | */ | ||
396 | int | ||
397 | GNUNET_SCHEDULER_check_lifeness (); | ||
398 | |||
399 | |||
400 | /** | ||
386 | * Initialize and run scheduler. This function will return when all | 401 | * Initialize and run scheduler. This function will return when all |
387 | * tasks have completed. On systems with signals, receiving a SIGTERM | 402 | * tasks have completed. On systems with signals, receiving a SIGTERM |
388 | * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown | 403 | * (and other similar signals) will cause #GNUNET_SCHEDULER_shutdown |
diff --git a/src/util/scheduler.c b/src/util/scheduler.c index e1b6b4b51..f2fdbef2b 100644 --- a/src/util/scheduler.c +++ b/src/util/scheduler.c | |||
@@ -583,8 +583,8 @@ sighandler_shutdown () | |||
583 | * @return #GNUNET_OK to continue the main loop, | 583 | * @return #GNUNET_OK to continue the main loop, |
584 | * #GNUNET_NO to exit | 584 | * #GNUNET_NO to exit |
585 | */ | 585 | */ |
586 | static int | 586 | int |
587 | check_lifeness () | 587 | GNUNET_SCHEDULER_check_lifeness () |
588 | { | 588 | { |
589 | struct GNUNET_SCHEDULER_Task *t; | 589 | struct GNUNET_SCHEDULER_Task *t; |
590 | 590 | ||
@@ -767,7 +767,7 @@ shutdown_task (void *cls) | |||
767 | { | 767 | { |
768 | char c; | 768 | char c; |
769 | const struct GNUNET_DISK_FileHandle *pr; | 769 | const struct GNUNET_DISK_FileHandle *pr; |
770 | 770 | ||
771 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, | 771 | pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, |
772 | GNUNET_DISK_PIPE_END_READ); | 772 | GNUNET_DISK_PIPE_END_READ); |
773 | GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); | 773 | GNUNET_assert (! GNUNET_DISK_handle_invalid (pr)); |
@@ -835,7 +835,7 @@ GNUNET_SCHEDULER_cancel (struct GNUNET_SCHEDULER_Task *task) | |||
835 | task); | 835 | task); |
836 | ready_count--; | 836 | ready_count--; |
837 | } | 837 | } |
838 | LOG (GNUNET_ERROR_TYPE_WARNING, | 838 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
839 | "Canceling task %p\n", | 839 | "Canceling task %p\n", |
840 | task); | 840 | task); |
841 | ret = task->callback_cls; | 841 | ret = task->callback_cls; |
@@ -897,7 +897,7 @@ GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback tas | |||
897 | t->reason = reason; | 897 | t->reason = reason; |
898 | t->priority = priority; | 898 | t->priority = priority; |
899 | t->lifeness = current_lifeness; | 899 | t->lifeness = current_lifeness; |
900 | LOG (GNUNET_ERROR_TYPE_WARNING, | 900 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
901 | "Adding continuation task %p\n", | 901 | "Adding continuation task %p\n", |
902 | t); | 902 | t); |
903 | init_backtrace (t); | 903 | init_backtrace (t); |
@@ -979,8 +979,8 @@ GNUNET_SCHEDULER_add_at_with_priority (struct GNUNET_TIME_Absolute at, | |||
979 | /* finally, update heuristic insertion point to last insertion... */ | 979 | /* finally, update heuristic insertion point to last insertion... */ |
980 | pending_timeout_last = t; | 980 | pending_timeout_last = t; |
981 | 981 | ||
982 | LOG (GNUNET_ERROR_TYPE_WARNING, | 982 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
983 | "Adding task: %p\n", | 983 | "Adding task %p\n", |
984 | t); | 984 | t); |
985 | init_backtrace (t); | 985 | init_backtrace (t); |
986 | return t; | 986 | return t; |
@@ -1136,8 +1136,8 @@ GNUNET_SCHEDULER_add_shutdown (GNUNET_SCHEDULER_TaskCallback task, | |||
1136 | GNUNET_CONTAINER_DLL_insert (shutdown_head, | 1136 | GNUNET_CONTAINER_DLL_insert (shutdown_head, |
1137 | shutdown_tail, | 1137 | shutdown_tail, |
1138 | t); | 1138 | t); |
1139 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1139 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1140 | "Adding shutdown task: %p\n", | 1140 | "Adding shutdown task %p\n", |
1141 | t); | 1141 | t); |
1142 | init_backtrace (t); | 1142 | init_backtrace (t); |
1143 | return t; | 1143 | return t; |
@@ -1582,7 +1582,7 @@ GNUNET_SCHEDULER_add_select (enum GNUNET_SCHEDULER_Priority prio, | |||
1582 | get_timeout ()); | 1582 | get_timeout ()); |
1583 | max_priority_added = GNUNET_MAX (max_priority_added, | 1583 | max_priority_added = GNUNET_MAX (max_priority_added, |
1584 | t->priority); | 1584 | t->priority); |
1585 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1585 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1586 | "Adding task %p\n", | 1586 | "Adding task %p\n", |
1587 | t); | 1587 | t); |
1588 | init_backtrace (t); | 1588 | init_backtrace (t); |
@@ -1607,10 +1607,6 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task, | |||
1607 | enum GNUNET_SCHEDULER_Reason reason; | 1607 | enum GNUNET_SCHEDULER_Reason reason; |
1608 | struct GNUNET_TIME_Absolute now; | 1608 | struct GNUNET_TIME_Absolute now; |
1609 | 1609 | ||
1610 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1611 | "task ready: %p\n", | ||
1612 | task); | ||
1613 | |||
1614 | now = GNUNET_TIME_absolute_get (); | 1610 | now = GNUNET_TIME_absolute_get (); |
1615 | reason = task->reason; | 1611 | reason = task->reason; |
1616 | if (now.abs_value_us >= task->timeout.abs_value_us) | 1612 | if (now.abs_value_us >= task->timeout.abs_value_us) |
@@ -1703,7 +1699,7 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh) | |||
1703 | if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us > | 1699 | if (GNUNET_TIME_absolute_get_duration (pos->start_time).rel_value_us > |
1704 | DELAY_THRESHOLD.rel_value_us) | 1700 | DELAY_THRESHOLD.rel_value_us) |
1705 | { | 1701 | { |
1706 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1702 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1707 | "Task %p took %s to be scheduled\n", | 1703 | "Task %p took %s to be scheduled\n", |
1708 | pos, | 1704 | pos, |
1709 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), | 1705 | GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (pos->start_time), |
@@ -1725,8 +1721,8 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh) | |||
1725 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ) | 1721 | (0 != (pos->reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) ) |
1726 | GNUNET_NETWORK_fdset_set_native (sh->ws, | 1722 | GNUNET_NETWORK_fdset_set_native (sh->ws, |
1727 | pos->write_fd); | 1723 | pos->write_fd); |
1728 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1724 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1729 | "Running task from driver: %p\n", | 1725 | "Running task %p\n", |
1730 | pos); | 1726 | pos); |
1731 | pos->callback (pos->callback_cls); | 1727 | pos->callback (pos->callback_cls); |
1732 | active_task = NULL; | 1728 | active_task = NULL; |
@@ -1734,21 +1730,6 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh) | |||
1734 | destroy_task (pos); | 1730 | destroy_task (pos); |
1735 | tasks_run++; | 1731 | tasks_run++; |
1736 | } | 1732 | } |
1737 | if (GNUNET_NO == check_lifeness ()) | ||
1738 | { | ||
1739 | /* cancel fd tasks without lifeness */ | ||
1740 | pos = pending_head; | ||
1741 | while (NULL != pos) | ||
1742 | { | ||
1743 | struct GNUNET_SCHEDULER_Task *tsk = pos; | ||
1744 | pos = pos->next; | ||
1745 | if (GNUNET_NO == tsk->lifeness) | ||
1746 | { | ||
1747 | GNUNET_SCHEDULER_cancel (tsk); | ||
1748 | } | ||
1749 | } | ||
1750 | //sighandler_shutdown(); | ||
1751 | } | ||
1752 | if (0 == ready_count) | 1733 | if (0 == ready_count) |
1753 | { | 1734 | { |
1754 | scheduler_driver->set_wakeup (scheduler_driver->cls, | 1735 | scheduler_driver->set_wakeup (scheduler_driver->cls, |
@@ -1810,7 +1791,7 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver, | |||
1810 | scheduler_driver = driver; | 1791 | scheduler_driver = driver; |
1811 | 1792 | ||
1812 | /* install signal handlers */ | 1793 | /* install signal handlers */ |
1813 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1794 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1814 | "Registering signal handlers\n"); | 1795 | "Registering signal handlers\n"); |
1815 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, | 1796 | shc_int = GNUNET_SIGNAL_handler_install (SIGINT, |
1816 | &sighandler_shutdown); | 1797 | &sighandler_shutdown); |
@@ -1830,23 +1811,6 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver, | |||
1830 | #endif | 1811 | #endif |
1831 | 1812 | ||
1832 | /* Setup initial tasks */ | 1813 | /* Setup initial tasks */ |
1833 | //current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; | ||
1834 | //current_lifeness = GNUNET_YES; | ||
1835 | //memset (&tsk, | ||
1836 | // 0, | ||
1837 | // sizeof (tsk)); | ||
1838 | //active_task = &tsk; | ||
1839 | //GNUNET_SCHEDULER_add_with_reason_and_priority (task, | ||
1840 | // task_cls, | ||
1841 | // GNUNET_SCHEDULER_REASON_STARTUP, | ||
1842 | // GNUNET_SCHEDULER_PRIORITY_DEFAULT); | ||
1843 | //GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO, | ||
1844 | // &GNUNET_OS_install_parent_control_handler, | ||
1845 | // NULL); | ||
1846 | //GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1847 | // pr, | ||
1848 | // &shutdown_task, | ||
1849 | // NULL); | ||
1850 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; | 1814 | current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; |
1851 | current_lifeness = GNUNET_NO; | 1815 | current_lifeness = GNUNET_NO; |
1852 | memset (&tsk, | 1816 | memset (&tsk, |
@@ -1871,8 +1835,6 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver, | |||
1871 | GNUNET_NETWORK_fdset_handle_set (sh.rs, pr); | 1835 | GNUNET_NETWORK_fdset_handle_set (sh.rs, pr); |
1872 | ret = driver->loop (driver->cls, | 1836 | ret = driver->loop (driver->cls, |
1873 | &sh); | 1837 | &sh); |
1874 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1875 | "loop finished!\n"); | ||
1876 | GNUNET_NETWORK_fdset_destroy (sh.rs); | 1838 | GNUNET_NETWORK_fdset_destroy (sh.rs); |
1877 | GNUNET_NETWORK_fdset_destroy (sh.ws); | 1839 | GNUNET_NETWORK_fdset_destroy (sh.ws); |
1878 | 1840 | ||
@@ -2005,7 +1967,7 @@ select_loop (void *cls, | |||
2005 | ws = GNUNET_NETWORK_fdset_create (); | 1967 | ws = GNUNET_NETWORK_fdset_create (); |
2006 | last_tr = 0; | 1968 | last_tr = 0; |
2007 | busy_wait_warning = 0; | 1969 | busy_wait_warning = 0; |
2008 | while ((NULL != context->scheduled_in_head) || (NULL != context->scheduled_out_head)) | 1970 | while (GNUNET_YES == GNUNET_SCHEDULER_check_lifeness ()) |
2009 | { | 1971 | { |
2010 | GNUNET_NETWORK_fdset_zero (rs); | 1972 | GNUNET_NETWORK_fdset_zero (rs); |
2011 | GNUNET_NETWORK_fdset_zero (ws); | 1973 | GNUNET_NETWORK_fdset_zero (ws); |
@@ -2121,10 +2083,6 @@ select_loop (void *cls, | |||
2121 | last_tr = tasks_run; | 2083 | last_tr = tasks_run; |
2122 | busy_wait_warning = 0; | 2084 | busy_wait_warning = 0; |
2123 | } | 2085 | } |
2124 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2125 | "scheduled_in_head = %p, scheduled_out_head = %p\n", | ||
2126 | context->scheduled_in_head, | ||
2127 | context->scheduled_out_head); | ||
2128 | } | 2086 | } |
2129 | return GNUNET_OK; | 2087 | return GNUNET_OK; |
2130 | } | 2088 | } |