aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorlurchi <lurchi@strangeplace.net>2017-08-09 19:21:30 +0200
committerlurchi <lurchi@strangeplace.net>2017-08-09 19:21:38 +0200
commitb44cf84da67b78b4022009321a01376d74530685 (patch)
tree2fc99c13bb4e0d3f69e1d04ca66794715d484b33 /src
parent564ca7f14fce740e848b68bf78c358eca53d2c9e (diff)
downloadgnunet-b44cf84da67b78b4022009321a01376d74530685.tar.gz
gnunet-b44cf84da67b78b4022009321a01376d74530685.zip
lifeness checks; shutdown now working; checkSignal not passing yet
Diffstat (limited to 'src')
-rw-r--r--src/util/scheduler.c129
1 files changed, 78 insertions, 51 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index c7471ee0b..e1b6b4b51 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -583,29 +583,29 @@ 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 586static int
587//check_lifeness () 587check_lifeness ()
588//{ 588{
589// struct GNUNET_SCHEDULER_Task *t; 589 struct GNUNET_SCHEDULER_Task *t;
590// 590
591// if (ready_count > 0) 591 if (ready_count > 0)
592// return GNUNET_OK; 592 return GNUNET_OK;
593// for (t = pending_head; NULL != t; t = t->next) 593 for (t = pending_head; NULL != t; t = t->next)
594// if (t->lifeness == GNUNET_YES) 594 if (t->lifeness == GNUNET_YES)
595// return GNUNET_OK; 595 return GNUNET_OK;
596// for (t = shutdown_head; NULL != t; t = t->next) 596 for (t = shutdown_head; NULL != t; t = t->next)
597// if (t->lifeness == GNUNET_YES) 597 if (t->lifeness == GNUNET_YES)
598// return GNUNET_OK; 598 return GNUNET_OK;
599// for (t = pending_timeout_head; NULL != t; t = t->next) 599 for (t = pending_timeout_head; NULL != t; t = t->next)
600// if (t->lifeness == GNUNET_YES) 600 if (t->lifeness == GNUNET_YES)
601// return GNUNET_OK; 601 return GNUNET_OK;
602// if (NULL != shutdown_head) 602 if (NULL != shutdown_head)
603// { 603 {
604// GNUNET_SCHEDULER_shutdown (); 604 GNUNET_SCHEDULER_shutdown ();
605// return GNUNET_OK; 605 return GNUNET_OK;
606// } 606 }
607// return GNUNET_NO; 607 return GNUNET_NO;
608//} 608}
609 609
610 610
611/** 611/**
@@ -1652,7 +1652,6 @@ GNUNET_SCHEDULER_task_ready (struct GNUNET_SCHEDULER_Task *task,
1652int 1652int
1653GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh) 1653GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1654{ 1654{
1655 // FIXME: we have to check lifeness here!
1656 enum GNUNET_SCHEDULER_Priority p; 1655 enum GNUNET_SCHEDULER_Priority p;
1657 struct GNUNET_SCHEDULER_Task *pos; 1656 struct GNUNET_SCHEDULER_Task *pos;
1658 struct GNUNET_TIME_Absolute now; 1657 struct GNUNET_TIME_Absolute now;
@@ -1735,10 +1734,29 @@ GNUNET_SCHEDULER_run_from_driver (struct GNUNET_SCHEDULER_Handle *sh)
1735 destroy_task (pos); 1734 destroy_task (pos);
1736 tasks_run++; 1735 tasks_run++;
1737 } 1736 }
1738 scheduler_driver->set_wakeup (scheduler_driver->cls, 1737 if (GNUNET_NO == check_lifeness ())
1739 get_timeout ()); 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 }
1740 if (0 == ready_count) 1752 if (0 == ready_count)
1753 {
1754 scheduler_driver->set_wakeup (scheduler_driver->cls,
1755 get_timeout ());
1741 return GNUNET_NO; 1756 return GNUNET_NO;
1757 }
1758 scheduler_driver->set_wakeup (scheduler_driver->cls,
1759 GNUNET_TIME_absolute_get ());
1742 return GNUNET_OK; 1760 return GNUNET_OK;
1743} 1761}
1744 1762
@@ -1812,23 +1830,40 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
1812#endif 1830#endif
1813 1831
1814 /* Setup initial tasks */ 1832 /* 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);
1815 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT; 1850 current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
1816 current_lifeness = GNUNET_YES; 1851 current_lifeness = GNUNET_NO;
1817 memset (&tsk, 1852 memset (&tsk,
1818 0, 1853 0,
1819 sizeof (tsk)); 1854 sizeof (tsk));
1820 active_task = &tsk; 1855 active_task = &tsk;
1821 GNUNET_SCHEDULER_add_with_reason_and_priority (task, 1856 GNUNET_SCHEDULER_add_now (&GNUNET_OS_install_parent_control_handler,
1822 task_cls, 1857 NULL);
1823 GNUNET_SCHEDULER_REASON_STARTUP,
1824 GNUNET_SCHEDULER_PRIORITY_DEFAULT);
1825 GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
1826 &GNUNET_OS_install_parent_control_handler,
1827 NULL);
1828 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL, 1858 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
1829 pr, 1859 pr,
1830 &shutdown_task, 1860 &shutdown_task,
1831 NULL); 1861 NULL);
1862 current_lifeness = GNUNET_YES;
1863 GNUNET_SCHEDULER_add_with_reason_and_priority (task,
1864 task_cls,
1865 GNUNET_SCHEDULER_REASON_STARTUP,
1866 GNUNET_SCHEDULER_PRIORITY_DEFAULT);
1832 active_task = NULL; 1867 active_task = NULL;
1833 /* begin main event loop */ 1868 /* begin main event loop */
1834 sh.rs = GNUNET_NETWORK_fdset_create (); 1869 sh.rs = GNUNET_NETWORK_fdset_create ();
@@ -1837,7 +1872,7 @@ GNUNET_SCHEDULER_run_with_driver (const struct GNUNET_SCHEDULER_Driver *driver,
1837 ret = driver->loop (driver->cls, 1872 ret = driver->loop (driver->cls,
1838 &sh); 1873 &sh);
1839 LOG (GNUNET_ERROR_TYPE_WARNING, 1874 LOG (GNUNET_ERROR_TYPE_WARNING,
1840 "loop finished!"); 1875 "loop finished!\n");
1841 GNUNET_NETWORK_fdset_destroy (sh.rs); 1876 GNUNET_NETWORK_fdset_destroy (sh.rs);
1842 GNUNET_NETWORK_fdset_destroy (sh.ws); 1877 GNUNET_NETWORK_fdset_destroy (sh.ws);
1843 1878
@@ -1912,6 +1947,7 @@ select_del (void *cls,
1912 1947
1913 int ret = GNUNET_SYSERR; 1948 int ret = GNUNET_SYSERR;
1914 struct Scheduled *pos; 1949 struct Scheduled *pos;
1950 // FIXME: are multiple ORed event types allowed?
1915 switch (fdi->et) 1951 switch (fdi->et)
1916 { 1952 {
1917 case GNUNET_SCHEDULER_ET_IN: 1953 case GNUNET_SCHEDULER_ET_IN:
@@ -1952,13 +1988,6 @@ select_del (void *cls,
1952} 1988}
1953 1989
1954 1990
1955//int
1956//select_loop_condition (const struct DriverContext *context)
1957//{
1958// struct GNUNET_TIME_absolute_
1959//}
1960
1961
1962int 1991int
1963select_loop (void *cls, 1992select_loop (void *cls,
1964 struct GNUNET_SCHEDULER_Handle *sh) 1993 struct GNUNET_SCHEDULER_Handle *sh)
@@ -1976,8 +2005,7 @@ select_loop (void *cls,
1976 ws = GNUNET_NETWORK_fdset_create (); 2005 ws = GNUNET_NETWORK_fdset_create ();
1977 last_tr = 0; 2006 last_tr = 0;
1978 busy_wait_warning = 0; 2007 busy_wait_warning = 0;
1979 while ((NULL != context->scheduled_in_head) || 2008 while ((NULL != context->scheduled_in_head) || (NULL != context->scheduled_out_head))
1980 (NULL != context->scheduled_out_head))
1981 { 2009 {
1982 GNUNET_NETWORK_fdset_zero (rs); 2010 GNUNET_NETWORK_fdset_zero (rs);
1983 GNUNET_NETWORK_fdset_zero (ws); 2011 GNUNET_NETWORK_fdset_zero (ws);
@@ -1990,11 +2018,6 @@ select_loop (void *cls,
1990 { 2018 {
1991 GNUNET_NETWORK_fdset_set_native (ws, pos->fdi->sock); 2019 GNUNET_NETWORK_fdset_set_native (ws, pos->fdi->sock);
1992 } 2020 }
1993 if (ready_count > 0)
1994 {
1995 /* no blocking, more work already ready! */
1996 context->timeout = GNUNET_TIME_UNIT_ZERO;
1997 }
1998 if (NULL == scheduler_select) 2021 if (NULL == scheduler_select)
1999 { 2022 {
2000 select_result = GNUNET_NETWORK_socket_select (rs, 2023 select_result = GNUNET_NETWORK_socket_select (rs,
@@ -2071,20 +2094,20 @@ select_loop (void *cls,
2071 { 2094 {
2072 if (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, pos->fdi->sock)) 2095 if (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (rs, pos->fdi->sock))
2073 { 2096 {
2074 GNUNET_SCHEDULER_task_ready (pos->task, GNUNET_SCHEDULER_ET_IN);
2075 GNUNET_CONTAINER_DLL_remove (context->scheduled_in_head, 2097 GNUNET_CONTAINER_DLL_remove (context->scheduled_in_head,
2076 context->scheduled_in_tail, 2098 context->scheduled_in_tail,
2077 pos); 2099 pos);
2100 GNUNET_SCHEDULER_task_ready (pos->task, GNUNET_SCHEDULER_ET_IN);
2078 } 2101 }
2079 } 2102 }
2080 for (pos = context->scheduled_out_head; NULL != pos; pos = pos->next) 2103 for (pos = context->scheduled_out_head; NULL != pos; pos = pos->next)
2081 { 2104 {
2082 if (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, pos->fdi->sock)) 2105 if (GNUNET_YES == GNUNET_NETWORK_fdset_test_native (ws, pos->fdi->sock))
2083 { 2106 {
2084 GNUNET_SCHEDULER_task_ready (pos->task, GNUNET_SCHEDULER_ET_OUT);
2085 GNUNET_CONTAINER_DLL_remove (context->scheduled_out_head, 2107 GNUNET_CONTAINER_DLL_remove (context->scheduled_out_head,
2086 context->scheduled_out_tail, 2108 context->scheduled_out_tail,
2087 pos); 2109 pos);
2110 GNUNET_SCHEDULER_task_ready (pos->task, GNUNET_SCHEDULER_ET_OUT);
2088 } 2111 }
2089 } 2112 }
2090 GNUNET_SCHEDULER_run_from_driver (sh); 2113 GNUNET_SCHEDULER_run_from_driver (sh);
@@ -2098,6 +2121,10 @@ select_loop (void *cls,
2098 last_tr = tasks_run; 2121 last_tr = tasks_run;
2099 busy_wait_warning = 0; 2122 busy_wait_warning = 0;
2100 } 2123 }
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);
2101 } 2128 }
2102 return GNUNET_OK; 2129 return GNUNET_OK;
2103} 2130}