本文整理汇总了C++中Thread::CPUTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Thread::CPUTime方法的具体用法?C++ Thread::CPUTime怎么用?C++ Thread::CPUTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thread
的用法示例。
在下文中一共展示了Thread::CPUTime方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: timeLocker
status_t
user_timer_get_clock(clockid_t clockID, bigtime_t& _time)
{
switch (clockID) {
case CLOCK_MONOTONIC:
_time = system_time();
return B_OK;
case CLOCK_REALTIME:
_time = real_time_clock_usecs();
return B_OK;
case CLOCK_THREAD_CPUTIME_ID:
{
Thread* thread = thread_get_current_thread();
InterruptsSpinLocker timeLocker(thread->time_lock);
_time = thread->CPUTime(false);
return B_OK;
}
case CLOCK_PROCESS_USER_CPUTIME_ID:
{
Team* team = thread_get_current_thread()->team;
InterruptsSpinLocker timeLocker(team->time_lock);
_time = team->UserCPUTime();
return B_OK;
}
case CLOCK_PROCESS_CPUTIME_ID:
default:
{
// get the ID of the target team (or the respective placeholder)
team_id teamID;
if (clockID == CLOCK_PROCESS_CPUTIME_ID) {
teamID = B_CURRENT_TEAM;
} else {
if (clockID < 0)
return B_BAD_VALUE;
if (clockID == team_get_kernel_team_id())
return B_NOT_ALLOWED;
teamID = clockID;
}
// get the team
Team* team = Team::Get(teamID);
if (team == NULL)
return B_BAD_VALUE;
BReference<Team> teamReference(team, true);
// get the time
InterruptsSpinLocker timeLocker(team->time_lock);
_time = team->CPUTime(false);
return B_OK;
}
}
}