Changeset 9983


Ignore:
Timestamp:
Jul 10, 2008, 9:51:51 AM (11 years ago)
Author:
gb
Message:

Allow natural-sized stacks.
Try to check for pthread = 0 in pthread_kill calls.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/working-0711/ccl/lisp-kernel/thread_manager.c

    r9337 r9983  
    5252#endif
    5353
     54#ifdef WINDOWS
    5455int
    5556raise_thread_interrupt(TCR *target)
    5657{
     58}
     59#else
     60int
     61raise_thread_interrupt(TCR *target)
     62{
     63  pthread_t thread = (pthread_t)target->osid;
    5764#ifdef DARWIN_not_yet
    5865  if (use_mach_exception_handling) {
     
    6067  }
    6168#endif
    62   return pthread_kill((pthread_t)target->osid, SIGNAL_FOR_PROCESS_INTERRUPT);
    63 }
     69  if (thread != (pthread_t) 0) {
     70    return pthread_kill(thread, SIGNAL_FOR_PROCESS_INTERRUPT);
     71  }
     72  return ESRCH;
     73}
     74#endif
    6475
    6576signed_natural
     
    108119      }
    109120    }
     121#ifndef WINDOWS
    110122    sched_yield();
     123#endif
    111124  }
    112125}
     
    143156
    144157static void inline
    145 lock_futex(natural *p)
     158lock_futex(signed_natural *p)
    146159{
    147160 
     
    160173
    161174static void inline
    162 unlock_futex(natural *p)
     175unlock_futex(signed_natural *p)
    163176{
    164177  if (atomic_decf(p) != FUTEX_AVAIL) {
     
    171184lock_recursive_lock(RECURSIVE_LOCK m, TCR *tcr)
    172185{
    173   natural val;
    174186  if (tcr == NULL) {
    175187    tcr = get_tcr(true);
     
    223235unlock_recursive_lock(RECURSIVE_LOCK m, TCR *tcr)
    224236{
    225   int ret = EPERM, pending;
     237  int ret = EPERM;
    226238
    227239   if (tcr == NULL) {
     
    385397
    386398 
     399#ifdef WINDOWS
    387400LispObj
    388401current_thread_osid()
    389402{
     403}
     404#else
     405LispObj
     406current_thread_osid()
     407{
    390408  return (LispObj)ptr_to_lispobj(pthread_self());
    391409}
    392 
     410#endif
    393411
    394412
     
    478496*/
    479497 
     498#ifdef WINDOWS
     499void
     500os_get_stack_bounds(LispObj q,void **base, natural *size)
     501{
     502}
     503#else
    480504void
    481505os_get_stack_bounds(LispObj q,void **base, natural *size)
     
    508532
    509533}
     534#endif
    510535
    511536void *
     
    572597}
    573598
     599#ifdef WINDOWS
    574600void
    575601tsd_set(LispObj key, void *datum)
    576602{
    577   pthread_setspecific((pthread_key_t)key, datum);
    578603}
    579604
     
    581606tsd_get(LispObj key)
    582607{
     608}
     609#else
     610void
     611tsd_set(LispObj key, void *datum)
     612{
     613  pthread_setspecific((pthread_key_t)key, datum);
     614}
     615
     616void *
     617tsd_get(LispObj key)
     618{
    583619  return pthread_getspecific((pthread_key_t)key);
    584620}
     621#endif
    585622
    586623void
     
    690727  Caller must hold the area_lock.
    691728*/
     729#ifdef WINDOWS
    692730TCR *
    693731new_tcr(natural vstack_size, natural tstack_size)
    694732{
     733}
     734#else
     735TCR *
     736new_tcr(natural vstack_size, natural tstack_size)
     737{
    695738  extern area
    696     *allocate_vstack_holding_area_lock(unsigned),
    697     *allocate_tstack_holding_area_lock(unsigned);
     739    *allocate_vstack_holding_area_lock(natural),
     740    *allocate_tstack_holding_area_lock(natural);
    698741  area *a;
    699742  int i;
     
    758801  return tcr;
    759802}
     803#endif
    760804
    761805void
     
    858902          pthread_self()
    859903#endif
     904#ifdef WINDOWS
     905          /* ThreadSelf() */ 23
     906#endif
    860907          );
    861908}
     
    921968#endif
    922969
     970#ifdef WINDOWS
    923971Ptr
    924972create_stack(int size)
     973{
     974}
     975#else
     976Ptr
     977create_stack(natural size)
    925978{
    926979  Ptr p;
    927980  size=align_to_power_of_2(size, log2_page_size);
    928981  p = (Ptr) mmap(NULL,
    929                      (size_t)size,
    930                      PROT_READ | PROT_WRITE | PROT_EXEC,
    931                      MAP_PRIVATE | MAP_ANON | MAP_GROWSDOWN,
    932                      -1,        /* Darwin insists on this when not mmap()ing
    933                                 a real fd */
    934                      0);
     982                 (size_t)size,
     983                 PROT_READ | PROT_WRITE | PROT_EXEC,
     984                 MAP_PRIVATE | MAP_ANON | MAP_GROWSDOWN,
     985                 -1,    /* Darwin insists on this when not mmap()ing
     986                          a real fd */
     987                 0);
    935988  if (p != (Ptr)(-1)) {
    936989    *((size_t *)p) = size;
     
    940993
    941994}
    942  
     995#endif
     996
    943997void *
    944 allocate_stack(unsigned size)
     998allocate_stack(natural size)
    945999{
    9461000  return create_stack(size);
    9471001}
    9481002
     1003#ifdef WINDOWS
     1004void
     1005free_stack(void *s)
     1006{
     1007}
     1008#else
    9491009void
    9501010free_stack(void *s)
     
    9531013  munmap(s, size);
    9541014}
     1015#endif
    9551016
    9561017Boolean threads_initialized = false;
    9571018
    9581019#ifndef USE_FUTEX
     1020#ifdef WINDOWS
     1021void
     1022count_cpus()
     1023{
     1024}
     1025#else
    9591026void
    9601027count_cpus()
     
    9811048}
    9821049#endif
    983 
    984 
     1050#endif
     1051
     1052#ifdef WINDOWS
     1053void
     1054init_threads(void * stack_base, TCR *tcr)
     1055{
     1056}
     1057void *
     1058lisp_thread_entry(void *param)
     1059{
     1060}
     1061#else
    9851062void
    9861063init_threads(void * stack_base, TCR *tcr)
     
    10011078{
    10021079  thread_activation *activation = (thread_activation *)param;
    1003   TCR *tcr = new_tcr(activation->vsize, activation->vsize);
     1080  TCR *tcr = new_tcr(activation->vsize, activation->tsize);
    10041081  sigset_t mask, old_mask;
    10051082
     
    10251102
    10261103}
    1027 
     1104#endif
    10281105
    10291106void *
     
    10341111{
    10351112  thread_activation activation;
    1036   TCR *current = get_tcr(false);
    10371113
    10381114
     
    10661142}
    10671143
    1068 
     1144#ifdef WINDOWS
     1145OSErr
     1146xDisposeThread(TCR *tcr)
     1147{
     1148}
     1149#else
    10691150OSErr
    10701151xDisposeThread(TCR *tcr)
     
    10781159  return -50;
    10791160}
     1161#endif
    10801162
    10811163OSErr
     
    10941176
    10951177
    1096 
     1178#ifdef WINDOWS
    10971179LispObj
    10981180create_system_thread(size_t stack_size,
     
    11011183                     void* param)
    11021184{
     1185}
     1186#else
     1187LispObj
     1188create_system_thread(size_t stack_size,
     1189                     void* stackaddr,
     1190                     void* (*start_routine)(void *),
     1191                     void* param)
     1192{
    11031193  pthread_attr_t attr;
    11041194  pthread_t returned_thread = (pthread_t) 0;
     
    11291219  return (LispObj) ptr_to_lispobj(returned_thread);
    11301220}
     1221#endif
    11311222
    11321223TCR *
     
    11511242    register_thread_tcr(current);
    11521243#ifdef DEBUG_TCR_CREATION
     1244#ifndef WINDOWS
    11531245    fprintf(stderr, "\ncreating TCR for pthread 0x%x", pthread_self());
     1246#endif
    11541247#endif
    11551248    current->vs_area->active -= node_size;
     
    11781271}
    11791272
    1180 
     1273#ifdef WINDOWS
    11811274Boolean
    11821275suspend_tcr(TCR *tcr)
    11831276{
     1277}
     1278#else
     1279Boolean
     1280suspend_tcr(TCR *tcr)
     1281{
    11841282  int suspend_count = atomic_incf(&(tcr->suspend_count));
     1283  pthread_t thread;
    11851284  if (suspend_count == 1) {
    11861285#if SUSPEND_RESUME_VERBOSE
     
    11931292    }
    11941293#endif
    1195     if (pthread_kill((pthread_t)(tcr->osid), thread_suspend_signal) == 0) {
     1294    thread = (pthread_t)(tcr->osid);
     1295    if ((thread != (pthread_t) 0) &&
     1296        (pthread_kill(thread, thread_suspend_signal) == 0)) {
    11961297      SET_TCR_FLAG(tcr,TCR_FLAG_BIT_SUSPEND_ACK_PENDING);
    11971298    } else {
     
    12091310  return false;
    12101311}
     1312#endif
    12111313
    12121314Boolean
     
    12601362resume_tcr(TCR *tcr)
    12611363{
    1262   int suspend_count = atomic_decf(&(tcr->suspend_count)), err;
     1364  int suspend_count = atomic_decf(&(tcr->suspend_count));
    12631365  if (suspend_count == 0) {
    12641366#ifdef DARWIN
     
    14771579
    14781580  void *p = calloc(1,sizeof(rwlock)+cache_block_size-1);
    1479   rwlock *rw;
     1581  rwlock *rw = NULL;;
    14801582 
    14811583  if (p) {
Note: See TracChangeset for help on using the changeset viewer.