Changeset 15738


Ignore:
Timestamp:
Feb 17, 2013, 8:41:41 AM (6 years ago)
Author:
gb
Message:

When adding a new foreign TCR on Darwin, call the undocumemted function
pthread_workqueue_setkill(1) if we can find that function. If the
thread is a "workqueue thread" (created by libdispatch in some cases),
this will make it possible to signal the thread via pthread_kill().

It's obviously not good to do this, and obviously not good to have to.

This fixes ticket:911 in the trunk.

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

Legend:

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

    r15723 r15738  
    783783}
    784784 
     785#ifdef DARWIN
     786/* Sending signals to "workqueue threads" (created via libdispatch)
     787   via pthread_kill() isn't supported, unless the thread calls an
     788   undocumented internal function.
     789
     790   Someone got paid to design this.
     791*/
     792static Boolean looked_up_setkill = false;
     793typedef int(*setkillfn)(int);
     794static setkillfn setkill = NULL;
     795
     796void
     797try_enable_kill()
     798{
     799  if (!looked_up_setkill) {
     800    setkill = dlsym(RTLD_DEFAULT,"__pthread_workqueue_setkill");
     801    looked_up_setkill = true;
     802  }
     803  if (setkill) {
     804    setkill(1);
     805  }
     806}
     807#endif
     808
    785809void
    786810enqueue_tcr(TCR *new)
     
    789813 
    790814  LOCK(lisp_global(TCR_AREA_LOCK),new);
     815#ifdef DARWIN
     816  if (new->flags & (1<<TCR_FLAG_BIT_FOREIGN)) {
     817    try_enable_kill();
     818  }
     819#endif
    791820  head = (TCR *)ptr_from_lispobj(lisp_global(INITIAL_TCR));
    792821  tail = TCR_AUX(head)->prev;
  • trunk/source/lisp-kernel/threads.h

    r15473 r15738  
    2525#ifndef WINDOWS
    2626#include <pthread.h>
     27#include <dlfcn.h>
    2728#endif
    2829#ifdef WINDOWS
Note: See TracChangeset for help on using the changeset viewer.