• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Product
    • Design UI
    • Develop
    • Analyze and test
    • Deploy
    • Framework and toolbox
    • Compatibility
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • OSAPIPeriodicTimer
  • 4.12.9

OSAPIPeriodicTimer Class

The OSAPIPeriodicTimer is a high-resolution timer for periodic thread scheduling. More...

Header: #include <OSAPI/Timer/Timer.h>
Inherited By:

OSAPIOneShotTimer

  • List of all members, including inherited members

Public Functions

OSAPIPeriodicTimer()
virtual ~OSAPIPeriodicTimer()
void Destroy()
int SetEvent()
virtual int Start(int periodInMs)
virtual void Stop()
int WaitForEvent()

Detailed Description

The OSAPIPeriodicTimer is a high-resolution timer for periodic thread scheduling.

The WaitForEvent() method will wait for either a timer event or an event caused by a call to SetEvent().

Note that the timer will not catch up on missed events. This means that if we start the timer with a period set to 100ms, waiting 550 ms before executing WaitForEvent will make the function return immedeatly the first time and then continue its periods.

time      ----|---|---|---|---|---|---|---|---|---|---|---
event     ----*---*---*---*-----*-*---*---------*-*---*---

Usage

// In some thread's Main()
threadTimer.Start(PeriodInMS);
// ...

while(!Stopped())
{
  // Wait for timer tick or message event, set timerevent if timer event
  int event = threadTimer.WaitForEvent()
  if (event==0)
  {
    // Handle timer event
  }
  else if (event==1)
  {
    // Handle event caused by SetEvent()
  }
  else
  {
    // New events may be added in the future..
  }
}
threadTimer.Stop(); //

See also OSAPIOneShotTimer, CDPTimer, CDPParameterTimer, CDPTimerMs, CDPParameterTimerMs, CDPTimerCounting, and CDPRampTimer.

Member Function Documentation

OSAPIPeriodicTimer::OSAPIPeriodicTimer()

Constructs an OSAPIPeriodicTimer.

[virtual] OSAPIPeriodicTimer::~OSAPIPeriodicTimer()

Destructs the timer.

void OSAPIPeriodicTimer::Destroy()

Stops the timer and releases allocated resources.

int OSAPIPeriodicTimer::SetEvent()

Releases WaitForEvent() by signaling the event object.

Returns 0 on failure.

[virtual] int OSAPIPeriodicTimer::Start(int periodInMs)

Starts the timer.

periodInMs - Timer period in ms.

Returns: Event handle != 0 on success.

[virtual] void OSAPIPeriodicTimer::Stop()

Stops the timer.

int OSAPIPeriodicTimer::WaitForEvent()

Waits for timer event or event set by SetEvent().

Blocks calling thread until timer event or semaphore event occurs.

Returns 1 if event occured, 0 if timer tick occured. Supposed to return 0 if both event and timer tick occured.

Dependent implementation

  • WINDOWS: Uses timer functions SetWaitableTimer() / WaitForMultipleObjects();
  • Linux: Uses Mutex and timed condition variable (OSAPIEvent)

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2024 CDP Technologies. Privacy and cookie policy.

Return to top