Changeset 11742


Ignore:
Timestamp:
Feb 16, 2009, 1:51:37 PM (11 years ago)
Author:
gb
Message:

In suspend_resume_handler: if we don't have a TCR, create one (with
default stack sizes, unfortunately ...) but don't do the whole
foreign_thread_callback stuff that get_tcr(true) does.

cooperative_thread_startup(): a little different from the native
thread case. Some support for calling the (Carbon Thread Manager)
function SetThreadState?, which can be used to make the calling
cooperative thread inelegible for scheduling (until some other
thread changes its state.)

If get_tcr(true) creates a tcr, current stack size is a natural
(not unsigned.)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/lisp-kernel/thread_manager.c

    r11712 r11742  
    575575#endif
    576576  TCR *tcr = get_interrupt_tcr(false);
    577 
     577 
     578  if (tcr == NULL) {
     579    /* Got a suspend signal sent to the pthread. */
     580    extern natural initial_stack_size;
     581    void register_thread_tcr(TCR *);
     582   
     583    tcr = new_tcr(initial_stack_size, MIN_TSTACK_SIZE);
     584    tcr->suspend_count = 1;
     585    tcr->vs_area->active -= node_size;
     586    *(--tcr->save_vsp) = lisp_nil;
     587    register_thread_tcr(tcr);
     588  }
    578589  if (TCR_INTERRUPT_LEVEL(tcr) <= (-2<<fixnumshift)) {
    579590    SET_TCR_FLAG(tcr,TCR_FLAG_BIT_PENDING_SUSPEND);
     
    16791690}
    16801691
     1692typedef
     1693short (*suspendf)();
     1694
     1695
     1696void
     1697suspend_current_cooperative_thread()
     1698{
     1699  static suspendf cooperative_suspend = NULL;
     1700
     1701  if (cooperative_suspend == NULL) {
     1702    cooperative_suspend = (suspendf)xFindSymbol(NULL, "SetThreadState");
     1703  }
     1704  if (cooperative_suspend) {
     1705    cooperative_suspend(1 /* kCurrentThreadID */,
     1706                        1 /* kStoppedThreadState */,
     1707                        0 /* kAnyThreadID */);
     1708  }
     1709}
     1710
     1711void *
     1712cooperative_thread_startup(void *arg)
     1713{
     1714
     1715  TCR *tcr = get_tcr(0);
     1716  if (!tcr) {
     1717    return NULL;
     1718  }
     1719#ifndef WINDOWS
     1720  pthread_cleanup_push(tcr_cleanup,(void *)tcr);
     1721#endif
     1722  SET_TCR_FLAG(tcr,TCR_FLAG_BIT_AWAITING_PRESET);
     1723  do {
     1724    SEM_RAISE(tcr->reset_completion);
     1725    suspend_current_cooperative_thread();
     1726     
     1727    start_lisp(tcr, 0);
     1728  } while (tcr->flags & (1<<TCR_FLAG_BIT_AWAITING_PRESET));
     1729#ifndef WINDOWS
     1730  pthread_cleanup_pop(true);
     1731#else
     1732  tcr_cleanup(tcr);
     1733#endif
     1734}
     1735
    16811736void *
    16821737xNewThread(natural control_stack_size,
     
    18381893      callback_ptr = ((macptr *)ptr_from_lispobj(untag(callback_macptr)))->address;
    18391894    int i, nbindwords = 0;
    1840     extern unsigned initial_stack_size;
     1895    extern natural initial_stack_size;
    18411896   
    18421897    /* Make one. */
Note: See TracChangeset for help on using the changeset viewer.