Changeset 10385


Ignore:
Timestamp:
Aug 7, 2008, 9:59:35 PM (11 years ago)
Author:
gb
Message:

Remove some old/experimental conditionalization, making some of this
easier to read.

In resume_tcr(), don't try to raise a resume semaphore that may
not exist.

Location:
trunk/source/lisp-kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/lisp-exceptions.h

    r8547 r10385  
    140140exception_fn_name( ExceptionInformation *, int, char *, size_t );
    141141
    142 /* Need to define this here */
    143 #ifdef DARWIN
    144 #define USE_MACH_EXCEPTION_LOCK 0
    145 #endif
    146142
    147143
  • trunk/source/lisp-kernel/ppc-exceptions.c

    r9905 r10385  
    22672267
    22682268
    2269 #if USE_MACH_EXCEPTION_LOCK
    2270 pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
    2271 #endif
    22722269
    22732270#define LISP_EXCEPTIONS_HANDLED_MASK \
     
    26932690#endif
    26942691
    2695   if (
    2696 #if USE_MACH_EXCEPTION_LOCK
    2697     pthread_mutex_trylock(mach_exception_lock) == 0
    2698 #else
    2699     1
    2700 #endif
    2701     ) {
    2702     if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
    2703       CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2704     }
    2705     if ((exception == EXC_BAD_INSTRUCTION) &&
    2706         (code_vector[0] == EXC_PPC_UNIPL_INST) &&
    2707         (((code1 = code_vector[1]) == (int)pseudo_sigreturn) ||
    2708          (code1 == (int)enable_fp_exceptions) ||
    2709          (code1 == (int)disable_fp_exceptions))) {
    2710       if (code1 == (int)pseudo_sigreturn) {
    2711         kret = do_pseudo_sigreturn(thread, tcr);
     2692  if (tcr->flags & (1<<TCR_FLAG_BIT_PENDING_EXCEPTION)) {
     2693    CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
     2694  }
     2695  if ((exception == EXC_BAD_INSTRUCTION) &&
     2696      (code_vector[0] == EXC_PPC_UNIPL_INST) &&
     2697      (((code1 = code_vector[1]) == (int)pseudo_sigreturn) ||
     2698       (code1 == (int)enable_fp_exceptions) ||
     2699       (code1 == (int)disable_fp_exceptions))) {
     2700    if (code1 == (int)pseudo_sigreturn) {
     2701      kret = do_pseudo_sigreturn(thread, tcr);
    27122702#if 0
    27132703      fprintf(stderr, "Exception return in 0x%x\n",tcr);
    27142704#endif
    27152705       
    2716       } else if (code1 == (int)enable_fp_exceptions) {
    2717         kret = thread_set_fp_exceptions_enabled(thread, true);
    2718       } else kret =  thread_set_fp_exceptions_enabled(thread, false);
    2719     } else if (tcr->flags & (1<<TCR_FLAG_BIT_PROPAGATE_EXCEPTION)) {
    2720       CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
    2721       kret = 17;
    2722     } else {
    2723       switch (exception) {
    2724       case EXC_BAD_ACCESS:
    2725         signum = SIGSEGV;
    2726         break;
     2706    } else if (code1 == (int)enable_fp_exceptions) {
     2707      kret = thread_set_fp_exceptions_enabled(thread, true);
     2708    } else kret =  thread_set_fp_exceptions_enabled(thread, false);
     2709  } else if (tcr->flags & (1<<TCR_FLAG_BIT_PROPAGATE_EXCEPTION)) {
     2710    CLR_TCR_FLAG(tcr,TCR_FLAG_BIT_PROPAGATE_EXCEPTION);
     2711    kret = 17;
     2712  } else {
     2713    switch (exception) {
     2714    case EXC_BAD_ACCESS:
     2715      signum = SIGSEGV;
     2716      break;
    27272717       
    2728       case EXC_BAD_INSTRUCTION:
    2729         signum = SIGILL;
    2730         break;
     2718    case EXC_BAD_INSTRUCTION:
     2719      signum = SIGILL;
     2720      break;
    27312721     
    2732       case EXC_SOFTWARE:
    2733         if (code == EXC_PPC_TRAP) {
    2734           signum = SIGTRAP;
    2735         }
    2736         break;
     2722    case EXC_SOFTWARE:
     2723      if (code == EXC_PPC_TRAP) {
     2724        signum = SIGTRAP;
     2725      }
     2726      break;
    27372727     
    2738       case EXC_ARITHMETIC:
    2739         signum = SIGFPE;
    2740         break;
    2741 
    2742       default:
    2743         break;
    2744       }
    2745       if (signum) {
    2746         kret = setup_signal_frame(thread,
    2747                                   (void *)pseudo_signal_handler,
    2748                                   signum,
    2749                                   code,
    2750                                   tcr);
     2728    case EXC_ARITHMETIC:
     2729      signum = SIGFPE;
     2730      break;
     2731
     2732    default:
     2733      break;
     2734    }
     2735    if (signum) {
     2736      kret = setup_signal_frame(thread,
     2737                                (void *)pseudo_signal_handler,
     2738                                signum,
     2739                                code,
     2740                                tcr);
    27512741#if 0
    27522742      fprintf(stderr, "Setup pseudosignal handling in 0x%x\n",tcr);
    27532743#endif
    27542744
    2755       } else {
    2756         kret = 17;
    2757       }
    2758     }
    2759 #if USE_MACH_EXCEPTION_LOCK
    2760 #ifdef DEBUG_MACH_EXCEPTIONS
    2761     fprintf(stderr, "releasing Mach exception lock in exception thread\n");
    2762 #endif
    2763     pthread_mutex_unlock(mach_exception_lock);
    2764 #endif
    2765   } else {
    2766     SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2767 #if 0
    2768     fprintf(stderr, "deferring pending exception in 0x%x\n", tcr);
    2769 #endif
    2770     kret = 0;
    2771     if (tcr == gc_tcr) {
    2772       int i;
    2773       write(1, "exception in GC thread. Sleeping for 60 seconds\n",sizeof("exception in GC thread.  Sleeping for 60 seconds\n"));
    2774       for (i = 0; i < 60; i++) {
    2775         sleep(1);
    2776       }
    2777       _exit(EX_SOFTWARE);
    2778     }
    2779   }
     2745    } else {
     2746      kret = 17;
     2747    }
     2748  }
     2749
    27802750  return kret;
    27812751}
     
    28542824  kern_return_t kret; 
    28552825  if (__exception_port_set == MACH_PORT_NULL) {
    2856 #if USE_MACH_EXCEPTION_LOCK
    2857     mach_exception_lock = &_mach_exception_lock;
    2858     pthread_mutex_init(mach_exception_lock, NULL);
    2859 #endif
    28602826    kret = mach_port_allocate(mach_task_self(),
    28612827                              MACH_PORT_RIGHT_PORT_SET,
     
    31313097
    31323098  LOCK(lisp_global(TCR_AREA_LOCK), current);
    3133 #if USE_MACH_EXCEPTION_LOCK
    3134   pthread_mutex_lock(mach_exception_lock);
    3135 #endif
    31363099
    31373100  if (suspend_mach_thread(mach_thread)) {
     
    31613124   
    31623125  }
    3163 #if USE_MACH_EXCEPTION_LOCK
    3164   pthread_mutex_unlock(mach_exception_lock);
    3165 #endif
    31663126  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    31673127  return 0;
  • trunk/source/lisp-kernel/ppc-exceptions.h

    r9067 r10385  
    388388#include <mach/machine/thread_status.h>
    389389
    390 #if USE_MACH_EXCEPTION_LOCK
    391 pthread_mutex_t *mach_exception_lock;
    392 #endif
    393390#endif
    394391
  • trunk/source/lisp-kernel/thread_manager.c

    r10183 r10385  
    1818#include "Threads.h"
    1919
    20 /*
    21    If we suspend via signals - and if the "suspend" signal is maked
    22    in the handler for that signal - then it's not possible to suspend
    23    a thread that's still waiting to be resumed (which is what
    24    WAIT_FOR_RESUME_ACK is all about.)
    25 */
    26 #define WAIT_FOR_RESUME_ACK 0
    27 #define RESUME_VIA_RESUME_SEMAPHORE 1
    28 #define SUSPEND_RESUME_VERBOSE 0
    2920
    3021typedef struct {
     
    427418}
    428419 
    429   void
     420void
    430421suspend_resume_handler(int signo, siginfo_t *info, ExceptionInformation *context)
    431422{
     
    438429    SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_SUSPEND);
    439430  } else {
    440     if (signo == thread_suspend_signal) {
    441 #if 0
    442       sigset_t wait_for;
    443 #endif
    444 
    445       tcr->suspend_context = context;
    446 #if 0
    447       sigfillset(&wait_for);
    448 #endif
    449       SEM_RAISE(tcr->suspend);
    450 #if 0
    451       sigdelset(&wait_for, thread_resume_signal);
    452 #endif
    453 #if 1
    454 #if RESUME_VIA_RESUME_SEMAPHORE
    455       SEM_WAIT_FOREVER(tcr->resume);
    456 #if SUSPEND_RESUME_VERBOSE
    457       fprintf(stderr, "got  resume in 0x%x\n",tcr);
    458 #endif
    459       tcr->suspend_context = NULL;
    460 #else
    461       sigsuspend(&wait_for);
    462 #endif
    463 #else
    464     do {
    465       sigsuspend(&wait_for);
    466     } while (tcr->suspend_context);
    467 #endif 
    468     } else {
    469       tcr->suspend_context = NULL;
    470 #if SUSEPEND_RESUME_VERBOSE
    471       fprintf(stderr,"got  resume in in 0x%x\n",tcr);
    472 #endif
    473     }
    474 #if WAIT_FOR_RESUME_ACK
     431    tcr->suspend_context = context;
    475432    SEM_RAISE(tcr->suspend);
    476 #endif
     433    SEM_WAIT_FOREVER(tcr->resume);
     434    tcr->suspend_context = NULL;
    477435  }
    478436#ifdef DARWIN_GS_HACK
     
    13541312  pthread_t thread;
    13551313  if (suspend_count == 1) {
    1356 #if SUSPEND_RESUME_VERBOSE
    1357     fprintf(stderr,"Suspending 0x%x\n", tcr);
    1358 #endif
    1359 #ifdef DARWIN_nope
    1360     if (mach_suspend_tcr(tcr)) {
    1361       SET_TCR_FLAG(tcr,TCR_FLAG_BIT_ALT_SUSPEND);
    1362       return true;
    1363     }
    1364 #endif
    13651314    thread = (pthread_t)(tcr->osid);
    13661315    if ((thread != (pthread_t) 0) &&
     
    13891338    SEM_WAIT_FOREVER(tcr->suspend);
    13901339    tcr->flags &= ~(1<<TCR_FLAG_BIT_SUSPEND_ACK_PENDING);
    1391 #if SUSPEND_RESUME_VERBOSE
    1392     fprintf(stderr,"Suspend ack from 0x%x\n", tcr);
    1393 #endif
    1394 
    13951340  }
    13961341  return true;
     
    14071352 
    14081353  LOCK(lisp_global(TCR_AREA_LOCK),current);
    1409 #ifdef DARWIN
    1410 #if USE_MACH_EXCEPTION_LOCK
    1411   if (use_mach_exception_handling) {
    1412     pthread_mutex_lock(mach_exception_lock);
    1413   }
    1414 #endif
    1415 #endif
    14161354  suspended = suspend_tcr(tcr);
    14171355  if (suspended) {
    14181356    while (!tcr_suspend_ack(tcr));
    14191357  }
    1420 #ifdef DARWIN
    1421 #if USE_MACH_EXCEPTION_LOCK
    1422   if (use_mach_exception_handling) {
    1423     pthread_mutex_unlock(mach_exception_lock);
    1424   }
    1425 #endif
    1426 #endif
    14271358  UNLOCK(lisp_global(TCR_AREA_LOCK),current);
    14281359  return suspended;
     
    14351366  int suspend_count = atomic_decf(&(tcr->suspend_count));
    14361367  if (suspend_count == 0) {
    1437 #ifdef DARWIN
    1438     if (tcr->flags & (1<<TCR_FLAG_BIT_ALT_SUSPEND)) {
    1439 #if SUSPEND_RESUME_VERBOSE
    1440     fprintf(stderr,"Mach resume to 0x%x\n", tcr);
    1441 #endif
    1442       mach_resume_tcr(tcr);
     1368    void *s = (tcr->resume);
     1369    if (s != NULL) {
     1370      SEM_RAISE(s);
    14431371      return true;
    14441372    }
    1445 #endif
    1446 #if RESUME_VIA_RESUME_SEMAPHORE
    1447     SEM_RAISE(tcr->resume);
    1448 #else
    1449     if ((err = (pthread_kill((pthread_t)(tcr->osid), thread_resume_signal))) != 0) {
    1450       Bug(NULL, "pthread_kill returned %d on thread #x%x", err, tcr->osid);
    1451     }
    1452 #endif
    1453 #if SUSPEND_RESUME_VERBOSE
    1454     fprintf(stderr, "Sent resume to 0x%x\n", tcr);
    1455 #endif
    1456     return true;
    14571373  }
    14581374  return false;
    14591375}
    14601376
    1461 void
    1462 wait_for_resumption(TCR *tcr)
    1463 {
    1464   if (tcr->suspend_count == 0) {
    1465 #ifdef DARWIN
    1466     if (tcr->flags & (1<<TCR_FLAG_BIT_ALT_SUSPEND)) {
    1467       tcr->flags &= ~(1<<TCR_FLAG_BIT_ALT_SUSPEND);
    1468       return;
    1469   }
    1470 #endif
    1471 #if WAIT_FOR_RESUME_ACK
    1472 #if SUSPEND_RESUME_VERBOSE
    1473     fprintf(stderr, "waiting for resume in 0x%x\n",tcr);
    1474 #endif
    1475     SEM_WAIT_FOREVER(tcr->suspend);
    1476 #endif
    1477   }
    1478 }
    14791377   
    14801378
     
    14881386  LOCK(lisp_global(TCR_AREA_LOCK),current);
    14891387  resumed = resume_tcr(tcr);
    1490   wait_for_resumption(tcr);
    14911388  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    14921389  return resumed;
     
    15541451
    15551452  LOCK(lisp_global(TCR_AREA_LOCK), current);
    1556 #ifdef DARWIN
    1557 #if USE_MACH_EXCEPTION_LOCK
    1558   if (for_gc && use_mach_exception_handling) {
    1559 #if SUSPEND_RESUME_VERBOSE
    1560     fprintf(stderr, "obtaining Mach exception lock in GC thread 0x%x\n", current);
    1561 #endif
    1562     pthread_mutex_lock(mach_exception_lock);
    1563   }
    1564 #endif
    1565 #endif
    15661453  for (other = current->next; other != current; other = other->next) {
    15671454    if ((other->osid != 0)) {
     
    16041491lisp_suspend_other_threads()
    16051492{
    1606   TCR *current = get_tcr(true);
    1607   LOCK(lisp_global(TCR_AREA_LOCK),current);
    16081493  suspend_other_threads(false);
    16091494}
     
    16181503    }
    16191504  }
    1620   for (other = current->next; other != current; other = other->next) {
    1621     if ((other->osid != 0)) {
    1622       wait_for_resumption(other);
    1623     }
    1624   }
    16251505  free_freed_tcrs();
    1626 #ifdef DARWIN
    1627 #if USE_MACH_EXCEPTION_LOCK
    1628   if (for_gc && use_mach_exception_handling) {
    1629 #if SUSPEND_RESUME_VERBOSE
    1630     fprintf(stderr, "releasing Mach exception lock in GC thread 0x%x\n", current);
    1631 #endif
    1632     pthread_mutex_unlock(mach_exception_lock);
    1633   }
    1634 #endif
    1635 #endif
    1636 
    16371506  UNLOCK(lisp_global(TCR_AREA_LOCK), current);
    16381507}
     
    16411510lisp_resume_other_threads()
    16421511{
    1643   TCR *current = get_tcr(true);
    16441512  resume_other_threads(false);
    1645   UNLOCK(lisp_global(TCR_AREA_LOCK),current);
    16461513}
    16471514
  • trunk/source/lisp-kernel/x86-exceptions.c

    r10246 r10385  
    23392339#define TCR_TO_EXCEPTION_PORT(tcr) ((mach_port_t)((natural)(tcr)))
    23402340
    2341 #if USE_MACH_EXCEPTION_LOCK
    2342 pthread_mutex_t _mach_exception_lock, *mach_exception_lock;
    2343 #endif
    23442341extern void pseudo_sigreturn(void);
    23452342
     
    27752772
    27762773
    2777   if (
    2778 #if USE_MACH_EXCEPTION_LOCK
    2779       pthread_mutex_trylock(mach_exception_lock) == 0
    2780 #else
    2781       1
    2782 #endif
    2783       ) {
     2774  if (1) {
    27842775#ifdef X8664
    27852776    do {
     
    28552846      }
    28562847    }
    2857 #if USE_MACH_EXCEPTION_LOCK
    2858 #ifdef DEBUG_MACH_EXCEPTIONS
    2859     fprintf(stderr, "releasing Mach exception lock in exception thread\n");
    2860 #endif
    2861     pthread_mutex_unlock(mach_exception_lock);
    2862 #endif
    2863   } else {
    2864     SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_EXCEPTION);
    2865      
    2866 #if 0
    2867     fprintf(stderr, "deferring pending exception in 0x%x\n", tcr);
    2868 #endif
    2869     kret = KERN_SUCCESS;
    2870     if (tcr == gc_tcr) {
    2871       int i;
    2872       write(1, "exception in GC thread. Sleeping for 60 seconds\n",sizeof("exception in GC thread.  Sleeping for 60 seconds\n"));
    2873       for (i = 0; i < 60; i++) {
    2874         sleep(1);
    2875       }
    2876       _exit(EX_SOFTWARE);
    2877     }
    28782848  }
    28792849  return kret;
     
    29232893  kern_return_t kret; 
    29242894  if (__exception_port_set == MACH_PORT_NULL) {
    2925 #if USE_MACH_EXCEPTION_LOCK
    2926     mach_exception_lock = &_mach_exception_lock;
    2927     pthread_mutex_init(mach_exception_lock, NULL);
    2928 #endif
    29292895
    29302896    kret = mach_port_allocate(mach_task_self(),
Note: See TracChangeset for help on using the changeset viewer.