Home | History | Annotate | Download | only in base
      1 /*
      2  *  Copyright 2007 The WebRTC Project Authors. All rights reserved.
      3  *
      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
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 // Helper function for using Cocoa with Posix threading.
     11 
     12 #import <assert.h>
     13 #import <Foundation/Foundation.h>
     14 
     15 #import "webrtc/base/maccocoathreadhelper.h"
     16 
     17 namespace rtc {
     18 
     19 // 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 // immediately exit.
     22 void InitCocoaMultiThreading() {
     23   if ([NSThread isMultiThreaded] == NO) {
     24     // 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     // with no autorelease pool in place.
     27     // Doing NSAutoreleasePool* hack = [[NSAutoreleasePool alloc] init];
     28     // causes unused variable error.
     29     NSAutoreleasePool* hack;
     30     hack = [[NSAutoreleasePool alloc] init];
     31     [NSThread detachNewThreadSelector:@selector(class)
     32                              toTarget:[NSObject class]
     33                            withObject:nil];
     34     [hack drain];
     35   }
     36 
     37   assert([NSThread isMultiThreaded]);
     38 }
     39 
     40 }  // namespace rtc
     41