• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ pthread_equal函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中pthread_equal函数的典型用法代码示例。如果您正苦于以下问题:C++ pthread_equal函数的具体用法?C++ pthread_equal怎么用?C++ pthread_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pthread_equal函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: dt_control_gdk_lock

gboolean dt_control_gdk_lock()
{
  /* if current thread equals gui thread do nothing */
  if(pthread_equal(darktable.control->gui_thread, pthread_self()) != 0) return FALSE;

  dt_pthread_mutex_lock(&_control_gdk_lock_threads_mutex);

  /* lets check if current thread has a managed lock */
  if(_control_gdk_lock_mine)
  {
    /* current thread has a lock just do nothing */
    dt_pthread_mutex_unlock(&_control_gdk_lock_threads_mutex);
    return FALSE;
  }

  /* lets lock */
  _control_gdk_lock_mine = TRUE;
  dt_pthread_mutex_unlock(&_control_gdk_lock_threads_mutex);

  /* enter gdk critical section */
  gdk_threads_enter();

  return TRUE;
}
开发者ID:powentan,项目名称:darktable,代码行数:24,代码来源:control.c


示例2: CCAssert

WebSocket::~WebSocket(){
	
	if(readyState != CLOSED){
		this->fire("close", NULL);
		this->proxy_fire("close", NULL);
		
		readyState = CLOSED;
	}
	CCAssert(!pthread_equal(m_networkThread, pthread_self()), "websocket instance should not release in sub thread!");

	pthread_mutex_lock(&m_responseQueueMutex);
	CCObject* obj;
	CCARRAY_FOREACH(m_responseMessage, obj){
		obj->release();
	}
	m_responseMessage->release();
	pthread_mutex_unlock(&m_responseQueueMutex);
	pthread_mutex_destroy(&m_responseQueueMutex);

	if(NULL != s_pool && s_pool->containsObject(this)){
		pthread_mutex_lock(&s_socketsMutex);
		s_pool->removeObject(this);
		pthread_mutex_unlock(&s_socketsMutex);
	}

	if(NULL != s_pool && s_pool->count() <= 0){
		
		pthread_mutex_lock(&s_requestQueueMutex);

		//s_requestMessageQueue->removeAllObjects();
		CCObject* obj;
		CCARRAY_FOREACH(s_requestMessageQueue, obj){
			s_requestMessageQueue->removeObject(obj);
			JsonData* msg = (JsonData*)obj;
			CC_SAFE_DELETE(msg);
		}
开发者ID:akira-cn,项目名称:cocos2dx-cqwrap,代码行数:36,代码来源:WebSocket.cpp


示例3: thread_fini

static void
thread_fini(void)
{
	kthread_t *kt = curthread;

	ASSERT(pthread_equal(kt->t_tid, pthread_self()));
	ASSERT3P(kt->t_func, ==, NULL);

	umem_free(kt, sizeof(kthread_t));

	/* Wait for all threads to exit via thread_exit() */
	VERIFY3S(pthread_mutex_lock(&kthread_lock), ==, 0);

	kthread_nr--; /* Main thread is exiting */

	while (kthread_nr > 0)
		VERIFY3S(pthread_cond_wait(&kthread_cond, &kthread_lock), ==,
		    0);

	ASSERT3S(kthread_nr, ==, 0);
	VERIFY3S(pthread_mutex_unlock(&kthread_lock), ==, 0);

	VERIFY3S(pthread_key_delete(kthread_key), ==, 0);
}
开发者ID:ChErePOdaViLka,项目名称:zfs,代码行数:24,代码来源:kernel.c


示例4: gp_monitor_leave

int
gp_monitor_leave(gp_monitor * mona)
{
    pthread_mutex_t * const mon = (pthread_mutex_t *)mona;
    int scode = 0;

#ifdef GS_RECURSIVE_MUTEXATTR
    scode = pthread_mutex_unlock(mon);
#else
    assert(((gp_pthread_recursive_t *)mona)->lcount > 0 && ((gp_pthread_recursive_t *)mona)->self_id != 0);

    if (pthread_equal(pthread_self(),((gp_pthread_recursive_t *)mona)->self_id)) {
      if ((--((gp_pthread_recursive_t *)mona)->lcount) == 0) {
          ((gp_pthread_recursive_t *)mona)->self_id = 0;	/* Not valid unless mutex is locked */
          scode = pthread_mutex_unlock(mon);

      }
    }
    else {
        scode = -1 /* should be EPERM */;
    }
#endif
    return SEM_ERROR_CODE(scode);
}
开发者ID:computersforpeace,项目名称:ghostpdl,代码行数:24,代码来源:gp_psync.c


示例5: faceproc_comp_abort

/**
 * Function: faceproc_comp_abort
 *
 * Description: Aborts the execution of faceproc
 *
 * Input parameters:
 *   handle - The pointer to the component handle.
 *   p_data - The pointer to the command structure. The structure
 *            for each command type is defined in denoise.h
 *
 * Return values:
 *     IMG_SUCCESS
 *
 * Notes: none
 **/
int faceproc_comp_abort(void *handle, void *p_data)
{
  faceproc_comp_t *p_comp = (faceproc_comp_t *)handle;
  img_component_t *p_base = (img_component_t *)handle;
  int status = IMG_SUCCESS;

  IDBG_HIGH("%s:%d] state %d", __func__, __LINE__, p_base->state);
  pthread_mutex_lock(&p_base->mutex);
  if (IMG_STATE_STARTED != p_base->state) {
    pthread_mutex_unlock(&p_base->mutex);
    return IMG_SUCCESS;
  }
  p_base->state = IMG_STATE_STOP_REQUESTED;
  pthread_mutex_unlock(&p_base->mutex);
  /*signal the thread*/
  img_q_signal(&p_base->inputQ);

  if (!pthread_equal(pthread_self(), p_base->threadid)) {
    IDBG_MED("%s:%d] thread id %d %d", __func__, __LINE__,
      (uint32_t)pthread_self(), (uint32_t)p_base->threadid);
    pthread_join(p_base->threadid, NULL);
  }

  /* destroy the handle */
  status = faceproc_comp_eng_destroy(p_comp);
  if (IMG_ERROR(status)) {
    IDBG_ERROR("%s:%d] failed", __func__, __LINE__);
    return status;
  }

  pthread_mutex_lock(&p_base->mutex);
  p_base->state = IMG_STATE_INIT;
  pthread_mutex_unlock(&p_base->mutex);
  IDBG_HIGH("%s:%d] X", __func__, __LINE__);
  return status;
}
开发者ID:tangxl0591,项目名称:camera,代码行数:51,代码来源:faceproc_comp.c


示例6: rwl_writelock_p

/*
 * Lock for write access, wait until locked (or error).
 *   Multiple nested write locking is permitted.
 */
int rwl_writelock_p(brwlock_t *rwl, const char *file, int line)
{
   int status;

   if (rwl->valid != RWLOCK_VALID) {
      return EINVAL;
   }
   if ((status = pthread_mutex_lock(&rwl->mutex)) != 0) {
      return status;
   }
   if (rwl->w_active && pthread_equal(rwl->writer_id, pthread_self())) {
      rwl->w_active++;
      pthread_mutex_unlock(&rwl->mutex);
      return 0;
   }
   lmgr_pre_lock(rwl, rwl->priority, file, line);
   if (rwl->w_active || rwl->r_active > 0) {
      rwl->w_wait++;                  /* indicate that we are waiting */
      pthread_cleanup_push(rwl_write_release, (void *)rwl);
      while (rwl->w_active || rwl->r_active > 0) {
         if ((status = pthread_cond_wait(&rwl->write, &rwl->mutex)) != 0) {
            lmgr_do_unlock(rwl);
            break;                    /* error, bail out */
         }
      }
      pthread_cleanup_pop(0);
      rwl->w_wait--;                  /* we are no longer waiting */
   }
   if (status == 0) {
      rwl->w_active++;                /* we are running */
      rwl->writer_id = pthread_self(); /* save writer thread's id */
      lmgr_post_lock();
   }
   pthread_mutex_unlock(&rwl->mutex);
   return status;
}
开发者ID:eneuhauss,项目名称:bareos,代码行数:40,代码来源:rwlock.c


示例7: mutex_abandon

static void mutex_abandon (gpointer handle, pid_t pid, pthread_t tid)
{
	struct _WapiHandle_mutex *mutex_handle;
	gboolean ok;
	int thr_ret;
	
	ok = _wapi_lookup_handle (handle, WAPI_HANDLE_MUTEX,
				  (gpointer *)&mutex_handle);
	if (ok == FALSE) {
		g_warning ("%s: error looking up mutex handle %p", __func__,
			   handle);
		return;
	}

	pthread_cleanup_push ((void(*)(void *))_wapi_handle_unlock_handle,
			      handle);
	thr_ret = _wapi_handle_lock_handle (handle);
	g_assert (thr_ret == 0);
	
	if (mutex_handle->pid == pid &&
	    pthread_equal (mutex_handle->tid, tid)) {
#ifdef DEBUG
		g_message ("%s: Mutex handle %p abandoned!", __func__, handle);
#endif

		mutex_handle->recursion = 0;
		mutex_handle->pid = 0;
		mutex_handle->tid = 0;
		
		_wapi_handle_set_signal_state (handle, TRUE, FALSE);
	}

	thr_ret = _wapi_handle_unlock_handle (handle);
	g_assert (thr_ret == 0);
	pthread_cleanup_pop (0);
}
开发者ID:Andrea,项目名称:mono,代码行数:36,代码来源:mutexes.c


示例8: _mosquitto_destroy

void _mosquitto_destroy(struct mosquitto *mosq)
{
	struct _mosquitto_packet *packet;
	if(!mosq) return;

#ifdef WITH_THREADING
	if(mosq->threaded && !pthread_equal(mosq->thread_id, pthread_self())){
		pthread_cancel(mosq->thread_id);
		pthread_join(mosq->thread_id, NULL);
		mosq->threaded = false;
	}

	if(mosq->id){
		/* If mosq->id is not NULL then the client has already been initialised
		 * and so the mutexes need destroying. If mosq->id is NULL, the mutexes
		 * haven't been initialised. */
		pthread_mutex_destroy(&mosq->callback_mutex);
		pthread_mutex_destroy(&mosq->log_callback_mutex);
		pthread_mutex_destroy(&mosq->state_mutex);
		pthread_mutex_destroy(&mosq->out_packet_mutex);
		pthread_mutex_destroy(&mosq->current_out_packet_mutex);
		pthread_mutex_destroy(&mosq->msgtime_mutex);
		pthread_mutex_destroy(&mosq->in_message_mutex);
		pthread_mutex_destroy(&mosq->out_message_mutex);
		pthread_mutex_destroy(&mosq->mid_mutex);
	}
#endif
	if(mosq->sock != INVALID_SOCKET){
		_mosquitto_socket_close(mosq);
	}
	_mosquitto_message_cleanup_all(mosq);
	_mosquitto_will_clear(mosq);
#ifdef WITH_TLS
	if(mosq->ssl){
		SSL_free(mosq->ssl);
	}
	if(mosq->ssl_ctx){
		SSL_CTX_free(mosq->ssl_ctx);
	}
	if(mosq->tls_cafile) _mosquitto_free(mosq->tls_cafile);
	if(mosq->tls_capath) _mosquitto_free(mosq->tls_capath);
	if(mosq->tls_certfile) _mosquitto_free(mosq->tls_certfile);
	if(mosq->tls_keyfile) _mosquitto_free(mosq->tls_keyfile);
	if(mosq->tls_pw_callback) mosq->tls_pw_callback = NULL;
	if(mosq->tls_version) _mosquitto_free(mosq->tls_version);
	if(mosq->tls_ciphers) _mosquitto_free(mosq->tls_ciphers);
	if(mosq->tls_psk) _mosquitto_free(mosq->tls_psk);
	if(mosq->tls_psk_identity) _mosquitto_free(mosq->tls_psk_identity);
#endif

	if(mosq->address){
		_mosquitto_free(mosq->address);
		mosq->address = NULL;
	}
	if(mosq->id){
		_mosquitto_free(mosq->id);
		mosq->id = NULL;
	}
	if(mosq->username){
		_mosquitto_free(mosq->username);
		mosq->username = NULL;
	}
	if(mosq->password){
		_mosquitto_free(mosq->password);
		mosq->password = NULL;
	}
	if(mosq->host){
		_mosquitto_free(mosq->host);
		mosq->host = NULL;
	}
	if(mosq->bind_address){
		_mosquitto_free(mosq->bind_address);
		mosq->bind_address = NULL;
	}

	/* Out packet cleanup */
	if(mosq->out_packet && !mosq->current_out_packet){
		mosq->current_out_packet = mosq->out_packet;
		mosq->out_packet = mosq->out_packet->next;
	}
	while(mosq->current_out_packet){
		packet = mosq->current_out_packet;
		/* Free data and reset values */
		mosq->current_out_packet = mosq->out_packet;
		if(mosq->out_packet){
			mosq->out_packet = mosq->out_packet->next;
		}

		_mosquitto_packet_cleanup(packet);
		_mosquitto_free(packet);
	}

	_mosquitto_packet_cleanup(&mosq->in_packet);
	if(mosq->sockpairR != INVALID_SOCKET){
		COMPAT_CLOSE(mosq->sockpairR);
		mosq->sockpairR = INVALID_SOCKET;
	}
	if(mosq->sockpairW != INVALID_SOCKET){
		COMPAT_CLOSE(mosq->sockpairW);
		mosq->sockpairW = INVALID_SOCKET;
//.........这里部分代码省略.........
开发者ID:SSSang2,项目名称:mosquittoSlave,代码行数:101,代码来源:mosquitto.c


示例9: pthread_cancel

int
pthread_cancel (pthread_t thread)
     /*
      * ------------------------------------------------------
      * DOCPUBLIC
      *      This function requests cancellation of 'thread'.
      *
      * PARAMETERS
      *      thread
      *              reference to an instance of pthread_t
      *
      *
      * DESCRIPTION
      *      This function requests cancellation of 'thread'.
      *      NOTE: cancellation is asynchronous; use pthread_join to
      *                wait for termination of 'thread' if necessary.
      *
      * RESULTS
      *              0               successfully requested cancellation,
      *              ESRCH           no thread found corresponding to 'thread',
      *              ENOMEM          implicit self thread create failed.
      * ------------------------------------------------------
      */
{
  int result;
  int cancel_self;
  pthread_t self;
  ptw32_thread_t * tp;

  result = pthread_kill (thread, 0);

  if (0 != result)
    {
      return result;
    }

  if ((self = pthread_self ()).p == NULL)
    {
      return ENOMEM;
    };

  /*
   * FIXME!!
   *
   * Can a thread cancel itself?
   *
   * The standard doesn't
   * specify an error to be returned if the target
   * thread is itself.
   *
   * If it may, then we need to ensure that a thread can't
   * deadlock itself trying to cancel itself asyncronously
   * (pthread_cancel is required to be an async-cancel
   * safe function).
   */
  cancel_self = pthread_equal (thread, self);

  tp = (ptw32_thread_t *) thread.p;

  /*
   * Lock for async-cancel safety.
   */
  (void) pthread_mutex_lock (&tp->cancelLock);

  if (tp->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
      && tp->cancelState == PTHREAD_CANCEL_ENABLE
      && tp->state < PThreadStateCanceling)
    {
      if (cancel_self)
	{
	  tp->state = PThreadStateCanceling;
	  tp->cancelState = PTHREAD_CANCEL_DISABLE;

	  (void) pthread_mutex_unlock (&tp->cancelLock);
	  ptw32_throw (PTW32_EPS_CANCEL);

	  /* Never reached */
	}
      else
	{
	  HANDLE threadH = tp->threadH;

	  SuspendThread (threadH);

	  if (WaitForSingleObject (threadH, 0) == WAIT_TIMEOUT)
	    {
	      tp->state = PThreadStateCanceling;
	      tp->cancelState = PTHREAD_CANCEL_DISABLE;
	      /*
	       * If alertdrv and QueueUserAPCEx is available then the following
	       * will result in a call to QueueUserAPCEx with the args given, otherwise
	       * this will result in a call to ptw32_RegisterCancelation and only
	       * the threadH arg will be used.
	       */
	      ptw32_register_cancelation (ptw32_cancel_callback, threadH, 0);
	      (void) pthread_mutex_unlock (&tp->cancelLock);
	      //ResumeThread (threadH);
	    }
	}
    }
//.........这里部分代码省略.........
开发者ID:CodeAsm,项目名称:ffplay360,代码行数:101,代码来源:pthread_cancel.c


示例10: pthread_equal

bool CThread::IsCurrentThread(const ThreadIdentifier tid)
{
  return pthread_equal(pthread_self(), tid);
}
开发者ID:IchabodFletchman,项目名称:xbmc,代码行数:4,代码来源:ThreadImpl.cpp


示例11: equal_systemwide_thread_id

inline bool equal_systemwide_thread_id(const OS_systemwide_thread_id_t &id1, const OS_systemwide_thread_id_t &id2)
{
   return (0 != pthread_equal(id1.tid, id2.tid)) && (id1.pid == id2.pid);
}
开发者ID:Bloodyaugust,项目名称:SugarLabCPP,代码行数:4,代码来源:os_thread_functions.hpp


示例12: need_safe_call

/// Returns true, if outside the thread.
static bool need_safe_call() { return pthread_equal(view_thread->thread, pthread_self()) == 0; }
开发者ID:B-Rich,项目名称:hermes-legacy,代码行数:2,代码来源:view_support.cpp


示例13:

	/*! Thread inequivalence operator.
	  \param that the other thread id
	  \return true if the threads are unequal */
	bool operator!=(const _threadbase& that) const { return !pthread_equal(_tid, that._tid); }
开发者ID:capitalk,项目名称:fix8,代码行数:4,代码来源:thread.hpp


示例14: EplApiProcessImageExchange

tEplKernel PUBLIC EplApiProcessImageExchange(
    tEplApiProcessImageCopyJob* pCopyJob_p)
{
    tEplKernel                      Ret = kEplSuccessful;
    tEplApiProcessImageCopyJobInt   IntCopyJob;

#if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
    if (EplApiProcessImageInstance_g.m_pCurrentTask == get_current())
#elif (TARGET_SYSTEM == _LINUX_) && !defined(__KERNEL__)
    if (pthread_equal(EplApiProcessImageInstance_g.m_currentThreadId, pthread_self()))
#elif (TARGET_SYSTEM == _WIN32_)
    if (EplApiProcessImageInstance_g.m_dwCurrentThreadId == GetCurrentThreadId())
#elif (TARGET_SYSTEM == _VXWORKS_)
    if (EplApiProcessImageInstance_g.m_currentThreadId == taskIdSelf())
#else
#error "OS currently not supported by EplApiProcessImage!"
#endif
    {
        Ret = EplApiProcessImageExchangeInt(pCopyJob_p);
        if (Ret != kEplSuccessful)
        {
            goto Exit;
        }
        goto Exit;
    }

    if ((EplApiProcessImageInstance_g.m_In.m_uiSize == 0)
            || (EplApiProcessImageInstance_g.m_Out.m_uiSize == 0))
    {   // the process image has been freed
        // therefore, indicate shutdown to application thread
        Ret = kEplShutdown;
        goto Exit;
    }

    IntCopyJob.m_CopyJob = *pCopyJob_p;

    if (pCopyJob_p->m_fNonBlocking == FALSE)
    {
        Ret = EplApiProcessImageCreateCompletion(&IntCopyJob);
        if (Ret != kEplSuccessful)
        {
            EplApiProcessImageDeleteCompletion(&IntCopyJob);
            goto Exit;
        }
    }
#if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
    else
    {
        Ret = kEplApiPINonBlockingNotSupp;
        goto Exit;
    }
#endif

#if (TARGET_SYSTEM == _LINUX_) && defined(__KERNEL__)
#endif

    Ret = EplApiProcessImagePostCopyJob(&IntCopyJob);

    if (pCopyJob_p->m_fNonBlocking == FALSE)
    {
        if (Ret == kEplSuccessful)
        {
            Ret = EplApiProcessImageWaitForCompletion(&IntCopyJob);

            if ((Ret != kEplSuccessful)
                    || (EplApiProcessImageInstance_g.m_In.m_uiSize == 0)
                    || (EplApiProcessImageInstance_g.m_Out.m_uiSize == 0))
            {   // in the mean time the process image has been freed
                // therefore, indicate shutdown to application thread
                Ret = kEplShutdown;
            }
        }

        EplApiProcessImageDeleteCompletion(&IntCopyJob);
    }

Exit:
    return Ret;
}
开发者ID:victorlp,项目名称:openPOWERLINK_systec,代码行数:79,代码来源:EplApiProcessImage.c


示例15: main

/* The main test function. */
int main( int argc, char * argv[] )
{
	int ret, i;
	pthread_t ch[ NTHREADS ];

	/* Initialize output */
	output_init();

	/* Set the signal mask */
	ret = sigemptyset( &setusr );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to empty signal set" );
	}

	ret = sigaddset( &setusr, SIGUSR1 );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "failed to add SIGUSR1 to signal set" );
	}

	ret = pthread_sigmask( SIG_BLOCK, &setusr, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to block SIGUSR1" );
	}

	/* Create the children */

	for ( i = 0; i < NTHREADS; i++ )
	{
		ret = pthread_create( &ch[ i ], NULL, threaded, NULL );

		if ( ret != 0 )
		{
			UNRESOLVED( ret, "Failed to create a thread" );
		}
	}

	/* raise the signal */
	ret = pthread_kill( ch[ 0 ], SIGUSR1 );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to raise the signal" );
	}

	sleep( 1 );

	if ( n_awaken != 1 )
	{
		output( "%d threads were awaken\n", n_awaken );
		FAILED( "Unexpected number of threads awaken" );
	}

	if ( !pthread_equal( last_awaken, ch[ 0 ] ) )
	{
		FAILED( "The awaken thread is not the signal target one." );
	}

	/* Wake other threads */
	for ( i = 1; i < NTHREADS ; i++ )
	{
		ret = pthread_kill( ch[ i ], SIGUSR1 );

		if ( ret != 0 )
		{
			UNRESOLVED( ret, "Failed to raise the signal" );
		}
	}

	/* Wait for child thread termination */
	for ( i = 0; i < NTHREADS; i++ )
	{
		ret = pthread_join( ch[ i ], NULL );

		if ( ret != 0 )
		{
			UNRESOLVED( ret, "Failed to join the thread" );
		}
	}

	/* Test passed */
#if VERBOSE > 0

	output( "Test passed\n" );

#endif

	PASSED;
}
开发者ID:chathhorn,项目名称:posixtestsuite,代码行数:95,代码来源:6-2.c


示例16: pthread_equal

	bool Host::IsMainThread()
	{
		return pthread_equal(mainThread, pthread_self());
	}
开发者ID:OnlyChristopher,项目名称:TideSDK,代码行数:4,代码来源:linux_host.cpp


示例17: pthread_equal

bool Thread::isCurrent() const
{
    return pthread_equal( pthread_self(), _id._data->pthread );
}
开发者ID:MichaelVlad,项目名称:Equalizer,代码行数:4,代码来源:thread.cpp


示例18: pthread_cancel

int
pthread_cancel (pthread_t thread)
     /*
      * ------------------------------------------------------
      * DOCPUBLIC
      *      This function requests cancellation of 'thread'.
      *
      * PARAMETERS
      *      thread
      *              reference to an instance of pthread_t
      *
      *
      * DESCRIPTION
      *      This function requests cancellation of 'thread'.
      *      NOTE: cancellation is asynchronous; use pthread_join to
      *                wait for termination of 'thread' if necessary.
      *
      * RESULTS
      *              0               successfully requested cancellation,
      *              ESRCH           no thread found corresponding to 'thread',
      *              ENOMEM          implicit self thread create failed.
      * ------------------------------------------------------
      */
{
  int result;
  int cancel_self;
  pthread_t self;

  if (thread == NULL )
    {
      return ESRCH;
    }

  result = 0;
  if ((self = pthread_self()) == NULL)
    {
      return ENOMEM;
    };

  /*
   * FIXME!!
   *
   * Can a thread cancel itself?
   *
   * The standard doesn't
   * specify an error to be returned if the target
   * thread is itself.
   *
   * If it may, then we need to ensure that a thread can't
   * deadlock itself trying to cancel itself asyncronously
   * (pthread_cancel is required to be an async-cancel
   * safe function).
   */
  cancel_self = pthread_equal(thread, self);

  /*
   * Lock for async-cancel safety.
   */
  (void) pthread_mutex_lock(&thread->cancelLock);

  if (thread->cancelType == PTHREAD_CANCEL_ASYNCHRONOUS
      && thread->cancelState == PTHREAD_CANCEL_ENABLE
      && thread->state < PThreadStateCanceling )
    {
      if (cancel_self)
        {
          thread->state = PThreadStateCanceling;
          thread->cancelState = PTHREAD_CANCEL_DISABLE;

          (void) pthread_mutex_unlock(&thread->cancelLock);
          ptw32_throw(PTW32_EPS_CANCEL);

          /* Never reached */
        }
      else
        {
          HANDLE threadH = thread->threadH;

          SuspendThread(threadH);

          if (WaitForSingleObject(threadH, 0) == WAIT_TIMEOUT )
            {
              CONTEXT context;

              thread->state = PThreadStateCanceling;
              thread->cancelState = PTHREAD_CANCEL_DISABLE;
              context.ContextFlags = CONTEXT_CONTROL;
              GetThreadContext(threadH, &context);
              PTW32_PROGCTR(context) = (DWORD) ptw32_cancel_self;
              SetThreadContext(threadH, &context);
              (void) pthread_mutex_unlock(&thread->cancelLock);
              ResumeThread(threadH);
            }
        }
    }
  else
    {
      /*
       * Set for deferred cancellation.
       */
//.........这里部分代码省略.........
开发者ID:nskipper1110,项目名称:objectivemedia,代码行数:101,代码来源:pthread_cancel.c


示例19: MUTEX_LOCK

void EHSServer::HandleData ( int inTimeoutMilliseconds, ///< milliseconds for timeout on select
							 pthread_t inThreadId ///< numeric ID for this thread to help debug
	)
{

	//fprintf ( stderr, "##### [%d] Trying to lock server mutex\n", inThreadId );

	MUTEX_LOCK ( m_oMutex );

	//fprintf ( stderr, "##### [%d] Got lock on server mutex\n", inThreadId );

	// determine if there are any jobs waiting if this thread should --
	//   if we're running one-thread-per-request and this is the accept thread
	//   we don't look for requests
	HttpRequest * poHttpRequest = NULL;
	if ( m_nServerRunningStatus != SERVERRUNNING_ONETHREADPERREQUEST ||
		 !pthread_equal(inThreadId,m_nAcceptThreadId) ) {

		poHttpRequest = GetNextRequest ( );

	}

	// if we got a request to handle
	if ( poHttpRequest != NULL ) {

		//fprintf ( stderr, "##### [%d] Got a request to handle\n", inThreadId );

		// handle the request and post it back to the connection object
		MUTEX_UNLOCK ( m_oMutex );

		// route the request
		HttpResponse * poHttpResponse = 
			m_poTopLevelEHS->RouteRequest ( poHttpRequest );

		// add the response to the appropriate connection's response list
		poHttpResponse->m_poEHSConnection->AddResponse ( poHttpResponse );

		delete poHttpRequest;

	} 
	// otherwise, no requests are pending
	else {

		// if something is already accepting, sleep
		if ( m_nAccepting ) {
			
			// wait until something happens
			// it's ok to not recheck our condition here, as we'll come back in the same way and recheck then
			//fprintf ( stderr, "##### [%d] Sleeping because no requests and someone else is accepting\n", inThreadId );

			pthread_cond_wait ( & m_oDoneAccepting,
								& m_oMutex );			

			MUTEX_UNLOCK ( m_oMutex );

		} 
		// if no one is accepting, we accept
		else {

			m_nAcceptedNewConnection = 0;
	
            
			
			//fprintf ( stderr, "Accepting\n" );

			// we're now accepting
			m_nAccepting = 1;

			MUTEX_UNLOCK ( m_oMutex );

			// create the FD set for poll
			CreateFdSet();
			int nSocketCount = poll( m_oReadFds.GetFdArray(), m_oReadFds.GetFdCount(), inTimeoutMilliseconds );

			// handle select error
#ifdef _WIN32
			if ( nSocketCount == SOCKET_ERROR )
#else // NOT _WIN32
			if ( nSocketCount == -1 )
#endif // _WIN32
			{

				EHS_TRACE ( "[%d] Critical Error: select() failed.  Aborting\n", inThreadId );

				// Idea! Remove stupid idea
				//exit ( 0 );
			}
			
			
			
			// if no sockets have data to read, clear accepting flag and return
			if ( nSocketCount > 0 ) {

				// Check the accept socket for a new connection
				CheckAcceptSocket ( );

				// check client sockets for data
				CheckClientSockets ( );

			}
//.........这里部分代码省略.........
开发者ID:Audifire,项目名称:mtasa-blue,代码行数:101,代码来源:ehs.cpp


示例20: mono_native_thread_id_equals

gboolean
mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
{
	return pthread_equal (id1, id2);
}
开发者ID:FrancisVarga,项目名称:mono,代码行数:5,代码来源:mono-threads-posix.c



注:本文中的pthread_equal函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_getattr_np函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_create函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap