示例#1
0
int
__profil (u_short *sample_buffer, size_t size, size_t offset, u_int scale)
{
    error_t err;

    __spin_lock (&lock);

    if (scale == 0)
    {
        /* Disable profiling.  */
        int count;

        if (profile_thread != MACH_PORT_NULL)
            __thread_suspend (profile_thread);

        /* Fetch the last set of samples */
        if (sample_scale)
            fetch_samples ();

        err = __task_disable_pc_sampling (__mach_task_self (), &count);
        sample_scale = 0;
        seqno = 0;
    }
    else
        err = update_waiter (sample_buffer, size, offset, scale);

    __spin_unlock (&lock);

    return err ? __hurd_fail (err) : 0;
}
示例#2
0
error_t
hurd_thread_cancel (thread_t thread)
{
    struct hurd_sigstate *ss = _hurd_thread_sigstate (thread);
    struct machine_thread_all_state state;
    int state_change;
    error_t err;

    if (! ss)
        return EINVAL;
    if (ss == _hurd_self_sigstate ())
    {
        /* We are cancelling ourselves, so it is easy to succeed
        quickly.  Since this function is not a cancellation point, we
         just leave the flag set pending the next cancellation point
         (hurd_check_cancel or RPC) and return success.  */
        ss->cancel = 1;
        return 0;
    }

    assert (! __spin_lock_locked (&ss->critical_section_lock));
    __spin_lock (&ss->critical_section_lock);
    __spin_lock (&ss->lock);
    err = __thread_suspend (thread);
    __spin_unlock (&ss->lock);

    if (! err)
    {
        /* Set the flag telling the thread its operation is being cancelled.  */
        ss->cancel = 1;

        /* Interrupt any interruptible RPC now in progress.  */
        state.set = 0;
        _hurdsig_abort_rpcs (ss, 0, 0, &state, &state_change, NULL, 0, 0);
        if (state_change)
            err = __thread_set_state (thread, MACHINE_THREAD_STATE_FLAVOR,
                                      (natural_t *) &state.basic,
                                      MACHINE_THREAD_STATE_COUNT);

        if (ss->cancel_hook)
            /* The code being cancelled has a special wakeup function.
               Calling this should make the thread wake up and check the
               cancellation flag.  */
            (*ss->cancel_hook) ();

        __thread_resume (thread);
    }

    _hurd_critical_section_unlock (ss);
    return err;
}
int pthread_cond_wait(pthread_cond_t*cond,pthread_mutex_t*mutex) {
  _pthread_descr this=__thread_self();
  _pthread_descr*tmp;

  if (mutex->owner!=this) return EINVAL;

  __NO_ASYNC_CANCEL_BEGIN_(this);

  /* put in wait-chain */
  LOCK(cond);
  tmp=&(cond->wait_chain);
  this->waitnext=0;
  while (*tmp) tmp=&((*tmp)->waitnext);
  this->waitprev=tmp;
  *tmp=this;
  UNLOCK(cond);

  /* Aeh yeah / wait till condition-signal (or cancel) */
  pthread_mutex_unlock(mutex);

  __thread_suspend(this,1);

  pthread_mutex_lock(mutex);

  /* remove from wait-chain (if not signaled) */
  LOCK(cond);
  if (this->waitnext) {
    this->waitnext->waitprev=this->waitprev;
    *(this->waitprev)=this->waitnext;
  }
  else *(this->waitprev)=0;
  UNLOCK(cond);

  __NO_ASYNC_CANCEL_END_(this);

  return 0;
}