/*
This file is part of GNUnet
- (C) 2009-2013 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2009-2013 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
*/
/**
*/
int lifeness;
+ /**
+ * Is this task in the ready list?
+ */
+ int in_ready_list;
+
#if EXECINFO
/**
* Array of strings which make up a backtrace from the point when this
enum GNUNET_SCHEDULER_Priority p = check_priority (task->priority);
if (0 != (task->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- p = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
+ p = task->priority = GNUNET_SCHEDULER_PRIORITY_SHUTDOWN;
GNUNET_CONTAINER_DLL_insert (ready_head[p],
ready_tail[p],
task);
+ task->in_ready_list = GNUNET_YES;
ready_count++;
}
if ((0 != (tc.reason & GNUNET_SCHEDULER_REASON_WRITE_READY)) &&
(-1 != pos->write_fd) &&
(!GNUNET_NETWORK_fdset_test_native (ws, pos->write_fd)))
- GNUNET_abort (); // added to ready in previous select loop!
+ GNUNET_assert (0); // added to ready in previous select loop!
LOG (GNUNET_ERROR_TYPE_DEBUG,
"Running task: %p\n",
pos);
unsigned int i;
for (i = 0; i < pos->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Task %llu trace %u: %s\n",
- pos->id,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Task %p trace %u: %s\n",
+ pos,
i,
pos->backtrace_strings[i]);
#endif
#endif
current_priority = GNUNET_SCHEDULER_PRIORITY_DEFAULT;
current_lifeness = GNUNET_YES;
- GNUNET_SCHEDULER_add_continuation (task,
- task_cls,
- GNUNET_SCHEDULER_REASON_STARTUP);
+ GNUNET_SCHEDULER_add_with_reason_and_priority (task,
+ task_cls,
+ GNUNET_SCHEDULER_REASON_STARTUP,
+ GNUNET_SCHEDULER_PRIORITY_DEFAULT);
active_task = (void *) (long) -1; /* force passing of sanity check */
GNUNET_SCHEDULER_add_now_with_lifeness (GNUNET_NO,
&GNUNET_OS_install_parent_control_handler,
timeout = GNUNET_TIME_UNIT_ZERO;
}
if (NULL == scheduler_select)
- ret = GNUNET_NETWORK_socket_select (rs, ws, NULL, timeout);
+ ret = GNUNET_NETWORK_socket_select (rs,
+ ws,
+ NULL,
+ timeout);
else
- ret = scheduler_select (scheduler_select_cls, rs, ws, NULL, timeout);
+ ret = scheduler_select (scheduler_select_cls,
+ rs,
+ ws,
+ NULL,
+ timeout);
if (ret == GNUNET_SYSERR)
{
if (errno == EINTR)
"system");
#endif
#endif
- GNUNET_abort ();
+#if DEBUG_FDS
+ struct GNUNET_SCHEDULER_Task *t;
+
+ for (t = pending_head; NULL != t; t = t->next)
+ {
+ if (-1 != t->read_fd)
+ {
+ int flags = fcntl (t->read_fd, F_GETFD);
+ if ((flags == -1) && (errno == EBADF))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Got invalid file descriptor %d!\n",
+ t->read_fd);
+#if EXECINFO
+ unsigned int i;
+
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Trace: %s\n",
+ t->backtrace_strings[i]);
+#endif
+ }
+ }
+ if (-1 != t->write_fd)
+ {
+ int flags = fcntl (t->write_fd, F_GETFD);
+ if ((flags == -1) && (errno == EBADF))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Got invalid file descriptor %d!\n",
+ t->write_fd);
+#if EXECINFO
+ unsigned int i;
+
+ for (i = 0; i < t->num_backtrace_strings; i++)
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Trace: %s\n",
+ t->backtrace_strings[i]);
+#endif
+ }
+ }
+ }
+#endif
+ GNUNET_assert (0);
break;
}
+
if ( (0 == ret) &&
(0 == timeout.rel_value_us) &&
(busy_wait_warning > 16) )
{
LOG (GNUNET_ERROR_TYPE_WARNING,
- _("Looks like we're busy waiting...\n"));
+ "Looks like we're busy waiting...\n");
short_wait (100); /* mitigate */
}
check_ready (rs, ws);
void *ret;
GNUNET_assert (NULL != active_task);
- if (GNUNET_SCHEDULER_REASON_NONE == task->reason)
+ if (! task->in_ready_list)
{
if ( (-1 == task->read_fd) &&
(-1 == task->write_fd) &&
* @param priority priority to use for the task
*/
void
-GNUNET_SCHEDULER_add_continuation_with_priority (GNUNET_SCHEDULER_TaskCallback task,
- void *task_cls,
- enum GNUNET_SCHEDULER_Reason reason,
- enum GNUNET_SCHEDULER_Priority priority)
+GNUNET_SCHEDULER_add_with_reason_and_priority (GNUNET_SCHEDULER_TaskCallback task,
+ void *task_cls,
+ enum GNUNET_SCHEDULER_Reason reason,
+ enum GNUNET_SCHEDULER_Priority priority)
{
struct GNUNET_SCHEDULER_Task *t;
}
-/**
- * Continue the current execution with the given function. This is
- * similar to the other "add" functions except that there is no delay
- * and the reason code can be specified.
- *
- * @param task main function of the task
- * @param task_cls closure for @a task
- * @param reason reason for task invocation
- */
-void
-GNUNET_SCHEDULER_add_continuation (GNUNET_SCHEDULER_TaskCallback task, void *task_cls,
- enum GNUNET_SCHEDULER_Reason reason)
-{
- GNUNET_SCHEDULER_add_continuation_with_priority (task, task_cls,
- reason,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT);
-}
-
-
/**
* Schedule a new task to be run with a specified delay. The task
* will be scheduled for execution once the delay has expired.
"Got invalid file descriptor %d!\n",
rfd);
#if EXECINFO
- int i;
+ unsigned int i;
for (i = 0; i < t->num_backtrace_strings; i++)
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_ERROR,
"Trace: %s\n",
t->backtrace_strings[i]);
#endif
"Got invalid file descriptor %d!\n",
wfd);
#if EXECINFO
- int i;
+ unsigned int i;
for (i = 0; i < t->num_backtrace_strings; i++)
LOG (GNUNET_ERROR_TYPE_DEBUG,