Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / libgc / solaris_threads.c
index 0af78055e7da66fd3cb9971546a6ff7e851f239c..e67c514c7988a59a7fea854669ac86f397405f98 100644 (file)
  */
 /* Boehm, September 14, 1994 4:44 pm PDT */
 
+# include "private/gc_priv.h"
+
 # if defined(GC_SOLARIS_THREADS) || defined(GC_SOLARIS_PTHREADS)
 
-# include "private/gc_priv.h"
+/* Avoid  #error"Cannot use procfs in the large file compilation environment" */
+#if defined(_ILP32) && (_FILE_OFFSET_BITS != 32)
+#undef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 32
+#endif
+
 # include "private/solaris_threads.h"
 # include <thread.h>
 # include <synch.h>
@@ -248,8 +255,8 @@ static void stop_all_lwps()
     for (i = 0; i < max_lwps; i++)
        last_ids[i] = 0;
     for (;;) {
-    if (syscall(SYS_ioctl, GC_main_proc_fd, PIOCSTATUS, &status) < 0)
-       ABORT("Main PIOCSTATUS failed");
+        if (syscall(SYS_ioctl, GC_main_proc_fd, PIOCSTATUS, &status) < 0)
+           ABORT("Main PIOCSTATUS failed");
        if (status.pr_nlwp < 1)
                ABORT("Invalid number of lwps returned by PIOCSTATUS");
        if (status.pr_nlwp >= max_lwps) {
@@ -262,7 +269,7 @@ static void stop_all_lwps()
                for (i = 0; i < max_lwps; i++)
                        last_ids[i] = 0;
                continue;
-    }
+       }
         if (syscall(SYS_ioctl, GC_main_proc_fd, PIOCLWPIDS, GC_current_ids) < 0)
             ABORT("PIOCLWPIDS failed");
         changed = FALSE;
@@ -635,6 +642,21 @@ int GC_thread_is_registered (void)
        return ptr ? 1 : 0;
 }
 
+void GC_allow_register_threads (void)
+{
+       /* No-op for GC pre-v7. */
+}
+
+int GC_register_my_thread (struct GC_stack_base *sb)
+{
+       /* FIXME: */
+       return GC_UNIMPLEMENTED;
+}
+
+void GC_register_altstack (void *stack, int stack_size, void *altstack, int altstack_size)
+{
+}
+
 /* Solaris 2/Intel uses an initial stack size limit slightly bigger than the
    SPARC default of 8 MB.  Account for this to warn only if the user has
    raised the limit beyond the default.
@@ -657,7 +679,7 @@ word GC_get_orig_stack_size() {
     result = (word)rl.rlim_cur & ~(HBLKSIZE-1);
     if (result > MAX_ORIG_STACK_SIZE) {
        if (!warned) {
-           WARN("Large stack limit(%ld): only scanning 8 MB\n", result);
+           /* WARN("Large stack limit(%ld): only scanning 8 MB\n", result); */
            warned = 1;
        }
        result = MAX_ORIG_STACK_SIZE;
@@ -774,18 +796,20 @@ void * GC_thr_daemon(void * dummy)
             UNLOCK();
        } else {
            t = GC_lookup_thread(departed);
-           GC_multithreaded--;
-           if (!(t -> flags & CLIENT_OWNS_STACK)) {
-               GC_stack_free(t -> stack, t -> stack_size);
-           }
-           if (t -> flags & DETACHED) {
-               GC_delete_thread(departed);
-           } else {
-               t -> status = status;
-               t -> flags |= FINISHED;
-               cond_signal(&(t -> join_cv));
-               cond_broadcast(&GC_prom_join_cv);
-           }
+                       GC_multithreaded--;
+                       if (t) {
+                               if (!(t -> flags & CLIENT_OWNS_STACK)) {
+                                       GC_stack_free(t -> stack, t -> stack_size);
+                               }
+                               if (t -> flags & DETACHED) {
+                                       GC_delete_thread(departed);
+                               } else {
+                                       t -> status = status;
+                                       t -> flags |= FINISHED;
+                                       cond_signal(&(t -> join_cv));
+                                       cond_broadcast(&GC_prom_join_cv);
+                               }
+                       }
            UNLOCK();
        }
     }
@@ -797,6 +821,7 @@ void GC_thr_init(void)
 {
     GC_thread t;
     thread_t tid;
+    int ret;
 
     if (GC_thr_initialized)
            return;
@@ -814,9 +839,11 @@ void GC_thr_init(void)
       t = GC_new_thread(thr_self());
       t -> stack_size = 0;
       t -> flags = DETACHED | CLIENT_OWNS_STACK;
-    if (thr_create(0 /* stack */, 0 /* stack_size */, GC_thr_daemon,
-                  0 /* arg */, THR_DETACHED | THR_DAEMON,
-                  &tid /* thread_id */) != 0) {
+    ret = thr_create(0 /* stack */, 0 /* stack_size */, GC_thr_daemon,
+                    0 /* arg */, THR_DETACHED | THR_DAEMON,
+                    &tid /* thread_id */);
+    if (ret != 0) {
+       GC_err_printf1("Thr_create returned %ld\n", ret);
        ABORT("Cant fork daemon");
     }
     thr_setprio(tid, 126);