dispatch_apply_gc.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (c) 2009-2011 Apple Inc. All rights reserved.
  3. *
  4. * @APPLE_APACHE_LICENSE_HEADER_START@
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. * @APPLE_APACHE_LICENSE_HEADER_END@
  19. */
  20. #include <dispatch/dispatch.h>
  21. #import <Foundation/Foundation.h>
  22. #include <libkern/OSAtomic.h>
  23. #include <bsdtests.h>
  24. #include "dispatch_test.h"
  25. #if __OBJC_GC__
  26. const size_t final = 50000, desclen = 538892;
  27. #else
  28. const size_t final = 1000, desclen = 8892;
  29. #endif
  30. NSAutoreleasePool *pool = nil;
  31. static void
  32. work(void* ctxt __attribute__((unused)))
  33. {
  34. pool = [[NSAutoreleasePool alloc] init];
  35. NSMutableArray *a = [NSMutableArray array];
  36. OSSpinLock sl = OS_SPINLOCK_INIT, *l = &sl;
  37. dispatch_apply(final, dispatch_get_global_queue(0, 0), ^(size_t i){
  38. NSDecimalNumber *n = [NSDecimalNumber decimalNumberWithDecimal:
  39. [[NSNumber numberWithInteger:i] decimalValue]];
  40. OSSpinLockLock(l);
  41. [a addObject:n];
  42. OSSpinLockUnlock(l);
  43. });
  44. test_long("count", [a count], final);
  45. test_long("description length", [[a description] length], desclen);
  46. a = nil;
  47. [pool drain];
  48. test_stop_after_delay((void*)(intptr_t)1);
  49. }
  50. int
  51. main(void)
  52. {
  53. dispatch_test_start("Dispatch Apply GC"); // <rdar://problem/7455071>
  54. dispatch_async_f(dispatch_get_main_queue(), (void*)(intptr_t)1, work);
  55. CFRunLoopRun();
  56. return 0;
  57. }