]> git.jsancho.org Git - gacela.git/blob - threads.lisp
(no commit message)
[gacela.git] / threads.lisp
1 (clines "#include <pthread.h>")
2
3 (clines "#define inheap(pp) ((char *)(pp) < heap_end)")
4 (clines "static object code_for_eval_code;")
5
6 (defcfun "static object staticp (object array)" 0
7   "if (inheap (array->st.st_self)) return Ct;"
8   "else return Cnil;")
9
10 (defcfun "static void *eval_code (void *parameter)" 0
11   (eval code_for_eval_code))
12
13 (defcfun "int run_thread (object code)" 0
14   "pthread_t tid;"
15   "int ret;"
16   "code_for_eval_code = code;"
17   "ret = pthread_create (&tid, NULL, eval_code, NULL);"
18   "return ret;")
19
20 (defcfun "int runprocess (object code)" 0
21   "int pid;"
22   "pid = fork ();"
23   "if (pid == 0) {"
24   "close (0);"
25   (eval code)
26   "exit (0);"
27   "} else {"
28   "return pid;"
29   "}")
30
31 (defentry run-thread2 (object) (int "run_thread"))
32 (defentry staticp (object) (object "staticp"))
33 (defentry run-process (object) (int "runprocess"))
34
35 (defun run-thread (code)
36   (and (staticp code) (run-thread2 code)))