本文整理汇总了C++中TIMER类的典型用法代码示例。如果您正苦于以下问题:C++ TIMER类的具体用法?C++ TIMER怎么用?C++ TIMER使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TIMER类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: VFIO
VFIO(timer_write, file, data, size)
{
TIMER *timer = (TIMER*)data;
unsigned char cnf = 1, i = 1;
timer->config = timer->config & 0x7;
while(timer->config)
{
cnf &= timer->config;
switch(cnf)
{
case 0x4:
timer->set_mode(timer);
break;
case 0x2:
timer->set_frq(timer);
break;
case 0x1:
/* get the tick offset */
if(size <= sizeof(void*))
return 0;
uint64_t offset = *((uint64_t*)(data+
sizeof(void*)));
timer->set_tick(timer, offset);
break;
default: /* unknown config word.. reset bits set? */
break;
}
timer->config &= (~cnf); /* disable just checked bit */
cnf = (++i)<<1;
if(cnf >= 1>>3)
break;
}
return E_SUCCESS;
}
示例2: IRQ
IRQ(timer_irq, irq, stack)
{
struct irq_data *data = get_irq_data(irq);
struct device *dev = (struct device *)(data->irq_data);
TIMER *timer = dev->device_data;
timer->tick++;
timer->tick_handle(timer);
return;
}
示例3:
void LocalClient::KeystateTaskThread::task() {
#define KEYSTATE_GRANULARITY_MS 46.66 // aiming for as low a rate as possible
static TIMER keystate_timer;
keystate_timer.begin();
while (LocalClient::KeystateTaskThread::is_running() && LocalClient::is_connected()) {
if (keystate_timer.get_ms() > KEYSTATE_GRANULARITY_MS) {
update_keystate(keys);
post_keystate();
keystate_timer.begin();
long wait_ms = KEYSTATE_GRANULARITY_MS - keystate_timer.get_ms();
if (wait_ms > 1) { SLEEP_MS(wait_ms); }
}
}
}
示例4: stopwatch_event
stopwatch_event(uint32_t waitms,
std::function<void(void)>&& d,
const TIMER& in_ms_timer) :
ms_timer([&in_ms_timer]() { return in_ms_timer.milliseconds(); }),
_canceled(IS_NOT_CANCELED),
_step(IS_NOT_STARTED),
waitms(waitms),
d(std::move(d)),
lastms(ms_timer())
{ }
示例5: mpi_reduce_timers
/**
* Reduce all server timers to server master.
* @param timer
*/
void mpi_reduce_timers(TIMER& timer){
sip::SIPMPIAttr &attr = sip::SIPMPIAttr::get_instance();
sip::check(attr.is_server(), "Trying to reduce timer on a non-server rank !");
long long * timers = timer.get_timers();
long long * timer_counts = timer.get_timer_count();
// Data to send to reduce
long long * sendbuf = new long long[2*timer.max_slots + 1];
sendbuf[0] = timer.max_slots;
// The data will be structured as
// Length of arrays 1 & 2
// Array1 -> timer_switched_ array
// Array2 -> timer_list_ array
std::copy(timer_counts + 0, timer_counts + timer.max_slots, sendbuf+1);
std::copy(timers + 0, timers + timer.max_slots, sendbuf+1+ timer.max_slots);
long long * recvbuf = new long long[2*timer.max_slots + 1]();
int server_master = attr.COMPANY_MASTER_RANK;
MPI_Comm server_company = attr.company_communicator();
MPI_Datatype server_timer_reduce_dt; // MPI Type for timer data to be reduced.
MPI_Op server_timer_reduce_op; // MPI OP to reduce timer data.
SIPMPIUtils::check_err(MPI_Type_contiguous(timer.max_slots*2+1, MPI_LONG_LONG, &server_timer_reduce_dt));
SIPMPIUtils::check_err(MPI_Type_commit(&server_timer_reduce_dt));
SIPMPIUtils::check_err(MPI_Op_create((MPI_User_function *)server_timer_reduce_op_function, 1, &server_timer_reduce_op));
SIPMPIUtils::check_err(MPI_Reduce(sendbuf, recvbuf, 1, server_timer_reduce_dt, server_timer_reduce_op, server_master, server_company));
if (attr.is_company_master()){
std::copy(recvbuf+1, recvbuf+1+timer.max_slots, timer_counts);
std::copy(recvbuf+1+timer.max_slots, recvbuf+1+2*timer.max_slots, timers);
}
// Cleanup
delete [] sendbuf;
delete [] recvbuf;
SIPMPIUtils::check_err(MPI_Type_free(&server_timer_reduce_dt));
SIPMPIUtils::check_err(MPI_Op_free(&server_timer_reduce_op));
}
示例6: CheckTimers
void CheckTimers()
{
//50 msecs were elasped
std::list<TIMER*>::iterator itr;
for(itr = gTimerList.begin(); itr != gTimerList.end();)
{
TIMER* curr = *itr;
curr->current += 50;
if ( curr->current >= curr->period ) {
if (curr->routine(curr->period)) {
curr->current -= curr->period;
}
else {
delete curr;
itr=gTimerList.erase(itr);
}
}
else
++itr;
}
}
示例7: execute
virtual void execute(TIMER& timer) {
void ** tau_timers = timer.get_tau_timers();
std::vector<std::string>::const_iterator it = line_to_str_.begin();
for (int line_num = 0; it!= line_to_str_.end(); ++it, ++line_num){
const std::string &line_str = *it;
if (line_str != ""){
int total_time_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::TOTALTIME);
if (tau_timers[total_time_timer_offset] != NULL){
// Set total time string
std::stringstream tot_sstr;
tot_sstr << sip::GlobalState::get_program_num() << ": " << line_num << ": " << " Total " << line_str;
const char *tau_string = tot_sstr.str().c_str();
TAU_PROFILE_TIMER_SET_NAME(tau_timers[total_time_timer_offset], tau_string);
}
int block_wait_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::BLOCKWAITTIME);
if (tau_timers[block_wait_timer_offset] != NULL){
// Set block wait time string
std::stringstream blkw_sstr;
blkw_sstr << sip::GlobalState::get_program_num() << ":" << line_num <<":" << " Blkwait " << line_str ;
const char *tau_string = blkw_sstr.str().c_str();
TAU_PROFILE_TIMER_SET_NAME(tau_timers[block_wait_timer_offset], tau_string);
}
int read_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::READTIME);
if (tau_timers[read_timer_offset] != NULL){
// Set disk read time string
std::stringstream readd_sstr;
readd_sstr << sip::GlobalState::get_program_num() << ":" << line_num <<":" << " ReadDisk " << line_str ;
const char *tau_string = readd_sstr.str().c_str();
TAU_PROFILE_TIMER_SET_NAME(tau_timers[read_timer_offset], tau_string);
}
int write_timer_offset = line_num + sialx_lines_ * static_cast<int>(ServerTimer::WRITETIME);
if (tau_timers[write_timer_offset] != NULL){
// Set disk write time string
std::stringstream writed_sstr;
writed_sstr << sip::GlobalState::get_program_num() << ":" << line_num <<":" << " WriteDisk " << line_str ;
const char *tau_string = writed_sstr.str().c_str();
TAU_PROFILE_TIMER_SET_NAME(tau_timers[write_timer_offset], tau_string);
}
}
}
}
示例8: run_task
MDA_TASK_RETURN_CODE MDA_TASK_PATH:: run_task() {
puts("Press q to quit");
MDA_VISION_MODULE_PATH path_vision;
MDA_VISION_MODULE_GATE gate_vision;
MDA_TASK_RETURN_CODE ret_code = TASK_MISSING;
TASK_STATE state = STARTING_GATE;
bool done_gate = false;
bool done_path = false;
// read the starting orientation
int starting_yaw = attitude_input->yaw();
printf("Starting yaw: %d\n", starting_yaw);
int GATE_DEPTH;
read_mv_setting ("hacks.csv", "GATE_DEPTH", GATE_DEPTH);
// gate depth
if (HARDCODED_DEPTH > 350)
set (DEPTH, 350);
if (HARDCODED_DEPTH > 400)
set (DEPTH, 400);
set (DEPTH, GATE_DEPTH);
//set(DEPTH, 100);
// go to the starting orientation in case sinking changed it
set (YAW, starting_yaw);
//TIMER master_timer;
TIMER timer;
timer.restart();
while (1) {
IplImage* frame = NULL;
MDA_VISION_RETURN_CODE vision_code = NO_TARGET;
MDA_VISION_RETURN_CODE gate_vision_code = NO_TARGET;
(void) gate_vision_code;
/*if (!done_gate) {
frame = image_input->get_image(FWD_IMG);
if (!frame) {
ret_code = TASK_ERROR;
break;
}
gate_vision_code = gate_vision.filter(frame);
}*/
frame = image_input->get_image(DWN_IMG);
if (!frame) {
ret_code = TASK_ERROR;
break;
}
vision_code = path_vision.filter(frame);
// clear fwd image. RZ - do we need this?
// This ensures the other camera is properly logged
// and that the webcam cache is cleared so it stays in sync - VZ
//image_input->ready_image(FWD_IMG);
/**
* Basic Algorithm:
* - Go to path
* - Align with path
*/
if (!done_gate) {
if (state == STARTING_GATE) {
printf ("Starting Gate: Moving Foward at High Speed\n");
set (SPEED, 5);
if (timer.get_time() > MASTER_TIMEOUT) {
printf ("Starting Gate: Master Timer Timeout!!\n");
return TASK_MISSING;
}
/*else if (gate_vision_code == FULL_DETECT) {
printf ("Starting Gate: Full Detect\n");
int ang_x = gate_vision.get_angular_x();
set_yaw_change(ang_x);
if (gate_vision.get_range() < 420) { // finished the gate
printf ("Range = %d, Approaching Gate\n", gate_vision.get_range());
timer.restart();
while (timer.get_time() < 3) {
set(SPEED, 6);
}
set(SPEED, 0);
printf ("Gate Task Done!!\n");
// get ready for path task
done_gate = true;
set(YAW, starting_yaw);
state = STARTING_PATH;
}
timer.restart();
}*/
// if path vision saw something, go do the path task
if (vision_code != NO_TARGET) {
//.........这里部分代码省略.........
示例9: run_task
MDA_TASK_RETURN_CODE MDA_TASK_GATE:: run_task() {
puts("Press q to quit");
MDA_VISION_MODULE_GATE gate_vision;
TASK_STATE state = STARTING;
bool done_gate = false;
MDA_TASK_RETURN_CODE ret_code = TASK_MISSING;
// read the starting orientation
int starting_yaw = attitude_input->yaw();
printf("Starting yaw: %d\n", starting_yaw);
MDA_TASK_BASE::starting_depth = attitude_input->depth();
// gate depth
set (DEPTH, HARDCODED_DEPTH-50/*MDA_TASK_BASE::starting_depth+GATE_DELTA_DEPTH*/);
set (DEPTH, HARDCODED_DEPTH/*MDA_TASK_BASE::starting_depth+GATE_DELTA_DEPTH*/);
// go to the starting orientation in case sinking changed it
set (YAW, starting_yaw);
static TIMER timer; // keeps track of time spent in each state
static TIMER master_timer; // keeps track of time spent not having found the target
static TIMER full_detect_timer; // keeps track of time since the last full detect
timer.restart();
master_timer.restart();
full_detect_timer.restart();
while (1) {
IplImage* frame = image_input->get_image();
if (!frame) {
ret_code = TASK_ERROR;
break;
}
MDA_VISION_RETURN_CODE vision_code = gate_vision.filter(frame);
// clear dwn image. RZ - do we need this?
// This ensures the other camera is properly logged
// and that the webcam cache is cleared so it stays in sync - VZ
image_input->ready_image(DWN_IMG);
// static
//static int prev_t = -1;
/**
* Basic Algorithm: (repeat)
* - Go straight foward in STARTING state until we see anything
*
* - If we saw a ONE_SEGMENT, calculate the course we should take to allow the segment to remain in view.
* - If we saw a FULL_DETECT, change course to face it
* - Always go forwards in increments and stop for 1 seconds to stare each time.
*/
if (!done_gate) {
if (state == STARTING) {
printf ("Starting: Moving Foward at High Speed\n");
set (SPEED, 9);
if (master_timer.get_time() > MASTER_TIMEOUT) {
printf ("Master Timer Timeout!!\n");
return TASK_MISSING;
}
else if (vision_code == FULL_DETECT) {
printf ("FAST Foward: Full Detect\n");
//int ang_x = gate_vision.get_angular_x();
//set_yaw_change(ang_x);
if (gate_vision.get_range() < 420) {
done_gate = true;
printf ("Range = %d, Approaching Gate\n", gate_vision.get_range());
}
timer.restart();
full_detect_timer.restart();
master_timer.restart();
}
/*if (gate_vision.latest_frame_is_valid()) {
set (SPEED, 0);
master_timer.restart();
timer.restart();
gate_vision.clear_frames();
state = SLOW_FOWARD;
}*/
}
else if (state == SLOW_FOWARD) {
printf ("Slow Foward: Moving foward a little\n");
set (SPEED, 4);
if (timer.get_time() > 3) {
timer.restart();
gate_vision.clear_frames();
state = PANNING;
}
else if (vision_code == FULL_DETECT) {
printf ("Slow Foward: Full Detect\n");
int ang_x = gate_vision.get_angular_x();
set_yaw_change(ang_x);
if (gate_vision.get_range() < 420) {
done_gate = true;
printf ("Range = %d, Approaching Gate\n", gate_vision.get_range());
//.........这里部分代码省略.........
示例10: PeekMessageEx
//.........这里部分代码省略.........
}
UNLOCK_MSGQ (pMsgQueue);
return TRUE;
}
#endif
pMsg->message = MSG_PAINT;
pMsg->wParam = 0;
pMsg->lParam = 0;
SET_PADD (NULL);
#ifdef _LITE_VERSION
pHostingRoot = __mg_dsk_win;
#else
pHostingRoot = pMsgQueue->pRootMainWin;
#endif
if ( (hNeedPaint = msgCheckHostedTree (pHostingRoot)) ) {
pMsg->hwnd = hNeedPaint;
pWin = (PMAINWIN) hNeedPaint;
pMsg->lParam = (LPARAM)(&pWin->InvRgn.rgn);
UNLOCK_MSGQ (pMsgQueue);
return TRUE;
}
/* no paint message */
pMsgQueue->dwState &= ~QS_PAINT;
}
/*
* handle timer here
*/
#ifdef _LITE_VERSION
if (pMsgQueue->dwState & QS_DESKTIMER) {
pMsg->hwnd = HWND_DESKTOP;
pMsg->message = MSG_TIMER;
pMsg->wParam = 0;
pMsg->lParam = 0;
if (uRemoveMsg == PM_REMOVE) {
pMsgQueue->dwState &= ~QS_DESKTIMER;
}
return TRUE;
}
#endif
if (pMsgQueue->TimerMask && IS_MSG_WANTED(MSG_TIMER)) {
int slot;
TIMER* timer;
#ifndef _LITE_VERSION
if (hWnd == HWND_DESKTOP) {
pMsg->hwnd = hWnd;
pMsg->message = MSG_TIMER;
pMsg->wParam = 0;
pMsg->lParam = 0;
SET_PADD (NULL);
if (uRemoveMsg == PM_REMOVE) {
pMsgQueue->TimerMask = 0;
}
UNLOCK_MSGQ (pMsgQueue);
return TRUE;
}
#endif
示例11: UpdateFrame
//Perform per-frame updates
void UpdateFrame()
{
//set currentTime and timePassed
static double lastTime=timer.GetTime();
double currentTime=timer.GetTime();
double timePassed=currentTime-lastTime;
lastTime=currentTime;
//Update window
WINDOW::Instance()->Update();
//Update the lights
for(int i=0; i<numLights; ++i)
{
lights[i].position+=lights[i].velocity*float(timePassed)/1000;
//bounce off the borders
if(lights[i].position.x>1.0f && lights[i].velocity.x>0.0f)
lights[i].velocity.x=-lights[i].velocity.x;
if(lights[i].position.x<-1.0f && lights[i].velocity.x<0.0f)
lights[i].velocity.x=-lights[i].velocity.x;
if(lights[i].position.z>1.0f && lights[i].velocity.z>0.0f)
lights[i].velocity.z=-lights[i].velocity.z;
if(lights[i].position.z<-1.0f && lights[i].velocity.z<0.0f)
lights[i].velocity.z=-lights[i].velocity.z;
}
//Toggle vertex program/fixed function
if(WINDOW::Instance()->IsKeyPressed('1') && GLEE_NV_vertex_program)
{
useVP1=true;
useVP2=false;
useFixedFunction=false;
}
if(WINDOW::Instance()->IsKeyPressed('2') && GLEE_NV_vertex_program2)
{
useVP1=false;
useVP2=true;
useFixedFunction=false;
}
if(WINDOW::Instance()->IsKeyPressed('3'))
{
useVP1=false;
useVP2=false;
useFixedFunction=true;
}
//Render frame
RenderFrame(currentTime, timePassed);
}
示例12: Keyboard
//Called when a key is pressed
void Keyboard(unsigned char key, int x, int y)
{
//If escape is pressed, exit
if(key==27)
exit(0);
//Use P to pause the animation and U to unpause
if(key=='P' || key=='p')
timer.Pause();
if(key=='U' || key=='u')
timer.Unpause();
}
示例13: DemoInit
//Set up variables
bool DemoInit()
{
if(!window.Init("Metaballs", 512, 512, 32, 24, 8, WINDOWED_SCREEN))
return 0; //quit if not created
//set up grid
if(!cubeGrid.CreateMemory())
return false;
if(!cubeGrid.Init(gridSize))
return false;
//set up metaballs
for(int i=0; i<numMetaballs; i++)
metaballs[i].Init(VECTOR3D(0.0f, 0.0f, 0.0f), 5.0f+float(i));
//Set Up Colors
diffuseColors[0].Set(0.345f, 0.843f, 0.902f, 1.0f);
diffuseColors[1].Set(0.047f, 0.839f, 0.271f, 1.0f);
diffuseColors[2].Set(0.976f, 0.213f, 0.847f, 1.0f);
//reset timer for start
timer.Reset();
return true;
}
示例14: StateGraphicsNext
void StateGraphicsNext(int state)
{
if (StateGraphics == state)
{
return;
}
StateGraphicsTimer.Reset();
StateGraphicsLast = StateGraphics;
StateGraphics = state;
// The visual target first appears in this state, so set graphics sync timer.
if (StateGraphics == STATE_GO)
{
// Set graphics sync timer relative to offset of next vertical retrace.
GraphicsTargetTimer.Reset(-GRAPHICS_VerticalRetraceOffsetTimeUntilNext());
}
}
示例15: GraphicsScene
void GraphicsScene(void) // this is created by shyeo, isolating the gl routines only from GraphicsDisplay
{
int attr;
static matrix posn;
// Display text.
strncpy(GraphicsString, StateText[StateGraphics], STRLEN);
GraphicsDisplayText();
// Display rotating teapot during rest period.
if (StateGraphics == STATE_REST)
{
glPushMatrix();
GRAPHICS_ColorSet(GREEN);
glRotated(ExperimentTimer.ElapsedSeconds() * 10.0 * PI, 1.0, 1.0, 1.0);
glutWireTeapot(10.0);
glPopMatrix();
return;
}
// Display home position at start of trial.
if ((StateGraphics >= STATE_SETUP) && (StateGraphics <= STATE_MOVING))
{
attr = RobotHome() ? HomeColor : NotHomeColor;
//GRAPHICS_Circle(&StartPosition, HomeRadius, attr);
GRAPHICS_Sphere(&StartPosition, HomeRadius, attr);
}
// Display target spheres when trial running.
if ((StateGraphics >= STATE_GO) && (StateGraphics <= STATE_FINISH))
{
// Display target for movement.
GRAPHICS_Sphere(&TargetPosition, TargetRadius, TargetColor);
// Display graphics sync target for phototransistor.
if (!GraphicsSyncPosition.iszero())
{
GRAPHICS_Sphere(&GraphicsSyncPosition, GraphicsSyncRadius, GraphicsSyncColor);
}
}
// Display finish position.
if ((StateGraphics > STATE_MOVING) && (StateGraphics <= STATE_INTERTRIAL))
{
attr = RobotHome() ? HomeColor : NotHomeColor;
GRAPHICS_Sphere(&FinishPosition, HomeRadius, attr);
}
// Display robot position cursor.
if ((StateGraphics != STATE_ERROR) && (VisualFeedback || RobotHome()))
{
posn = CursorPosition;
posn(3, 1) += 2.0*HomeRadius;
GRAPHICS_Sphere(&posn, CursorRadius, CursorColor);
}
}