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

C++ pthread_getspecific函数代码示例

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

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



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

示例1: THR_GetBusyobj

struct busyobj *
THR_GetBusyobj(void)
{

	return (pthread_getspecific(bo_key));
}
开发者ID:1HLtd,项目名称:Varnish-Cache,代码行数:6,代码来源:cache_main.c


示例2: pthread_getspecific

/* get thread connections list */
struct mk_list *mk_patas_conx_get()
{
    return pthread_getspecific(_mkp_data);
}
开发者ID:f13mash,项目名称:monkey,代码行数:5,代码来源:patas.c


示例3: _res_thread_get

static _res_thread*
_res_thread_get(void)
{
    _res_thread*  rt;
    pthread_once( &_res_once, _res_init_key );
    rt = pthread_getspecific( _res_key );

    if (rt != NULL) {
        /* We already have one thread-specific DNS state object.
         * Check the serial value for any changes to net.* properties */
        D("%s: Called for tid=%d rt=%p rt->pi=%p rt->serial=%d",
           __FUNCTION__, gettid(), rt, rt->_pi, rt->_serial);
        if (rt->_pi == NULL) {
            /* The property wasn't created when _res_thread_get() was
             * called the last time. This should only happen very
             * early during the boot sequence. First, let's try to see if it
             * is here now. */
            rt->_pi = (struct prop_info*) __system_property_find("net.change");
            if (rt->_pi == NULL) {
                /* Still nothing, return current state */
                D("%s: exiting for tid=%d rt=%d since system property not found",
                  __FUNCTION__, gettid(), rt);
                return rt;
            }
        }
        if (rt->_serial == __system_property_serial(rt->_pi)) {
            /* Nothing changed, so return the current state */
            D("%s: tid=%d rt=%p nothing changed, returning",
              __FUNCTION__, gettid(), rt);
            return rt;
        }
        /* Update the recorded serial number, and go reset the state */
        rt->_serial = __system_property_serial(rt->_pi);
        goto RESET_STATE;
    }

    /* It is the first time this function is called in this thread,
     * we need to create a new thread-specific DNS resolver state. */
    rt = _res_thread_alloc();
    if (rt == NULL) {
        return NULL;
    }
    pthread_setspecific( _res_key, rt );
    D("%s: tid=%d Created new DNS state rt=%p",
      __FUNCTION__, gettid(), rt);

RESET_STATE:
    /* Reset the state, note that res_ninit() can now properly reset
     * an existing state without leaking memory.
     */
    D("%s: tid=%d, rt=%p, resetting DNS state (options RES_INIT=%d)",
      __FUNCTION__, gettid(), rt, (rt->_nres->options & RES_INIT) != 0);
    if ( res_ninit( rt->_nres ) < 0 ) {
        /* This should not happen */
        D("%s: tid=%d rt=%p, woot, res_ninit() returned < 0",
          __FUNCTION__, gettid(), rt);
        _res_thread_free(rt);
        pthread_setspecific( _res_key, NULL );
        return NULL;
    }
    return rt;
}
开发者ID:AOSP-S4,项目名称:platform_bionic,代码行数:62,代码来源:res_state.c


示例4: return

Thread* Thread::getCurrent() 
{
   return (Thread*)pthread_getspecific(ourKey);
}
开发者ID:zangel,项目名称:uquad,代码行数:4,代码来源:thread.cpp


示例5: pthread_self

pthread_t
pthread_self (void)
     /*
      * ------------------------------------------------------
      * DOCPUBLIC
      *      This function returns a reference to the current running
      *      thread.
      *
      * PARAMETERS
      *      N/A
      *
      *
      * DESCRIPTION
      *      This function returns a reference to the current running
      *      thread.
      *
      * RESULTS
      *              pthread_t       reference to the current thread
      *
      * ------------------------------------------------------
      */
{
  pthread_t self;

#ifdef _UWIN
  if (!ptw32_selfThreadKey)
    return (NULL);
#endif

  self = (pthread_t) pthread_getspecific (ptw32_selfThreadKey);

  if (self == NULL)
    {
      /*
       * Need to create an implicit 'self' for the currently
       * executing thread.
       */
      self = ptw32_new ();

      if (self != NULL)
	{
	  /*
	   * This is a non-POSIX thread which has chosen to call
	   * a POSIX threads function for some reason. We assume that
	   * it isn't joinable, but we do assume that it's
	   * (deferred) cancelable.
	   */
	  self->implicit = 1;
	  self->detachState = PTHREAD_CREATE_DETACHED;
	  self->thread = GetCurrentThreadId ();

#ifdef NEED_DUPLICATEHANDLE
	  /*
	   * DuplicateHandle does not exist on WinCE.
	   *
	   * NOTE:
	   * GetCurrentThread only returns a pseudo-handle
	   * which is only valid in the current thread context.
	   * Therefore, you should not pass the handle to
	   * other threads for whatever purpose.
	   */
	  self->threadH = GetCurrentThread ();
#else
	  if (!DuplicateHandle (GetCurrentProcess (),
				GetCurrentThread (),
				GetCurrentProcess (),
				&self->threadH,
				0, FALSE, DUPLICATE_SAME_ACCESS))
	    {
	      /* Thread structs are never freed. */
	      ptw32_threadReusePush (self);
	      return (NULL);
	    }
#endif

	  /*
	   * No need to explicitly serialise access to sched_priority
	   * because the new handle is not yet public.
	   */
	  self->sched_priority = GetThreadPriority (self->threadH);
	}

      pthread_setspecific (ptw32_selfThreadKey, self);
    }

  return (self);

}				/* pthread_self */
开发者ID:Schiiiiins,项目名称:lcu1,代码行数:88,代码来源:pthread_self.c


示例6: uv_key_get

void* uv_key_get(uv_key_t* key) {
  return pthread_getspecific(*key);
}
开发者ID:hpcc-systems,项目名称:libuv,代码行数:3,代码来源:thread.c


示例7: resetdlerror

static void resetdlerror()
{
	struct dlthread *tss;
	tss = pthread_getspecific(dlerror_key);
	tss->errset = 0;
}
开发者ID:Miguel-J,项目名称:eneboo-core,代码行数:6,代码来源:dlfcn.c


示例8: CmiGetState

CmiState CmiGetState() {
	CmiState ret;
	if (Cmi_state_key == (pthread_key_t)(-1)) return &Cmi_default_state;
	ret=(CmiState)pthread_getspecific(Cmi_state_key);
	return (ret==NULL)? &Cmi_default_state : ret;
}
开发者ID:luyukunphy,项目名称:namd,代码行数:6,代码来源:machine-smp.c


示例9: macosx_init_exception_handler

/* this initializes the subsystem (sets the exception port, starts the
   exception handling thread, etc) */
static void macosx_init_exception_handler(int isMASTERGC)
{
  kern_return_t retval;

  if (!isMASTERGC) {
    GC_attach_current_thread_exceptions_to_handler();
    return;
  }

  if(!task_self) task_self = mach_task_self();

  /* allocate the port we're going to get exceptions on */
  retval = mach_port_allocate(task_self, MACH_PORT_RIGHT_RECEIVE, &exc_port);
  if(retval != KERN_SUCCESS) {
    GCPRINT(GCOUTF, "Couldn't allocate exception port: %s\n", 
	   mach_error_string(retval));
    abort();
  }

  GC_attach_current_thread_exceptions_to_handler();

#ifdef PPC_HAND_ROLLED_THREAD 
  /* Old hand-rolled thread creation. */
 {
   /* set up the subthread */
   mach_port_t exc_thread;
   ARCH_thread_state_t *exc_thread_state;
   void *subthread_stack;

   retval = thread_create(task_self, &exc_thread);
   if(retval != KERN_SUCCESS) {
     GCPRINT(GCOUTF, "Couldn't create exception thread: %s\n", mach_error_string(retval));
     abort();
   }
   subthread_stack = (void*)malloc(page_size);
   subthread_stack += (page_size - C_ARGSAVE_LEN - C_RED_ZONE);
   exc_thread_state = (ARCH_thread_state_t*)malloc(sizeof(ARCH_thread_state_t));
   exc_thread_state->srr0 = (unsigned int)exception_thread;
   exc_thread_state->r1 = (unsigned int)subthread_stack;
   retval = thread_set_state(exc_thread, ARCH_THREAD_STATE,
			     (thread_state_t)exc_thread_state,
			     ARCH_THREAD_STATE_COUNT);
   if(retval != KERN_SUCCESS) {
     GCPRINT(GCOUTF, "Couldn't set subthread state: %s\n", mach_error_string(retval));
     abort();
   }
   retval = thread_resume(exc_thread);
   if(retval != KERN_SUCCESS) {
     GCPRINT(GCOUTF, "Couldn't resume subthread: %s\n", mach_error_string(retval));
     abort();
   }
 }
#else
 {
   pthread_t th;
   void *data = NULL;
#ifdef USE_THREAD_LOCAL
   data = pthread_getspecific(scheme_thread_local_key);
#endif
   pthread_create(&th, NULL, (void *(*)(void *))exception_thread, data);
 }
#endif
}
开发者ID:acarrico,项目名称:racket,代码行数:65,代码来源:vm_osx.c


示例10: get_current_thread_data

 boost::detail::thread_data_base* get_current_thread_data()
 {
     boost::call_once(current_thread_tls_init_flag,create_current_thread_tls_key);
     return (boost::detail::thread_data_base*)pthread_getspecific(current_thread_tls_key);
 }
开发者ID:CambrianTech,项目名称:boost-build,代码行数:5,代码来源:thread.cpp


示例11: lib_get_log_unit

static lib_log_t* lib_get_log_unit()
{
	return (lib_log_t*) pthread_getspecific(g_log_fd);
}
开发者ID:newwy,项目名称:otl,代码行数:4,代码来源:lib_log.cpp


示例12: fsal_increment_nbcall

/**
 * fsal_increment_nbcall:
 * Updates fonction call statistics.
 *
 * \param function_index (input):
 *        Index of the function whom number of call is to be incremented.
 * \param status (input):
 *        Status the function returned.
 *
 * \return Nothing.
 */
void fsal_increment_nbcall(int function_index, fsal_status_t status)
{

  fsal_statistics_t *bythread_stat = NULL;

  /* verify index */

  if(function_index >= FSAL_NB_FUNC)
    return;

  /* first, we init the keys if this is the first time */

  if(pthread_once(&once_key, init_keys) != 0)
    {
      LogError(COMPONENT_FSAL, ERR_SYS, ERR_PTHREAD_ONCE, errno);
      return;
    }

  /* we get the specific value */

  bythread_stat = (fsal_statistics_t *) pthread_getspecific(key_stats);

  /* we allocate stats if this is the first time */

  if(bythread_stat == NULL)
    {
      int i;

      bythread_stat = (fsal_statistics_t *) Mem_Alloc(sizeof(fsal_statistics_t));

      if(bythread_stat == NULL)
        {
          LogError(COMPONENT_FSAL, ERR_SYS, ERR_MALLOC, Mem_Errno);
          return;
        }

      /* inits the struct */

      for(i = 0; i < FSAL_NB_FUNC; i++)
        {
          bythread_stat->func_stats.nb_call[i] = 0;
          bythread_stat->func_stats.nb_success[i] = 0;
          bythread_stat->func_stats.nb_err_retryable[i] = 0;
          bythread_stat->func_stats.nb_err_unrecover[i] = 0;
        }

      /* set the specific value */
      pthread_setspecific(key_stats, (void *)bythread_stat);

    }

  /* we increment the values */

  if(bythread_stat)
    {
      bythread_stat->func_stats.nb_call[function_index]++;

      if(!FSAL_IS_ERROR(status))
        bythread_stat->func_stats.nb_success[function_index]++;
      else if(fsal_is_retryable(status))
        bythread_stat->func_stats.nb_err_retryable[function_index]++;
      else
        bythread_stat->func_stats.nb_err_unrecover[function_index]++;
    }

  return;
}
开发者ID:alangenfeld,项目名称:cloud-nfs,代码行数:78,代码来源:fsal_internal.c


示例13: co_get_current_co

co_t co_get_current_co()
{
    sched_t s = (sched_t)pthread_getspecific(co_sched_key); 
    return s->co_current; 
}
开发者ID:watsonjiang,项目名称:pth_test,代码行数:5,代码来源:co_sched.cpp


示例14: THR_GetRequest

struct req *
THR_GetRequest(void)
{

	return (pthread_getspecific(req_key));
}
开发者ID:1HLtd,项目名称:Varnish-Cache,代码行数:6,代码来源:cache_main.c


示例15: NaClFaultInjectionGetValue

static uintptr_t NaClFaultInjectionGetValue(void) {
  return (uintptr_t) pthread_getspecific(gTsd_FaultInjectValueKey);
}
开发者ID:bortoq,项目名称:zerovm,代码行数:3,代码来源:fault_injection.c


示例16: rt_print_init

int rt_print_init(size_t buffer_size, const char *buffer_name)
{
	struct print_buffer *buffer = pthread_getspecific(buffer_key);
	size_t size = buffer_size;
	unsigned long old_bitmap;
	unsigned j;

	if (!size)
		size = default_buffer_size;
	else if (size < RT_PRINT_LINE_BREAK)
		return EINVAL;

	if (buffer) {
		/* Only set name if buffer size is unchanged or default */
		if (size == buffer->size || !buffer_size) {
			set_buffer_name(buffer, buffer_name);
			return 0;
		}
		cleanup_buffer(buffer);
		buffer = NULL;
	}

#ifdef CONFIG_XENO_FASTSYNCH
	/* Find a free buffer in the pool */
	do {
		unsigned long bitmap;
		unsigned i;

		for (i = 0; i < pool_bitmap_len; i++) {
			old_bitmap = xnarch_atomic_get(&pool_bitmap[i]);
			if (old_bitmap)
				goto acquire;
		}

		goto not_found;

	  acquire:
		do {
			bitmap = old_bitmap;
			j = __builtin_ffsl(bitmap) - 1;
			old_bitmap = xnarch_atomic_cmpxchg(&pool_bitmap[i],
							   bitmap,
							   bitmap & ~(1UL << j));
		} while (old_bitmap != bitmap && old_bitmap);
		j += i * BITS_PER_LONG;
	} while (!old_bitmap);

	buffer = (struct print_buffer *)(pool_start + j * pool_buf_size);

  not_found:
#endif /* CONFIG_XENO_FASTSYNCH */

	if (!buffer) {
		assert_nrt();

		buffer = malloc(sizeof(*buffer));
		if (!buffer)
			return ENOMEM;

		buffer->ring = malloc(size);
		if (!buffer->ring) {
			free(buffer);
			return ENOMEM;
		}

		rt_print_init_inner(buffer, size);
	}

	set_buffer_name(buffer, buffer_name);

	pthread_setspecific(buffer_key, buffer);

	return 0;
}
开发者ID:BhargavKola,项目名称:xenomai-forge,代码行数:74,代码来源:printf.c


示例17:

bool RT::OS::isRealtime(void) {
	if (init_rt && pthread_getspecific(is_rt_key))
		return true;
	return false;
}
开发者ID:misterboyle,项目名称:rtxi,代码行数:5,代码来源:rt_os-xenomai.cpp


示例18: vprint_to_buffer

static int vprint_to_buffer(FILE *stream, int priority, unsigned int mode,
			    const char *format, va_list args)
{
	struct print_buffer *buffer = pthread_getspecific(buffer_key);
	off_t write_pos, read_pos;
	struct entry_head *head;
	int len, str_len;
	int res = 0;

	if (!buffer) {
		res = 0;
		if (auto_init)
			res = rt_print_init(0, NULL);
		else
			res = EIO;

		if (res) {
			errno = res;
			return -1;
		}
		buffer = pthread_getspecific(buffer_key);
	}

	/* Take a snapshot of the ring buffer state */
	write_pos = buffer->write_pos;
	read_pos = buffer->read_pos;
	xnarch_read_memory_barrier();

	/* Is our write limit the end of the ring buffer? */
	if (write_pos >= read_pos) {
		/* Keep a safety margin to the end for at least an empty entry */
		len = buffer->size - write_pos - sizeof(struct entry_head);

		/* Special case: We were stuck at the end of the ring buffer
		   with space left there only for one empty entry. Now
		   read_pos was moved forward and we can wrap around. */
		if (len == 0 && read_pos > sizeof(struct entry_head)) {
			/* Write out empty entry */
			head = buffer->ring + write_pos;
			head->seq_no = seq_no;
			head->priority = 0;
			head->text[0] = 0;

			/* Forward to the ring buffer start */
			write_pos = 0;
			len = read_pos - 1;
		}
	} else {
		/* Our limit is the read_pos ahead of our write_pos. One byte
		   margin is required to detect a full ring. */
		len = read_pos - write_pos - 1;
	}

	/* Account for head length */
	len -= sizeof(struct entry_head);
	if (len < 0)
		len = 0;

	head = buffer->ring + write_pos;

	if (mode == RT_PRINT_MODE_FORMAT) {
		res = vsnprintf(head->text, len, format, args);

		if (res < len) {
			/* Text was written completely, res contains its
			   length */
			len = res;
		} else {
			/* Text was truncated, remove closing \0 that
			   entry_head already includes */
			len--;
			res = len;
		}
	} else if (len >= 2) {
		str_len = strlen(format);
		len = (str_len < len - 2) ? str_len : len - 2;
		strncpy(head->text, format, len);
		head->text[len++] = '\n';
		head->text[len] = 0;
	} else
		len = 0;

	/* If we were able to write some text, finalise the entry */
	if (len > 0) {
		head->seq_no = ++seq_no;
		head->priority = priority;
		head->dest = stream;

		/* Move forward by text and head length */
		write_pos += len + sizeof(struct entry_head);
	}

	/* Wrap around early if there is more space on the other side */
	if (write_pos >= buffer->size - RT_PRINT_LINE_BREAK &&
	    read_pos <= write_pos && read_pos > buffer->size - write_pos) {
		/* An empty entry marks the wrap-around */
		head = buffer->ring + write_pos;
		head->seq_no = seq_no;
		head->priority = priority;
		head->text[0] = 0;
//.........这里部分代码省略.........
开发者ID:BhargavKola,项目名称:xenomai-forge,代码行数:101,代码来源:printf.c


示例19: pcu_thread_rank

int pcu_thread_rank(void)
{
  /* double cast to assure GCC that I know what I'm doing. */
  return (int)(ptrdiff_t)(pthread_getspecific(global_key));
}
开发者ID:GKosiba,项目名称:core,代码行数:5,代码来源:pcu_thread.c


示例20: TGetValue

 inline TYPE* TGetValue()             { return (TYPE*)pthread_getspecific(m_key); }
开发者ID:RexBaribal,项目名称:projectanarchy,代码行数:1,代码来源:VThreadVariable.hpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ pthread_join函数代码示例发布时间:2022-05-30
下一篇:
C++ pthread_getschedparam函数代码示例发布时间: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