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

C++ pthread_getattr_np函数代码示例

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

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



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

示例1: current_stack_region

static void current_stack_region(address* bottom, size_t* size) {
  if (os::Linux::is_initial_thread()) {
    // initial thread needs special handling because pthread_getattr_np()
    // may return bogus value.
    *bottom = os::Linux::initial_thread_stack_bottom();
    *size = os::Linux::initial_thread_stack_size();
  } else {
    pthread_attr_t attr;

    int rslt = pthread_getattr_np(pthread_self(), &attr);

    // JVM needs to know exact stack location, abort if it fails
    if (rslt != 0) {
      if (rslt == ENOMEM) {
        vm_exit_out_of_memory(0, "pthread_getattr_np");
      } else {
        fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
      }
    }

    if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) {
      fatal("Can not locate current stack attributes!");
    }

    pthread_attr_destroy(&attr);
  }
  assert(os::current_stack_pointer() >= *bottom &&
         os::current_stack_pointer() < *bottom + *size, "just checking");
}
开发者ID:AK47POMA,项目名称:openjdk-icedtea7,代码行数:29,代码来源:os_linux_sparc.cpp


示例2: get_stack

static int
get_stack(void **addr, size_t *size)
{
#define CHECK_ERR(expr)				\
    {int err = (expr); if (err) return err;}
#if defined HAVE_PTHREAD_GETATTR_NP || defined HAVE_PTHREAD_ATTR_GET_NP
    pthread_attr_t attr;
    size_t guard = 0;

# ifdef HAVE_PTHREAD_GETATTR_NP
    CHECK_ERR(pthread_getattr_np(pthread_self(), &attr));
#   ifdef HAVE_PTHREAD_ATTR_GETSTACK
    CHECK_ERR(pthread_attr_getstack(&attr, addr, size));
#   else
    CHECK_ERR(pthread_attr_getstackaddr(&attr, addr));
    CHECK_ERR(pthread_attr_getstacksize(&attr, size));
#   endif
    if (pthread_attr_getguardsize(&attr, &guard) == 0) {
	STACK_GROW_DIR_DETECTION;
	STACK_DIR_UPPER((void)0, (void)(*addr = (char *)*addr + guard));
	*size -= guard;
    }
# else
    CHECK_ERR(pthread_attr_init(&attr));
    CHECK_ERR(pthread_attr_get_np(pthread_self(), &attr));
    CHECK_ERR(pthread_attr_getstackaddr(&attr, addr));
    CHECK_ERR(pthread_attr_getstacksize(&attr, size));
# endif
    CHECK_ERR(pthread_attr_getguardsize(&attr, &guard));
    *size -= guard;
# ifndef HAVE_PTHREAD_GETATTR_NP
    pthread_attr_destroy(&attr);
# endif
#elif defined HAVE_PTHREAD_GET_STACKADDR_NP && defined HAVE_PTHREAD_GET_STACKSIZE_NP
    pthread_t th = pthread_self();
    *addr = pthread_get_stackaddr_np(th);
    *size = pthread_get_stacksize_np(th);
#elif defined HAVE_THR_STKSEGMENT || defined HAVE_PTHREAD_STACKSEG_NP
    stack_t stk;
# if defined HAVE_THR_STKSEGMENT
    CHECK_ERR(thr_stksegment(&stk));
# else
    CHECK_ERR(pthread_stackseg_np(pthread_self(), &stk));
# endif
    *addr = stk.ss_sp;
    *size = stk.ss_size;
#elif defined HAVE_PTHREAD_GETTHRDS_NP
    pthread_t th = pthread_self();
    struct __pthrdsinfo thinfo;
    char reg[256];
    int regsiz=sizeof(reg);
    CHECK_ERR(pthread_getthrds_np(&th, PTHRDSINFO_QUERY_ALL,
				  &thinfo, sizeof(thinfo),
				  &reg, &regsiz));
    *addr = thinfo.__pi_stackaddr;
    *size = thinfo.__pi_stacksize;
#endif
    return 0;
#undef CHECK_ERR
}
开发者ID:pascalt,项目名称:captalog,代码行数:60,代码来源:thread_pthread.c


示例3: run_

static void* run_(
	void* arg
	)
{
	pthread_mutex_t* mutex = (pthread_mutex_t*)arg;
	pthread_attr_t attr;
	void* stack_addr;
	size_t stack_size;

	pthread_getattr_np(pthread_self(), &attr);
	pthread_attr_getstack(&attr, &stack_addr, &stack_size);

	pthread_mutex_lock(mutex);

	printf("--- pthread ---\n");
	printf("thread id:          [0x%08x]\n", (unsigned int)pthread_self());
	printf("stack addr:         [%p]\n", stack_addr);
	printf("stack size:         [0x%08x]\n", stack_size);
	printf("&arg:               [%p]\n", &arg);
	printf("\n");
	raise(SIGINT);
	raise(SIGINT);

	pthread_mutex_unlock(mutex);

	return NULL;
}
开发者ID:yasukei,项目名称:junk,代码行数:27,代码来源:signal.c


示例4: get_stack

static void get_stack(void **stack_addr, size_t *stack_size)
{
    pthread_attr_t attr;
    pthread_getattr_np(pthread_self(), &attr);
    pthread_attr_getstack(&attr, stack_addr, stack_size);
    pthread_attr_destroy(&attr);
}
开发者ID:SunshineMou,项目名称:Study,代码行数:7,代码来源:pthread_attr_others.c


示例5: malloc_get_stack

//return 0: success, -1 fail
__LIBC_HIDDEN__ int malloc_get_stack(size_t* pthread_stack_start, size_t* pthread_stack_end) {
  pid_t pid = getpid();

  if (gettid() == pid) {
    if (pid != malloc_pid) {
      malloc_pid = pid;
      malloc_main_thread_stack_start = 0;  // reset for new process
      malloc_main_thread_stack_size = 0;
    }

    if (!malloc_main_thread_stack_start) {
      if (malloc_get_main_thread_stack(pid)) {
        return -1;
      }
    }
    *pthread_stack_start = malloc_main_thread_stack_start;
    *pthread_stack_end = malloc_main_thread_stack_start - malloc_main_thread_stack_size;
  }
  else {
    pthread_attr_t attr;
    pthread_getattr_np(pthread_self(), &attr);
    *pthread_stack_start = (size_t)attr.stack_base + attr.stack_size;
    *pthread_stack_end = (size_t)attr.stack_base;
  }
  return 0;
}
开发者ID:bju2000,项目名称:MT6797,代码行数:27,代码来源:debug_stacktrace.cpp


示例6: get_stack_size

size_t get_stack_size(int main) {
    if (main) {
        // Retrieve stack size of the main thread.
        struct rlimit curr;
        if (getrlimit(RLIMIT_STACK, &curr) != 0) {
            throw_get_stack_size_failed();
        }
        return curr.rlim_cur;
    } else {
        #if defined(LEAN_MULTI_THREAD)
        pthread_attr_t attr;
        memset (&attr, 0, sizeof(attr));
        if (pthread_getattr_np(pthread_self(), &attr) != 0) {
            throw_get_stack_size_failed();
        }
        void * ptr;
        size_t result;
        if (pthread_attr_getstack (&attr, &ptr, &result) != 0) {
            throw_get_stack_size_failed();
        }
        if (pthread_attr_destroy(&attr) != 0) {
            throw_get_stack_size_failed();
        }
        return result;
        #else
        return 0;
        #endif
    }
}
开发者ID:GallagherCommaJack,项目名称:lean,代码行数:29,代码来源:stackinfo.cpp


示例7: fct

static void
fct (union sigval s)
{
  mqd_t q = *(mqd_t *) s.sival_ptr;

  pthread_attr_t nattr;
  int ret = pthread_getattr_np (pthread_self (), &nattr);
  if (ret)
    {
      errno = ret;
      printf ("pthread_getattr_np failed: %m\n");
      fct_err = 1;
    }
  else
    {
      ret = pthread_attr_getguardsize (&nattr, &fct_guardsize);
      if (ret)
	{
	  errno = ret;
	  printf ("pthread_attr_getguardsize failed: %m\n");
	  fct_err = 1;
	}
      if (pthread_attr_destroy (&nattr) != 0)
	{
	  puts ("pthread_attr_destroy failed");
	  fct_err = 1;
	}
    }

  ++fct_cnt;
  fct_err |= mqsend (q);
}
开发者ID:JamesLinus,项目名称:glibc-mips,代码行数:32,代码来源:tst-mqueue6.c


示例8: pthread_getattr_np

int
Stack_Size_Check::svc (void)
{
  size_t my_size = 0;

#ifdef __USE_GNU
  pthread_attr_t my_attrs;
  pthread_getattr_np (pthread_self (), &my_attrs);
  pthread_attr_getstacksize (&my_attrs, &my_size);
  pthread_attr_destroy (&my_attrs);
#else
  // No known way to do this yet... feel free to fill this in.
  my_size = this->stack_size_;
#endif /* __USE_GNU */

  // The Posix docs say that the size set for the threads stack will be the
  // *minimum* size allocated (the actual size may be bigger because of
  // a) pagesize rounding, b) guardsize addition) so we can really only
  // check if we have gotten *at least* what we asked for.
  if (my_size < this->stack_size_)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_TEXT ("%t: My stack size attr %B; expected %B\n"),
                  my_size, this->stack_size_));
      this->failed_ = true;
    }
  else
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("%t: My stack size attr %B; correct.\n"),
                my_size));
  return 0;
}
开发者ID:asdlei00,项目名称:ACE,代码行数:32,代码来源:Thread_Attrs_Test.cpp


示例9: TestThreadStackSize_getstacksize

    void TestThreadStackSize_getstacksize()
    {
        const size_t c_stacksize = 320000;

        // set up a thread with a stack size of 'c_stacksize'
        SCXCoreLib::SCXHandle<SCXCoreLib::SCXThreadParam> p(new SCXCoreLib::SCXThreadParam());
        SCXCoreLib::SCXThreadAttr threadAttr;

        CPPUNIT_ASSERT_NO_THROW(threadAttr.SetStackSize(c_stacksize));

        SCXCoreLib::SCXThread* thread = new SCXCoreLib::SCXThread(SCXThreadTest::SimpleThreadBodyTerminate, p, &threadAttr);

        // Let's make sure the stack size is what we set it to be.
        // SCXThreadId is just a typedef of pthread_t on SCX_UNIX.
        SCXCoreLib::SCXThreadId pt = thread->GetThreadID();
        pthread_attr_t attr;

        int errorval = pthread_getattr_np(pt, &attr);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("pthread_getattr_np failed", 0, errorval);

        size_t actualsize;
        errorval = pthread_attr_getstacksize(&attr, &actualsize);
        CPPUNIT_ASSERT_EQUAL_MESSAGE("pthread_attr_getstacksize failed", 0, errorval);

        // according to pthread_attr_setstacksize's man page, the allocated stack size should be
        // greater than or equal to the requested stack size
        std::stringstream ss;
        ss << "Actual stack size (" << actualsize << ") should be greater than or equal to requested size  (" << c_stacksize <<  ")";
        CPPUNIT_ASSERT_MESSAGE(ss.str(), actualsize >= c_stacksize);

        // clean up the thread
        thread->RequestTerminate();
        thread->Wait();
        delete thread;
    }
开发者ID:Microsoft,项目名称:pal,代码行数:35,代码来源:scxthread_test.cpp


示例10: system_get_stack

void system_get_stack(pthread_t thread, void **base, size_t *size) {
  dbg_assert(base && size);

  pthread_attr_t attr;
  dbg_check( pthread_getattr_np(thread, &attr) );
  dbg_check( pthread_attr_getstack(&attr, base, size) );
}
开发者ID:dkogler,项目名称:hpx5-measurement-tests,代码行数:7,代码来源:cpu.c


示例11: AssertDetached

static void AssertDetached(pthread_t t, bool is_detached) {
  pthread_attr_t attr;
  ASSERT_EQ(0, pthread_getattr_np(t, &attr));
  int detach_state;
  ASSERT_EQ(0, pthread_attr_getdetachstate(&attr, &detach_state));
  pthread_attr_destroy(&attr);
  ASSERT_EQ(is_detached, (detach_state == PTHREAD_CREATE_DETACHED));
}
开发者ID:nick0lay,项目名称:platform_bionic,代码行数:8,代码来源:pthread_test.cpp


示例12: my_pthread_getattr_np

int
my_pthread_getattr_np(pthread_t __th, pthread_attr_t *__attr)
{
    assert(__attr != NULL);
    pthread_attr_t *realattr = (pthread_attr_t *) *(int *) __attr;
    assert(realattr != NULL);
    return pthread_getattr_np(__th,realattr);
}
开发者ID:Axxelloss,项目名称:apkenv,代码行数:8,代码来源:pthread_wrappers.c


示例13: my_pthread_getattr_np

static int my_pthread_getattr_np(pthread_t thid, pthread_attr_t *__attr)
{
    pthread_attr_t *realattr;

    realattr = malloc(sizeof(pthread_attr_t));
    *((unsigned int *)__attr) = (unsigned int) realattr;

    return pthread_getattr_np(thid, realattr);
}
开发者ID:NinjaComics,项目名称:libhybris,代码行数:9,代码来源:hooks.c


示例14: OS

size_t MachineThreads::Thread::getRegisters(MachineThreads::Thread::Registers& registers)
{
    Thread::Registers::PlatformRegisters& regs = registers.regs;
#if OS(DARWIN)
#if CPU(X86)
    unsigned user_count = sizeof(regs)/sizeof(int);
    thread_state_flavor_t flavor = i386_THREAD_STATE;
#elif CPU(X86_64)
    unsigned user_count = x86_THREAD_STATE64_COUNT;
    thread_state_flavor_t flavor = x86_THREAD_STATE64;
#elif CPU(PPC) 
    unsigned user_count = PPC_THREAD_STATE_COUNT;
    thread_state_flavor_t flavor = PPC_THREAD_STATE;
#elif CPU(PPC64)
    unsigned user_count = PPC_THREAD_STATE64_COUNT;
    thread_state_flavor_t flavor = PPC_THREAD_STATE64;
#elif CPU(ARM)
    unsigned user_count = ARM_THREAD_STATE_COUNT;
    thread_state_flavor_t flavor = ARM_THREAD_STATE;
#elif CPU(ARM64)
    unsigned user_count = ARM_THREAD_STATE64_COUNT;
    thread_state_flavor_t flavor = ARM_THREAD_STATE64;
#else
#error Unknown Architecture
#endif

    kern_return_t result = thread_get_state(platformThread, flavor, (thread_state_t)&regs, &user_count);
    if (result != KERN_SUCCESS) {
        WTFReportFatalError(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, 
                            "JavaScript garbage collection failed because thread_get_state returned an error (%d). This is probably the result of running inside Rosetta, which is not supported.", result);
        CRASH();
    }
    return user_count * sizeof(uintptr_t);
// end OS(DARWIN)

#elif OS(WINDOWS)
    regs.ContextFlags = CONTEXT_INTEGER | CONTEXT_CONTROL;
    GetThreadContext(platformThreadHandle, &regs);
    return sizeof(CONTEXT);
#elif USE(PTHREADS)
    pthread_attr_init(&regs);
#if HAVE(PTHREAD_NP_H) || OS(NETBSD)
#if !OS(OPENBSD)
    // e.g. on FreeBSD 5.4, [email protected]
    pthread_attr_get_np(platformThread, &regs);
#endif
#else
    // FIXME: this function is non-portable; other POSIX systems may have different np alternatives
    pthread_getattr_np(platformThread, &regs);
#endif
    return 0;
#else
#error Need a way to get thread registers on this platform
#endif
}
开发者ID:mu326668629,项目名称:webkit,代码行数:55,代码来源:MachineStackMarker.cpp


示例15: thread

void* thread(void* param)
{
	pthread_attr_t attr;
	printf("\n In thread\n" );
	pthread_getattr_np(pthread_self(), &attr);	
	read_stack_attributes(&attr);
	read_detachstate_attribute(&attr);
	read_guard_attribute(&attr);
	read_schedpolicy_attribute(&attr);
        return 0;
}
开发者ID:coder03,项目名称:ldd,代码行数:11,代码来源:pthread_getattr.c


示例16: pthread_attr_getstack_18908062_helper

static void pthread_attr_getstack_18908062_helper(void*) {
  char local_variable;
  pthread_attr_t attributes;
  pthread_getattr_np(pthread_self(), &attributes);
  void* stack_base;
  size_t stack_size;
  pthread_attr_getstack(&attributes, &stack_base, &stack_size);

  // Test whether &local_variable is in [stack_base, stack_base + stack_size).
  ASSERT_LE(reinterpret_cast<char*>(stack_base), &local_variable);
  ASSERT_LT(&local_variable, reinterpret_cast<char*>(stack_base) + stack_size);
}
开发者ID:loongchow,项目名称:platform_bionic,代码行数:12,代码来源:pthread_test.cpp


示例17: mono_threads_core_get_stack_bounds

void
mono_threads_core_get_stack_bounds (guint8 **staddr, size_t *stsize)
{
	pthread_attr_t attr;

	*staddr = NULL;
	*stsize = (size_t)-1;

	pthread_getattr_np (pthread_self (), &attr);
	pthread_attr_getstack (&attr, (void**)staddr, stsize);
	pthread_attr_destroy (&attr);
}
开发者ID:Adamcbrz,项目名称:mono,代码行数:12,代码来源:mono-threads-linux.c


示例18: print_it

void print_it () 
{
  int rc;
  pthread_attr_t foo;
  size_t size;
  rc = pthread_getattr_np (pthread_self(), & foo);
  assert (rc == 0);
  rc = pthread_attr_getstacksize(&foo, &size);
  assert (rc == 0);
  printf ("stacksize=%u\n", size);
  rc = pthread_attr_destroy (&foo);
  assert (rc == 0);
}
开发者ID:5kg,项目名称:systemtap,代码行数:13,代码来源:pthread_stacks.c


示例19: taskGetInfo

STATUS taskGetInfo(TASK_ID task_id, TASK_DESC *desc)
{
	int vfirst, vlast, ret;
	struct wind_task *task;
	struct WIND_TCB *tcb;
	pthread_attr_t attr;
	size_t stacksize;
	void *stackbase;

	task = get_wind_task(task_id);
	if (task == NULL) {
		errno = S_objLib_OBJ_ID_ERROR;
		return ERROR;
	}

	tcb = task->tcb;
	desc->td_tid = task_id;
	desc->td_priority = wind_task_get_priority(task);
	desc->td_status = get_task_status(task);
	desc->td_flags = tcb->flags;
	strncpy(desc->td_name, task->name, sizeof(desc->td_name));
	desc->td_entry = tcb->entry;
	desc->td_errorStatus = *task->thobj.errno_pointer;
	ret = pthread_getattr_np(task->thobj.tid, &attr);
	put_wind_task(task);

	/*
	 * If the target does not support pthread_getattr_np(), we are
	 * out of luck for determining the stack information. We just
	 * zero it.
	 */
	if (ret) {
		/* No idea, buddy. */
		desc->td_stacksize = 0;
		desc->td_pStackBase = NULL;
	} else {
		pthread_attr_getstack(&attr, &stackbase, &stacksize);
		desc->td_stacksize = stacksize;
		desc->td_pStackBase = stackbase;

		if (&vfirst < &vlast)
			/* Stack grows upward. */
			desc->td_pStackEnd = (caddr_t)stackbase + stacksize;
		else
			/* Stack grows downward. */
			desc->td_pStackEnd = (caddr_t)stackbase - stacksize;
	}

	return OK;
}
开发者ID:Lmaths,项目名称:xenomai-forge,代码行数:50,代码来源:taskInfo.c


示例20: defined

void *nativeStackBase() {
#if defined(__UCLIBC__) || defined(__EMSCRIPTEN__)
    return NULL;
#else
    pthread_attr_t attr;
    void *addr;
    size_t size;

    pthread_getattr_np(pthread_self(), &attr);
    pthread_attr_getstack(&attr, &addr, &size);

    return addr+size;
#endif
}
开发者ID:vilie,项目名称:javify,代码行数:14,代码来源:os.c



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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