Skip to content

Commit

Permalink
[scheduler] Sorting internal and interface functions for clearer docu…
Browse files Browse the repository at this point in the history
…mentation.

git-svn-id: https://svn.parrot.org/parrot/trunk@23979 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
  • Loading branch information
allisonrandal committed Dec 16, 2007
1 parent 8f6a381 commit 7bfdbaa
Showing 1 changed file with 86 additions and 68 deletions.
154 changes: 86 additions & 68 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ Each interpreter has a concurrency scheduler element in its core struct. The
scheduler is responsible for receiveing, dispatching, and monitoring events,
exceptions, async I/O, and concurrent tasks (threads).
=head2 Functions
=over 4
=cut
*/
Expand Down Expand Up @@ -45,6 +41,12 @@ static void* scheduler_runloop(NOTNULL(PMC *scheduler))

/*
=head2 Interface Functions
Functions that are used to interface with the concurrency scheduler.
=over 4
=item C<void
Parrot_cx_init_scheduler(PARROT_INTERP)>
Expand Down Expand Up @@ -87,70 +89,6 @@ Parrot_cx_init_scheduler(PARROT_INTERP)

/*
=item C<PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static void*
scheduler_runloop(NOTNULL(PMC *scheduler))>
The scheduler runloop is started by the interpreter. It manages the flow of
concurrent scheduling for the parent interpreter, and for lightweight
concurrent tasks running within that interpreter. More complex concurrent tasks
have their own runloop.
Currently the runloop is implented as a mutex/lock thread.
=cut
*/

PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static void*
scheduler_runloop(NOTNULL(PMC *scheduler))
{
Parrot_Scheduler * const sched_struct = PARROT_SCHEDULER(scheduler);
int running = 1;

#if CX_DEBUG
fprintf(stderr, "started scheduler runloop\n");
#endif
LOCK(sched_struct->lock);

while (running) {
/* Process pending tasks, if there are any */
if (VTABLE_get_integer(sched_struct->interp, scheduler) > 0) {
#if CX_DEBUG
fprintf(stderr, "handling tasks in scheduler runloop\n");
#endif
running = Parrot_cx_handle_tasks(sched_struct->interp, scheduler);
}
else {
/* Otherwise, the runloop sleeps until a task is pending */
#if CX_DEBUG
fprintf(stderr, "sleeping in scheduler runloop\n");
#endif
Parrot_cx_runloop_sleep(scheduler);
#if CX_DEBUG
fprintf(stderr, "waking in scheduler runloop\n");
#endif
/* LOCK(sched_struct->lock); */
}
} /* end runloop */

#if CX_DEBUG
fprintf(stderr, "ended scheduler runloop\n");
#endif

UNLOCK(sched_struct->lock);

COND_DESTROY(sched_struct->condition);
MUTEX_DESTROY(sched_struct->lock);

return NULL;
}

/*
=item C<PARROT_WARN_UNUSED_RESULT
static int
Parrot_cx_handle_tasks(PARROT_INTERP, NOTNULL(PMC *scheduler))>
Expand Down Expand Up @@ -359,6 +297,86 @@ Parrot_cx_find_handler_for_task(PARROT_INTERP, NOTNULL(PMC *task))
return handler;
}

/*
=back
=head2 Internal Functions
Functions that are only used within the scheduler.
=over 4
=item C<PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static void*
scheduler_runloop(NOTNULL(PMC *scheduler))>
The scheduler runloop is started by the interpreter. It manages the flow of
concurrent scheduling for the parent interpreter, and for lightweight
concurrent tasks running within that interpreter. More complex concurrent tasks
have their own runloop.
Currently the runloop is implented as a mutex/lock thread.
=cut
*/

PARROT_WARN_UNUSED_RESULT
PARROT_CAN_RETURN_NULL
static void*
scheduler_runloop(NOTNULL(PMC *scheduler))
{
Parrot_Scheduler * const sched_struct = PARROT_SCHEDULER(scheduler);
int running = 1;

#if CX_DEBUG
fprintf(stderr, "started scheduler runloop\n");
#endif
LOCK(sched_struct->lock);

while (running) {
/* Process pending tasks, if there are any */
if (VTABLE_get_integer(sched_struct->interp, scheduler) > 0) {
#if CX_DEBUG
fprintf(stderr, "handling tasks in scheduler runloop\n");
#endif
running = Parrot_cx_handle_tasks(sched_struct->interp, scheduler);
}
else {
/* Otherwise, the runloop sleeps until a task is pending */
#if CX_DEBUG
fprintf(stderr, "sleeping in scheduler runloop\n");
#endif
Parrot_cx_runloop_sleep(scheduler);
#if CX_DEBUG
fprintf(stderr, "waking in scheduler runloop\n");
#endif
/* LOCK(sched_struct->lock); */
}
} /* end runloop */

#if CX_DEBUG
fprintf(stderr, "ended scheduler runloop\n");
#endif

UNLOCK(sched_struct->lock);

COND_DESTROY(sched_struct->condition);
MUTEX_DESTROY(sched_struct->lock);

return NULL;
}

/*
=back
=cut
*/


/*
* Local variables:
Expand Down

0 comments on commit 7bfdbaa

Please sign in to comment.