#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-scheduler", syscall)
-#ifdef LINUX
+#if HAVE_EXECINFO_H
#include "execinfo.h"
/**
*/
GNUNET_SCHEDULER_TaskIdentifier id;
- /**
- * Identifier of a prerequisite task.
- */
- GNUNET_SCHEDULER_TaskIdentifier prereq_id;
-
/**
* Absolute timeout value for the task, or
* GNUNET_TIME_UNIT_FOREVER_ABS for "no timeout".
*/
static GNUNET_SCHEDULER_TaskIdentifier last_id;
-/**
- * Highest number so that all tasks with smaller identifiers
- * have already completed. Also the lowest number of a task
- * still waiting to be executed.
- */
-static GNUNET_SCHEDULER_TaskIdentifier lowest_pending_id;
-
/**
* Number of tasks on the ready list.
*/
}
-/**
- * Is a task with this identifier still pending? Also updates
- * "lowest_pending_id" as a side-effect (for faster checks in the
- * future), but only if the return value is "GNUNET_NO" (and
- * the "lowest_pending_id" check failed).
- *
- * @param id which task are we checking for
- * @return GNUNET_YES if so, GNUNET_NO if not
- */
-static int
-is_pending (GNUNET_SCHEDULER_TaskIdentifier id)
-{
- struct Task *pos;
- enum GNUNET_SCHEDULER_Priority p;
- GNUNET_SCHEDULER_TaskIdentifier min;
-
- if (id < lowest_pending_id)
- return GNUNET_NO;
- min = -1; /* maximum value */
- pos = pending;
- while (pos != NULL)
- {
- if (pos->id == id)
- return GNUNET_YES;
- if (pos->id < min)
- min = pos->id;
- pos = pos->next;
- }
- pos = pending_timeout;
- while (pos != NULL)
- {
- if (pos->id == id)
- return GNUNET_YES;
- if (pos->id < min)
- min = pos->id;
- pos = pos->next;
- }
- for (p = 0; p < GNUNET_SCHEDULER_PRIORITY_COUNT; p++)
- {
- pos = ready[p];
- while (pos != NULL)
- {
- if (pos->id == id)
- return GNUNET_YES;
- if (pos->id < min)
- min = pos->id;
- pos = pos->next;
- }
- }
- lowest_pending_id = min;
- return GNUNET_NO;
-}
-
-
/**
* Update all sets and timeout for select.
*
pos = pending;
while (pos != NULL)
{
- if ((pos->prereq_id != GNUNET_SCHEDULER_NO_TASK) &&
- (GNUNET_YES == is_pending (pos->prereq_id)))
- {
- pos = pos->next;
- continue;
- }
if (pos->timeout.abs_value != GNUNET_TIME_UNIT_FOREVER_ABS.abs_value)
{
to = GNUNET_TIME_absolute_get_difference (now, pos->timeout);
reason |= GNUNET_SCHEDULER_REASON_WRITE_READY;
if (reason == 0)
return GNUNET_NO; /* not ready */
- if (task->prereq_id != GNUNET_SCHEDULER_NO_TASK)
- {
- if (GNUNET_YES == is_pending (task->prereq_id))
- {
- task->reason = reason;
- return GNUNET_NO; /* prereq waiting */
- }
- reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
- }
+ reason |= GNUNET_SCHEDULER_REASON_PREREQ_DONE;
task->reason = reason;
return GNUNET_YES;
}
#if PROFILE_DELAYS
t->start_time = GNUNET_TIME_absolute_get ();
#endif
- t->prereq_id = GNUNET_SCHEDULER_NO_TASK;
t->timeout = GNUNET_TIME_relative_to_absolute (delay);
t->priority = check_priority ((priority == GNUNET_SCHEDULER_PRIORITY_KEEP) ? current_priority : priority);
t->lifeness = current_lifeness;
GNUNET_SCHEDULER_add_read_net (struct GNUNET_TIME_Relative delay,
struct GNUNET_NETWORK_Handle *rfd,
GNUNET_SCHEDULER_Task task, void *task_cls)
+{
+ return GNUNET_SCHEDULER_add_read_net_with_priority (delay,
+ GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ rfd, task, task_cls);
+}
+
+
+/**
+ * Schedule a new task to be run with a specified priority and to be
+ * run after the specified delay or when the specified file descriptor
+ * is ready for reading. The delay can be used as a timeout on the
+ * socket being ready. The task will be scheduled for execution once
+ * either the delay has expired or the socket operation is ready. It
+ * will be run with the DEFAULT priority.
+ *
+ * @param delay when should this operation time out? Use
+ * GNUNET_TIME_UNIT_FOREVER_REL for "on shutdown"
+ * @param priority priority to use for the task
+ * @param rfd read file-descriptor
+ * @param task main function of the task
+ * @param task_cls closure of task
+ * @return unique task identifier for the job
+ * only valid until "task" is started!
+ */
+GNUNET_SCHEDULER_TaskIdentifier
+GNUNET_SCHEDULER_add_read_net_with_priority (struct GNUNET_TIME_Relative delay,
+ enum GNUNET_SCHEDULER_Priority priority,
+ struct GNUNET_NETWORK_Handle *rfd,
+ GNUNET_SCHEDULER_Task task, void *task_cls)
{
#if MINGW
struct GNUNET_NETWORK_FDSet *rs;
rs = GNUNET_NETWORK_fdset_create ();
GNUNET_NETWORK_fdset_set (rs, rfd);
ret =
- GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ GNUNET_SCHEDULER_add_select (priority,
delay, rs, NULL,
task, task_cls);
GNUNET_NETWORK_fdset_destroy (rs);
return ret;
#else
return add_without_sets (delay,
- GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ priority,
GNUNET_NETWORK_get_fd (rfd), -1, task,
task_cls);
#endif
}
+
/**
* Schedule a new task to be run with a specified delay or when the
* specified file descriptor is ready for writing. The delay can be