1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
/***********************************************************************/
/* O'Browser */
/* */
/* Copyright 2008 Benjamin Canou. This file is distributed under the */
/* terms of the GNU Library General Public License described in file */
/* ../LICENSE. */
/* */
/***********************************************************************/
// Caml name: thread_initialize
// Type: unit -> unit
RT.thread_initialize = function () {
return UNIT;
}
// Caml name: thread_initialize_preemption
// Type: unit -> unit
RT.thread_initialize_preemption = function () {
return UNIT;
}
// Caml name: thread_new
// Type: (unit -> unit) -> t
RT.thread_new = function (clos) {
// type t = pid
return this.thread_new (clos);
}
// Caml name: thread_self
// Type: unit -> t
RT.thread_self = function (unit) {
return this.ctx.pid;
}
// Caml name: thread_kill
// Type: t -> unit
RT.thread_kill = function (pid) {
this.thread_kill (pid);
return UNIT;
}
// Caml name: thread_yield
// Type: unit -> unit
RT.thread_request_reschedule =
RT.thread_yield = function () {
this.thread_yield ();
return UNIT;
}
// Caml name: id
// Type: t -> int
RT.thread_id = function (pid) {
throw pid;
}
// Caml name: thread_sleep
// Type: unit -> unit
RT.thread_sleep = function () {
this.ctx.status = SLEEP;
return UNIT;
}
// Caml name: thread_wakeup
// Type: t -> unit
RT.thread_wakeup = function (pid) {
this.thread_wakeup (pid);
return UNIT;
}
// Caml name: thread_wait_pid, thread_join
// Type: t -> unit
RT.thread_wait_pid =
RT.thread_join = function (pid) {
this.ctx.status = WAIT;
this.ctx.waiting_for = pid;
}
// Caml name: thread_delay
// Type: float -> unit
RT.thread_delay = function (s) {
this.thread_delay (s.get (0) * 1000);
return UNIT;
}
// Caml name: thread_uncaught_exception
// Type: exn -> unit
RT.thread_uncaught_exception = function (e) {
debug ("Fatal error: " +
string_from_value (e.get(0).get(0))
+ (this.ctx.accu.size == 2
?(" " + repr (e.get (1), 1000))
:""));
this.thread_kill (this.ctx.pid);
}
// Caml name: create
// Type: unit -> t
RT.caml_js_mutex_create = function (u) {
var mutex = { locked: false, owner:0 };
return box_abstract (mutex);
}
// Caml name : lock
// Type: t -> unit
RT.caml_js_mutex_lock = function (m) {
var mutex = unbox_abstract (m);
if (mutex.locked) {
var vm = this ;
this.thread_wait (mutex, function () {
RT.caml_js_mutex_lock.call (vm, m);
});
} else {
mutex.locked = true;
mutex.owner = this.ctx.pid;
return UNIT ;
}
}
// Caml name : try_lock
// Type: t -> bool
RT.caml_js_mutex_try_lock = function (m) {
var mutex = unbox_abstract (m);
if (mutex.locked) {
return mk_bool (false) ;
} else {
mutex.locked = true;
mutex.owner = this.ctx.pid;
return mk_bool (true) ;
}
}
// Caml name: unlock
// Type: t -> unit
RT.caml_js_mutex_unlock = function (m) {
var mutex = unbox_abstract (m);
if (mutex.locked && mutex.owner == this.ctx.pid) {
mutex.locked = false;
this.thread_notify_one (mutex);
}
return UNIT;
}
|