dispatch_timer_bit63.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Copyright (c) 2008-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 <assert.h>
  21. #include <stdio.h>
  22. #include <string.h>
  23. #if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
  24. #include <sys/time.h>
  25. #endif
  26. #include <dispatch/dispatch.h>
  27. #include <bsdtests.h>
  28. #include "dispatch_test.h"
  29. static void
  30. test_timer(void)
  31. {
  32. dispatch_test_start("Dispatch Source Timer, bit 63");
  33. //uint64_t interval = 0xffffffffffffffffull;
  34. uint64_t interval = 0x8000000000000001ull;
  35. dispatch_queue_t mainq = dispatch_get_main_queue();
  36. __block int i = 0;
  37. struct timeval start_time;
  38. gettimeofday(&start_time, NULL);
  39. static dispatch_source_t ds;
  40. ds = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, mainq);
  41. assert(ds);
  42. dispatch_source_set_event_handler(ds, ^{
  43. assert(i < 1);
  44. printf("%d\n", i++);
  45. });
  46. dispatch_source_set_timer(ds, DISPATCH_TIME_NOW, interval, 0);
  47. dispatch_resume(ds);
  48. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1*NSEC_PER_SEC),
  49. dispatch_get_main_queue(), ^{
  50. test_stop();
  51. });
  52. }
  53. int
  54. main(void)
  55. {
  56. test_timer();
  57. dispatch_main();
  58. return 0;
  59. }