On 01/28/10 09:21, "Adam R Maxwell" <adam.maxw...@pnl.gov> wrote:
> I think the easiest (and best-performing) way to do this would be to use a > per-thread instance of BDSKTypeManager. I implemented this in my code, but > it's only minimally tested. The only slightly tricky part is observing > notifications, but that's not too bad. I forgot to mention that I profiled this and saw no performance difference vs. using the main thread singleton in +initialize. Using pthread_once isn't quite as elegant as dispatch_once, but it's still fast and allows lazy initialization. // do not access directly; only used because pthread_once doesn't pass a context pointer static BDSKTypeManager *_mainThreadSharedInstance = nil; static void __BDSKTypeManagerMainThreadInit() { _mainThreadSharedInstance = [BDSKTypeManager new]; } + (BDSKTypeManager *)sharedManager{ // singleton used on the main thread if (pthread_main_np()) { static pthread_once_t once = PTHREAD_ONCE_INIT; (void) pthread_once(&once, __BDSKTypeManagerMainThreadInit); return _mainThreadSharedInstance; } NSParameterAssert(pthread_main_np() == 0); // other threads get a new instance, saved in the thread's dictionary NSString *key = @"BDSKTypeManagerPerThreadKey"; BDSKTypeManager *manager = [[[NSThread currentThread] threadDictionary] objectForKey:key]; if (nil == manager) { manager = [self new]; [[[NSThread currentThread] threadDictionary] setObject:manager forKey:key]; [manager release]; } return manager; } ------------------------------------------------------------------------------ The Planet: dedicated and managed hosting, cloud storage, colocation Stay online with enterprise data centers and the best network in the business Choose flexible plans and management services without long-term contracts Personal 24x7 support from experience hosting pros just a phone call away. http://p.sf.net/sfu/theplanet-com _______________________________________________ Bibdesk-develop mailing list Bibdesk-develop@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-develop