Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: kqueue on OS X



Deric:

I am in the process of writing some kqueue sample code. Enclosed is an MP
based sample which watches three directories from its thread and posts a
CarbonEvent back to the main thread when something has changed.

This sample has not yet been reviewed, but you may find it useful. Please
let me know if you have any feedback.

Thanks for that, it was helpful.

My issue is simply this: I will run kqueue and kevent in a separate thread, as you have done. However I need to break into the kevent thread from my main event loop from time to time, to update the list of files to watch, e.g. when the file is closed from the GUI. This implies I need to send the kqueue some kind of event it recognizes. Now pipes and file descriptors seem dangerous to me, since they are not necessarily threadsafe (especially with Cocoa), and UNIX signal seems like overkill -- however if the kqueue could monitor a Mach port, well the main thread could interrupt it by sending it a Mach message.

That led me to look at sys/event.h, and discovering there EVFILT_MACHPORT and EVFILT_FS. Presumably for EVFILT_MACHPORT, the kqueue ident is a Mach port identifier? What kind of data could I expect, etc.?

Another thing you might want to look at re: your sample code is the usual OS X document save scheme (Cocoa for example, but I suppose the FSSpec file swap works the same way), which goes like:

1. Rename old file.
2. Save new file at old file's name.
3. Delete old file.

This means when I run a kqueue with EVFILT_VNODE, strangely enough I don't see the first rename, but I see the delete, at which stage the vnode I'm monitoring is defunct and I have to reopen the vnode to monitor again.

Cheers, Glen Low


---
pixelglow software | simply brilliant stuff
www.pixelglow.com
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.