Problem with informEvery() under TargetRTS |
Category: |
C++
Purpose: |
Provide additional information about a problem which may be encountered when using the periodic timer function informEvery().
Intended Audience: |
All ObjecTime developers.
Applicable to: |
ObjecTime 5.0
Description: |
ObjecTime 5.0 introduced a new periodic timing service through the informEvery() function. Due to a difference in implementation, informEvery() behaves differently under SimulationRTS and TargetRTS. Assuming that there is a Timing SAP named "timer", the call
timer.informEvery(300);
will start a cyclic timer.
Under the SimulationRTS, the argument is interpreted as the number of clock "ticks" to expiration of the timer. The granularity of the "ticks" is in centi-seconds, thus the timer will generate a timeout signal every 3 seconds. This behaviour is consistent with the behaviour of the functions informAt() and informIn().
Under the TargetRTS, the only legal arguments to informEvery() is an RTTimespec. RTTimespec is a struct with two fields; tv_sec and tv_nsec. Depending on the sophistication of the compiler being used, the call informEvery(300) will either report an error or coerce the integer into an RTTimespec. The copy constructor for an RTTimespec struct treats a single integer argument in a constructor call as the value of the tv_sec field. In otherwords, the timer will be started, but it will generate a timeout every 300 seconds, or 5 minutes!
The recommended solution is to always use an RTTimespec in timing service requests. Assuming that there is a Timing SAP named "timer", the following example will start a periodic timer which generates a timeout signal every 3 seconds under SimulationRTS and TargetRTS:
RTTimespec t(3, 0);
timer.informEvery(t);
The g++ 2.7.1 compiler coerced an integer argument in informEvery() to an RTTimespec. The behaviour that you see will depend on how your compiler deals with automatic coercions.
Limitations: |
None
See also: |
ObjecTime5.0 "C++ Guide", p. 301 for more details on RTTimespec and its use in fnction calls.
Copyright © 1999, ObjecTime Limited. |