ua_timer.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #ifndef UA_TIMER_H_
  5. #define UA_TIMER_H_
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. #include "ua_util.h"
  10. #include "ua_job.h"
  11. typedef void
  12. (*UA_RepeatedJobsListProcessCallback)(void *processContext, UA_Job *job);
  13. typedef struct {
  14. /* The linked list of jobs is sorted according to the execution timestamp. */
  15. SLIST_HEAD(RepeatedJobsSList, UA_RepeatedJob) repeatedJobs;
  16. /* Repeated jobs that shall be added or removed from the sorted list (with
  17. * atomic operations) */
  18. SLIST_HEAD(RepeatedJobsSList2, UA_RepeatedJob) addRemoveJobs;
  19. /* The callback to process jobs that have timed out */
  20. UA_RepeatedJobsListProcessCallback processCallback;
  21. void *processContext;
  22. } UA_RepeatedJobsList;
  23. /* Initialize the RepeatedJobsSList. Not thread-safe. */
  24. void
  25. UA_RepeatedJobsList_init(UA_RepeatedJobsList *rjl,
  26. UA_RepeatedJobsListProcessCallback processCallback,
  27. void *processContext);
  28. /* Add a repated job. Thread-safe, can be used in parallel and in parallel with
  29. * UA_RepeatedJobsList_process. */
  30. UA_StatusCode
  31. UA_RepeatedJobsList_addRepeatedJob(UA_RepeatedJobsList *rjl, const UA_Job job,
  32. const UA_UInt32 interval, UA_Guid *jobId);
  33. /* Remove a repated job. Thread-safe, can be used in parallel and in parallel
  34. * with UA_RepeatedJobsList_process. */
  35. UA_StatusCode
  36. UA_RepeatedJobsList_removeRepeatedJob(UA_RepeatedJobsList *rjl, const UA_Guid jobId);
  37. /* Process the repeated jobs that have timed out. Returns the timestamp of the
  38. * next scheduled repeated job. Not thread-safe. */
  39. UA_DateTime
  40. UA_RepeatedJobsList_process(UA_RepeatedJobsList *rjl, UA_DateTime nowMonotonic,
  41. UA_Boolean *dispatched);
  42. /* Remove all repeated jobs. Not thread-safe. */
  43. void
  44. UA_RepeatedJobsList_deleteMembers(UA_RepeatedJobsList *rjl);
  45. #ifdef __cplusplus
  46. } // extern "C"
  47. #endif
  48. #endif /* UA_TIMER_H_ */