scheduler: ajout de tests d'initialisation.

thread.ml: type de thread_wait_pid.


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@1079 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
master
Xavier Leroy 1996-10-17 09:59:18 +00:00
parent e8aedecb1a
commit 146c843406
2 changed files with 16 additions and 3 deletions

View File

@ -403,6 +403,7 @@ static void check_callback()
value thread_yield(unit) /* ML */
value unit;
{
Assert(curr_thread != NULL);
curr_thread->retval = Val_unit;
return schedule_thread();
}
@ -412,6 +413,7 @@ value thread_yield(unit) /* ML */
value thread_sleep(unit) /* ML */
value unit;
{
Assert(curr_thread != NULL);
check_callback();
curr_thread->status = SUSPENDED;
return schedule_thread();
@ -422,6 +424,7 @@ value thread_sleep(unit) /* ML */
value thread_wait_read(fd) /* ML */
value fd;
{
if (curr_thread == NULL) return Val_unit;
check_callback();
curr_thread->status = BLOCKED_READ;
curr_thread->fd = fd;
@ -431,6 +434,7 @@ value thread_wait_read(fd) /* ML */
value thread_wait_write(fd) /* ML */
value fd;
{
if (curr_thread == NULL) return Val_unit;
check_callback();
curr_thread->status = BLOCKED_WRITE;
curr_thread->fd = fd;
@ -468,6 +472,7 @@ value thread_delay(time) /* ML */
value time;
{
double date = timeofday() + Double_val(time);
Assert(curr_thread != NULL);
check_callback();
curr_thread->status = BLOCKED_DELAY;
Assign(curr_thread->delay, copy_double(date));
@ -480,6 +485,7 @@ value thread_wait_timed_read(fd, time) /* ML */
value fd, time;
{
double date = timeofday() + Double_val(time);
Assert(curr_thread != NULL);
check_callback();
curr_thread->status = BLOCKED_READ | BLOCKED_DELAY;
curr_thread->fd = fd;
@ -491,6 +497,7 @@ value thread_wait_timed_write(fd, time) /* ML */
value fd, time;
{
double date = timeofday() + Double_val(time);
Assert(curr_thread != NULL);
check_callback();
curr_thread->status = BLOCKED_WRITE | BLOCKED_DELAY;
curr_thread->fd = fd;
@ -504,6 +511,7 @@ value thread_join(th) /* ML */
value th;
{
check_callback();
Assert(curr_thread != NULL);
if (((thread_t)th)->status == KILLED) return Val_unit;
curr_thread->status = BLOCKED_JOIN;
Assign(curr_thread->joining, th);
@ -515,6 +523,7 @@ value thread_join(th) /* ML */
value thread_wait_pid(pid) /* ML */
value pid;
{
Assert(curr_thread != NULL);
check_callback();
curr_thread->status = BLOCKED_WAIT;
curr_thread->waitpid = pid;
@ -545,6 +554,7 @@ value thread_wakeup(thread) /* ML */
value thread_self(unit) /* ML */
value unit;
{
Assert(curr_thread != NULL);
return (value) curr_thread;
}

View File

@ -46,8 +46,7 @@ external thread_wait_timed_write
= "thread_wait_timed_write"
external thread_join : t -> unit = "thread_join"
external thread_delay : float -> unit = "thread_delay"
external thread_wait_pid : int -> int * Unix.process_status
= "thread_wait_pid"
external thread_wait_pid : int -> resumption_status = "thread_wait_pid"
external thread_wakeup : t -> unit = "thread_wakeup"
external thread_self : unit -> t = "thread_self"
external thread_kill : t -> unit = "thread_kill"
@ -63,7 +62,6 @@ let wait_read fd = thread_wait_read fd
let wait_write fd = thread_wait_write fd
let delay duration = thread_delay duration
let join th = thread_join th
let wait_pid pid = thread_wait_pid pid
let wakeup pid = thread_wakeup pid
let self () = thread_self()
let kill pid = thread_kill pid
@ -71,9 +69,14 @@ let exit () = thread_kill(thread_self())
let wait_timed_read_aux fd d = thread_wait_timed_read fd d
let wait_timed_write_aux fd d = thread_wait_timed_write fd d
let wait_pid_aux pid = thread_wait_pid pid
let wait_timed_read fd d = wait_timed_read_aux fd d = Resumed_io
let wait_timed_write fd d = wait_timed_write_aux fd d = Resumed_io
let wait_pid pid =
match wait_pid_aux pid with
Resumed_wait(pid, status) -> (pid, status)
| _ -> invalid_arg "Thread.wait_pid"
(* For new, make sure the function passed to thread_new always terminates
by calling exit. *)