OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2007 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 // Helper function for using Cocoa with Posix threading. | 10 // Helper function for using Cocoa with Posix threading. |
11 | 11 |
12 #import <assert.h> | |
13 #import <Foundation/Foundation.h> | 12 #import <Foundation/Foundation.h> |
14 | 13 |
15 #import "webrtc/base/maccocoathreadhelper.h" | 14 #import "webrtc/base/maccocoathreadhelper.h" |
16 | 15 |
| 16 #include "webrtc/base/checks.h" |
| 17 |
17 namespace rtc { | 18 namespace rtc { |
18 | 19 |
19 // Cocoa must be "put into multithreading mode" before Cocoa functionality can | 20 // Cocoa must be "put into multithreading mode" before Cocoa functionality can |
20 // be used on POSIX threads. The way to do that is to spawn one thread that may | 21 // be used on POSIX threads. The way to do that is to spawn one thread that may |
21 // immediately exit. | 22 // immediately exit. |
22 void InitCocoaMultiThreading() { | 23 void InitCocoaMultiThreading() { |
23 if ([NSThread isMultiThreaded] == NO) { | 24 if ([NSThread isMultiThreaded] == NO) { |
24 // The sole purpose of this autorelease pool is to avoid a console | 25 // The sole purpose of this autorelease pool is to avoid a console |
25 // message on Leopard that tells us we're autoreleasing the thread | 26 // message on Leopard that tells us we're autoreleasing the thread |
26 // with no autorelease pool in place. | 27 // with no autorelease pool in place. |
27 // Doing NSAutoreleasePool* hack = [[NSAutoreleasePool alloc] init]; | 28 // Doing NSAutoreleasePool* hack = [[NSAutoreleasePool alloc] init]; |
28 // causes unused variable error. | 29 // causes unused variable error. |
29 NSAutoreleasePool* hack; | 30 NSAutoreleasePool* hack; |
30 hack = [[NSAutoreleasePool alloc] init]; | 31 hack = [[NSAutoreleasePool alloc] init]; |
31 [NSThread detachNewThreadSelector:@selector(class) | 32 [NSThread detachNewThreadSelector:@selector(class) |
32 toTarget:[NSObject class] | 33 toTarget:[NSObject class] |
33 withObject:nil]; | 34 withObject:nil]; |
34 [hack drain]; | 35 [hack drain]; |
35 } | 36 } |
36 | 37 |
37 assert([NSThread isMultiThreaded]); | 38 RTC_DCHECK([NSThread isMultiThreaded]); |
38 } | 39 } |
39 | 40 |
40 } // namespace rtc | 41 } // namespace rtc |
OLD | NEW |