IOLockSleepDeadline example in docu is wrong (won't compile)
IOLockSleepDeadline example in docu is wrong (won't compile)
- Subject: IOLockSleepDeadline example in docu is wrong (won't compile)
- From: Markus Hanauska <email@hidden>
- Date: Tue, 4 Sep 2007 14:22:38 +0200
Hi everyone!
I'm trying to sleep within my KEXT. I found the following source code
sample on Appel's side:
http://developer.apple.com/documentation/Porting/Conceptual/
PortingDrivers/other-iokit/chapter_3_section_4.html
Nice, but it does not work! I can't even compile it.
int nanoseconds_to_delay = 1000000; # 1 msec for an example
AbsoluteTime absinterval, deadline;
.
.
.
nanoseconds_to_absolutetime(nanoseconds_to_delay, &absinterval);
clock_absolutetime_interval_to_deadline(absinterval, &deadline);
IOLockSleepDeadline(lock, event, deadline, THREAD_UNINT);
nanoseconds_to_absolutetime and
clock_absolutetime_interval_to_deadline work with uint64_t and not
with AbsoluteTime.
extern void nanoseconds_to_absolutetime(
uint64_t nanoseconds,
uint64_t *result);
and
extern void clock_absolutetime_interval_to_deadline(
uint64_t abstime,
uint64_t *result);
But AbsoluteTime is defined as
typedef UnsignedWide AbsoluteTime;
And UnsignedWide is
#if defined(__BIG_ENDIAN__)
typedef struct UnsignedWide {
UInt32 hi;
UInt32 lo;
} UnsignedWide;
#elif defined(__LITTLE_ENDIAN__)
typedef struct UnsignedWide {
UInt32 lo;
UInt32 hi;
} UnsignedWide;
#else
#error Unknown endianess.
#endif
I can't cast a number to a struct. Publishing source code that is
supposed to not even compile is not only silly and confusing
programmers, it's outreight useless.
Seeing that the struct is endian safe, I assume I can do the following:
AbsoluteTime deadlineTime;
memcpy(&deadlineTime, deadline, sizeof(deadline));
correct?
--
Best Regards,
Markus Hanauska
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-kernel mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden