pike.git/
src/
threads.c
Branch:
Tag:
Non-build tags
All tags
No tags
1999-12-14
1999-12-14 19:49:51 by Martin Stjernholm <mast@lysator.liu.se>
3f87be377ab7c5982f8dcfbd0751230957f85d57 (
76
lines) (+
43
/-
33
)
[
Show
|
Annotate
]
Branch:
7.9
Use global IDs for all thread programs.
Rev: src/program_id.h:1.2
Rev: src/threads.c:1.106
1:
#include "global.h"
-
RCSID("$Id: threads.c,v 1.
105
1999/12/
13
12
:
27
:
39
mast Exp $");
+
RCSID("$Id: threads.c,v 1.
106
1999/12/
14
19
:
49
:
51
mast Exp $");
int num_threads = 1; int threads_disabled = 0;
14:
#include "builtin_functions.h" #include "constants.h" #include "program.h"
+
#include "program_id.h"
#include "gc.h" #include "main.h" #include "module_support.h"
1154:
ADD_EFUN("thread_set_concurrency",f_thread_set_concurrency,tFunc(tInt,tVoid), OPT_SIDE_EFFECT); #endif
-
start
_
new
_
program
();
+
START
_
NEW
_
PROGRAM_ID
(
THREAD_MUTEX_KEY
);
mutex_key_offset = ADD_STORAGE(struct key_storage); /* This is needed to allow the gc to find the possible circular reference. * It also allows a process to take over ownership of a key.
1163:
mutex_key_offset + OFFSETOF(key_storage, owner), T_OBJECT); set_init_callback(init_mutex_key_obj); set_exit_callback(exit_mutex_key_obj);
-
mutex_key=
end
_program();
+
mutex_key=
new
_program
;
+
add_ref
(
mutex_key
);
+
end_class("mutex_key", 0);
mutex_key->flags|=PROGRAM_DESTRUCT_IMMEDIATE; #ifdef PIKE_DEBUG if(!mutex_key) fatal("Failed to initialize mutex_key program!\n"); #endif
-
start
_
new
_
program
();
+
START
_
NEW
_
PROGRAM_ID
(
THREAD_MUTEX
);
ADD_STORAGE(struct mutex_storage); /* function(int(0..2)|void:object(mutex_key)) */
-
ADD_FUNCTION
_DTYPE
("lock",f_mutex_lock,
-
dtFunc
(
dtOr
(
dtIntRange(0
,
2
),
dtVoid),dtObjInher(mutex
_
key
)
)
,0);
+
ADD_FUNCTION("lock",f_mutex_lock,
+
tFunc
(
tOr
(
tInt02
,
tVoid
),
tObjIs
_
THREAD_MUTEX_KEY
),0);
/* function(int(0..2)|void:object(mutex_key)) */
-
ADD_FUNCTION
_DTYPE
("trylock",f_mutex_trylock,
-
dtFunc
(
dtOr
(
dtIntRange(0
,
2
),
dtVoid),dtObjInher(mutex
_
key
)
)
,0);
+
ADD_FUNCTION("trylock",f_mutex_trylock,
+
tFunc
(
tOr
(
tInt02
,
tVoid
),
tObjIs
_
THREAD_MUTEX_KEY
),0);
set_init_callback(init_mutex_obj); set_exit_callback(exit_mutex_obj); end_class("mutex", 0);
-
start
_
new
_
program
();
+
START
_
NEW
_
PROGRAM_ID
(
THREAD_CONDITION
);
ADD_STORAGE(COND_T); /* function(void|object(mutex_key):void) */
-
ADD_FUNCTION
_DTYPE
("wait",f_cond_wait,
-
dtFunc
(
dtOr
(
dtVoid
,
dtObjInher(mutex
_
key
)
)
,
dtVoid
),0);
+
ADD_FUNCTION("wait",f_cond_wait,
+
tFunc
(
tOr
(
tVoid
,
tObjIs
_
THREAD_MUTEX_KEY
),
tVoid
),0);
/* function(:void) */ ADD_FUNCTION("signal",f_cond_signal,tFunc(tNone,tVoid),0); /* function(:void) */
1197:
{ struct program *tmp;
-
start
_
new
_
program
();
+
START
_
NEW
_
PROGRAM_ID
(
THREAD_DISABLE_THREADS
);
set_init_callback(init_threads_disable); set_exit_callback(exit_threads_disable);
-
tmp =
end
_program();
+
tmp =
new
_program
;
+
add_ref
(
tmp
);
+
end_class("threads_disabled", 0);
tmp->flags|=PROGRAM_DESTRUCT_IMMEDIATE; add_global_program("_disable_threads", tmp); free_program(tmp); }
-
start
_
new
_
program
();
+
START
_
NEW
_
PROGRAM_ID
(
THREAD_LOCAL
);
ADD_STORAGE(struct thread_local); /* function(:mixed) */ ADD_FUNCTION("get",f_thread_local_get,tFunc(tNone,tMix),0); /* function(mixed:mixed) */ ADD_FUNCTION("set",f_thread_local_set,tFunc(tMix,tMix),0);
-
thread_local_prog=
end
_program();
+
thread_local_prog=
new
_program
;
+
add_ref
(
thread_local_prog
);
+
end_class("thread_local", 0);
if(!thread_local_prog) fatal("Failed to initialize thread_local program!\n");
-
/* function(:object(thread_local
_prog
)) */
-
ADD_EFUN
_DTYPE
("thread_local",f_thread_local,
-
dtFunc
(
dtNone
,
dtObjInher(thread
_
local
_
prog
)
)
,
+
/* function(:object(thread_local)) */
+
ADD_EFUN("thread_local",f_thread_local,
+
tFunc
(
tNone
,
tObjIs
_
THREAD
_
LOCAL
),
OPT_SIDE_EFFECT);
-
start
_
new
_
program
();
+
START
_
NEW
_
PROGRAM_ID
(
THREAD_ID
);
thread_storage_offset=ADD_STORAGE(struct thread_state); thread_id_result_variable=simple_add_variable("result","mixed",0); /* function(:array) */
1233:
set_gc_check_callback(thread_was_checked); set_init_callback(init_thread_obj); set_exit_callback(exit_thread_obj);
-
thread_id_prog=
end
_program();
+
thread_id_prog=
new
_program
;
+
add_ref
(
thread_id_prog
);
+
end_class("thread_id", 0);
-
/* function(mixed ...:object(thread_id
_prog
)) */
-
ADD_EFUN
_DTYPE
("thread_create",f_thread_create,
-
dtFuncV
(
dtNone
,
dtMixed
,
dtObjInher(thread
_
id
_
prog
)
)
,
+
/* function(mixed ...:object(thread_id)) */
+
ADD_EFUN("thread_create",f_thread_create,
+
tFuncV
(
tNone
,
tMixed
,
tObjIs
_
THREAD
_
ID
),
OPT_SIDE_EFFECT);
-
/* function(:object(thread_id
_prog
)) */
-
ADD_EFUN
_DTYPE
("this_thread",f_this_thread,
-
dtFunc
(
dtNone
,
dtObjInher(thread
_
id
_
prog
)
)
,
+
/* function(:object(thread_id)) */
+
ADD_EFUN("this_thread",f_this_thread,
+
tFunc
(
tNone
,
tObjIs
_
THREAD
_
ID
),
OPT_EXTERNAL_DEPEND);
-
/* function(:array(object(thread_id
_prog
))) */
-
ADD_EFUN
_DTYPE
("all_threads",f_all_threads,
-
dtFunc
(
dtNone
,
dtArr
(
dtObjInher(thread
_
id
_
prog
))
)
,
+
/* function(:array(object(thread_id))) */
+
ADD_EFUN("all_threads",f_all_threads,
+
tFunc
(
tNone
,
tArr
(
tObjIs
_
THREAD
_
ID
)),
OPT_EXTERNAL_DEPEND); /* Some constants... */