3

We are porting a linux app to macOS / iOS

The app uses a timer wheel and timer_t type. This type is not defined in time.h class of macOS as described in:

why is "timer_t" defined in "time.h" on Linux but not OS X

Also the methods timer_create(), timer_settime() and timer_delete() are not defined.

This is the class that I'm porting: https://github.com/OpenOverlayRouter/oor/blob/testing/oor/lib/timers.c

We found that maybe we can do this with NSTimer and Objective-C but I would like to do in C.

Can we do it in C? Which kernel libraries should we use?

Thanks

anacelto
  • 61
  • 7
  • 2
    What system calls use this `timer_t` type, and what does the code use them for? – thrig Jun 27 '17 at 17:00
  • We use it in a timer wheel algorithm https://stackoverflow.com/questions/867621/efficient-timer-algorithm – anacelto Jun 27 '17 at 17:24
  • I thought you said you were porting an application to macOS, but you're asking about how to port a library to allow you to _not_ port the application. Am I right? – Kusalananda Jun 27 '17 at 17:27
  • You're going to have to implement `timer_settime` on macOS, or rewrite that library to instead use some other timer callback scheme; maybe see how `libevent` or such implements timers on *BSD systems? – thrig Jun 28 '17 at 14:09
  • Yes, I have to implement timer_settime, timer_create, timer_delete and timer_t type, or search another way to provide the same function... @thrig – anacelto Jun 28 '17 at 14:41
  • I changed the question. I think that now it's more clear. @Kusalananda – anacelto Jun 28 '17 at 14:42

1 Answers1

3

After talking with Apple Support:

The most obvious candidate here is dispatch timer sources.

Now I'm working in other section of that project, after implementing the timers section I'll post more information about that if I found something interesting.

Siva
  • 9,017
  • 8
  • 56
  • 86
anacelto
  • 61
  • 7
  • 1
    Any news? I understand that `timer_create()` and family are timer functions from the POSIX *realtime* library; I'm not sure libdispatch would be the most obvious candidate for anything realtime? – RJVB Oct 03 '18 at 11:15
  • @RJVB crosspost: https://stackoverflow.com/questions/44807302/create-c-timer-in-macos/52905687#52905687 – b degnan Dec 24 '18 at 02:11