0.9.0.8:
[sbcl.git] / src / runtime / thread.c
index 2a174d6..32dad36 100644 (file)
@@ -28,12 +28,16 @@ int dynamic_values_bytes=4096*sizeof(lispobj);      /* same for all threads */
 struct thread *all_threads;
 volatile lispobj all_threads_lock;
 extern struct interrupt_data * global_interrupt_data;
+extern int linux_no_threads_p;
 
 int
 initial_thread_trampoline(struct thread *th)
 {
     lispobj function;
+#if defined(LISP_FEATURE_X86) || defined(LISP_FEATURE_X86_64)
     lispobj *args = NULL;
+#endif
+
     function = th->unbound_marker;
     th->unbound_marker = UNBOUND_MARKER_WIDETAG;
     if(arch_os_thread_init(th)==0) return 1;
@@ -88,16 +92,15 @@ struct thread * create_thread_struct(lispobj initial_function) {
                       BINDING_STACK_SIZE+
                       ALIEN_STACK_SIZE+
                       dynamic_values_bytes+
-                      32*SIGSTKSZ
-                      );
-    if(!spaces) goto cleanup;
+                      32*SIGSTKSZ);
+    if(!spaces)
+        return NULL;
     per_thread=(union per_thread_data *)
        (spaces+
         THREAD_CONTROL_STACK_SIZE+
         BINDING_STACK_SIZE+
         ALIEN_STACK_SIZE);
 
-    th=&per_thread->thread;
     if(all_threads) {
        memcpy(per_thread,arch_os_get_current_thread(),
               dynamic_values_bytes);
@@ -129,6 +132,7 @@ struct thread * create_thread_struct(lispobj initial_function) {
 #endif
     }
 
+    th=&per_thread->thread;
     th->control_stack_start = spaces;
     th->binding_stack_start=
        (lispobj*)((void*)th->control_stack_start+THREAD_CONTROL_STACK_SIZE);
@@ -179,7 +183,8 @@ struct thread * create_thread_struct(lispobj initial_function) {
     bind_variable(INTERRUPT_PENDING, NIL,th);
     bind_variable(INTERRUPTS_ENABLED,T,th);
 
-    th->interrupt_data=os_validate(0,(sizeof (struct interrupt_data)));
+    th->interrupt_data =
+       os_validate(0,(sizeof (struct interrupt_data)));
     if(all_threads) 
        memcpy(th->interrupt_data,
               arch_os_get_current_thread()->interrupt_data,
@@ -190,12 +195,6 @@ struct thread * create_thread_struct(lispobj initial_function) {
 
     th->unbound_marker=initial_function;
     return th;
- cleanup:
-    /* if(th && th->tls_cookie>=0) os_free_tls_pointer(th); */
-    if(spaces) os_invalidate(spaces,
-                            THREAD_CONTROL_STACK_SIZE+BINDING_STACK_SIZE+
-                            ALIEN_STACK_SIZE+dynamic_values_bytes);
-    return 0;
 }
 
 void link_thread(struct thread *th,pid_t kid_pid)
@@ -229,13 +228,15 @@ void create_initial_thread(lispobj initial_function) {
 
 #ifdef LISP_FEATURE_SB_THREAD
 pid_t create_thread(lispobj initial_function) {
-    struct thread *th=create_thread_struct(initial_function);
+    struct thread *th;
     pid_t kid_pid=0;
 
+    if(linux_no_threads_p) return 0;
+    th=create_thread_struct(initial_function);
     if(th==0) return 0;
     kid_pid=clone(new_thread_trampoline,
                  (((void*)th->control_stack_start)+
-                  THREAD_CONTROL_STACK_SIZE-4),
+                  THREAD_CONTROL_STACK_SIZE-16),
                  CLONE_FILES|SIG_THREAD_EXIT|CLONE_VM,th);
     
     if(kid_pid>0) {
@@ -252,32 +253,6 @@ pid_t create_thread(lispobj initial_function) {
 }
 #endif
 
-/* unused */
-void destroy_thread (struct thread *th)
-{
-    /* precondition: the unix task has already been killed and exited.
-     * This is called by the parent or some other thread */
-#ifdef LISP_FEATURE_GENCGC
-    gc_alloc_update_page_tables(0, &th->alloc_region);
-#endif
-    get_spinlock(&all_threads_lock,th->pid);
-    th->unbound_marker=0;      /* for debugging */
-    if(th==all_threads) 
-       all_threads=th->next;
-    else {
-       struct thread *th1=all_threads;
-       while(th1 && th1->next!=th) th1=th1->next;
-       if(th1) th1->next=th->next;     /* unlink */
-    }
-    release_spinlock(&all_threads_lock);
-    if(th && th->tls_cookie>=0) arch_os_thread_cleanup(th); 
-    os_invalidate((os_vm_address_t) th->control_stack_start,
-                 ((sizeof (lispobj))
-                  * (th->control_stack_end-th->control_stack_start)) +
-                 BINDING_STACK_SIZE+ALIEN_STACK_SIZE+dynamic_values_bytes+
-                 32*SIGSTKSZ);
-}
-
 struct thread *find_thread_by_pid(pid_t pid) 
 {
     struct thread *th;