- gc_assert((((unsigned)current_region_free_pointer & 0x7) == 0)
- && ((nbytes & 0x7) == 0));
-
- if (SymbolValue(PSEUDO_ATOMIC_ATOMIC)) {/* if already in a pseudo atomic */
-
- void *new_free_pointer;
-
- retry1:
- if (alloc_entered) {
- SHOW("alloc re-entered in already-pseudo-atomic case");
- }
- ++alloc_entered;
-
- /* Check whether there is room in the current region. */
- new_free_pointer = current_region_free_pointer + nbytes;
-
- /* FIXME: Shouldn't we be doing some sort of lock here, to
- * keep from getting screwed if an interrupt service routine
- * allocates memory between the time we calculate new_free_pointer
- * and the time we write it back to current_region_free_pointer?
- * Perhaps I just don't understand pseudo-atomics..
- *
- * Perhaps I don't. It looks as though what happens is if we
- * were interrupted any time during the pseudo-atomic
- * interval (which includes now) we discard the allocated
- * memory and try again. So, at least we don't return
- * a memory area that was allocated out from underneath us
- * by code in an ISR.
- * Still, that doesn't seem to prevent
- * current_region_free_pointer from getting corrupted:
- * We read current_region_free_pointer.
- * They read current_region_free_pointer.
- * They write current_region_free_pointer.
- * We write current_region_free_pointer, scribbling over
- * whatever they wrote. */
-
- if (new_free_pointer <= boxed_region.end_addr) {
- /* If so then allocate from the current region. */
- void *new_obj = current_region_free_pointer;
- current_region_free_pointer = new_free_pointer;
- alloc_entered--;
- return((void *)new_obj);
- }
-
- if (auto_gc_trigger && bytes_allocated > auto_gc_trigger) {
- /* Double the trigger. */
- auto_gc_trigger *= 2;
- alloc_entered--;
- /* Exit the pseudo-atomic. */
- SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(0));
- if (SymbolValue(PSEUDO_ATOMIC_INTERRUPTED) != 0) {
- /* Handle any interrupts that occurred during
- * gc_alloc(..). */
- do_pending_interrupt();
- }
- funcall0(SymbolFunction(MAYBE_GC));
- /* Re-enter the pseudo-atomic. */
- SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(0));
- SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(1));
- goto retry1;
- }
- /* Call gc_alloc(). */
- boxed_region.free_pointer = current_region_free_pointer;
- {
- void *new_obj = gc_alloc(nbytes,0);
- current_region_free_pointer = boxed_region.free_pointer;
- current_region_end_addr = boxed_region.end_addr;
- alloc_entered--;
- return (new_obj);
- }
- } else {
- void *result;
- void *new_free_pointer;
-
- retry2:
- /* At least wrap this allocation in a pseudo atomic to prevent
- * gc_alloc() from being re-entered. */
- SetSymbolValue(PSEUDO_ATOMIC_INTERRUPTED, make_fixnum(0));
- SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(1));
-
- if (alloc_entered)
- SHOW("alloc re-entered in not-already-pseudo-atomic case");
- ++alloc_entered;
-
- /* Check whether there is room in the current region. */
- new_free_pointer = current_region_free_pointer + nbytes;
-
- if (new_free_pointer <= boxed_region.end_addr) {
- /* If so then allocate from the current region. */
- void *new_obj = current_region_free_pointer;
- current_region_free_pointer = new_free_pointer;
- alloc_entered--;
- SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(0));
- if (SymbolValue(PSEUDO_ATOMIC_INTERRUPTED)) {
- /* Handle any interrupts that occurred during
- * gc_alloc(..). */
- do_pending_interrupt();
- goto retry2;
- }
-
- return((void *)new_obj);
- }
-
- /* KLUDGE: There's lots of code around here shared with the
- * the other branch. Is there some way to factor out the
- * duplicate code? -- WHN 19991129 */
- if (auto_gc_trigger && bytes_allocated > auto_gc_trigger) {
- /* Double the trigger. */
- auto_gc_trigger *= 2;
- alloc_entered--;
- /* Exit the pseudo atomic. */
- SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(0));
- if (SymbolValue(PSEUDO_ATOMIC_INTERRUPTED) != 0) {
- /* Handle any interrupts that occurred during
- * gc_alloc(..); */
- do_pending_interrupt();
- }
- funcall0(SymbolFunction(MAYBE_GC));
- goto retry2;
- }
-
- /* Else call gc_alloc(). */
- boxed_region.free_pointer = current_region_free_pointer;
- result = gc_alloc(nbytes,0);
- current_region_free_pointer = boxed_region.free_pointer;
- current_region_end_addr = boxed_region.end_addr;
-
- alloc_entered--;
- SetSymbolValue(PSEUDO_ATOMIC_ATOMIC, make_fixnum(0));
- if (SymbolValue(PSEUDO_ATOMIC_INTERRUPTED) != 0) {
- /* Handle any interrupts that occurred during gc_alloc(..). */
- do_pending_interrupt();
- goto retry2;
+ gc_assert((((unsigned)region->free_pointer & LOWTAG_MASK) == 0)
+ && ((nbytes & LOWTAG_MASK) == 0));
+#if 0
+ if(all_threads)
+ /* there are a few places in the C code that allocate data in the
+ * heap before Lisp starts. This is before interrupts are enabled,
+ * so we don't need to check for pseudo-atomic */
+#ifdef LISP_FEATURE_SB_THREAD
+ if(!SymbolValue(PSEUDO_ATOMIC_ATOMIC,th)) {
+ register u32 fs;
+ fprintf(stderr, "fatal error in thread 0x%x, pid=%d\n",
+ th,getpid());
+ __asm__("movl %fs,%0" : "=r" (fs) : );
+ fprintf(stderr, "fs is %x, th->tls_cookie=%x \n",
+ debug_get_fs(),th->tls_cookie);
+ lose("If you see this message before 2004.01.31, mail details to sbcl-devel\n");