1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/platform_thread.h" 6 7 #import <Foundation/Foundation.h> 8 9 #include "base/logging.h" 10 11 // A simple class that demonstrates our impressive ability to do nothing. 12 @interface NoOp : NSObject 13 14 // Does the deed. Or does it? 15 + (void)noOp; 16 17 @end 18 19 @implementation NoOp 20 21 + (void)noOp { 22 } 23 24 @end 25 26 namespace base { 27 28 // If Cocoa is to be used on more than one thread, it must know that the 29 // application is multithreaded. Since it's possible to enter Cocoa code 30 // from threads created by pthread_thread_create, Cocoa won't necessarily 31 // be aware that the application is multithreaded. Spawning an NSThread is 32 // enough to get Cocoa to set up for multithreaded operation, so this is done 33 // if necessary before pthread_thread_create spawns any threads. 34 // 35 // http://developer.apple.com/documentation/Cocoa/Conceptual/Multithreading/CreatingThreads/chapter_4_section_4.html 36 void InitThreading() { 37 static BOOL multithreaded = [NSThread isMultiThreaded]; 38 if (!multithreaded) { 39 [NSThread detachNewThreadSelector:@selector(noOp) 40 toTarget:[NoOp class] 41 withObject:nil]; 42 multithreaded = YES; 43 44 DCHECK([NSThread isMultiThreaded]); 45 } 46 } 47 48 } // namespace base 49