#ifndef __DISPATCH_INTERNAL__
#define __DISPATCH_INTERNAL__
#define __DISPATCH_BUILDING_DISPATCH__
#define __DISPATCH_INDIRECT__
#include "dispatch.h"
#include "base.h"
#include "time.h"
#include "queue.h"
#include "object.h"
#include "source.h"
#include "group.h"
#include "semaphore.h"
#include "once.h"
#include "benchmark.h"
#include "queue_private.h"
#include "source_private.h"
#include "private.h"
#include "legacy.h"
#ifndef DISPATCH_DEBUG
#define DISPATCH_DEBUG 0
#endif
#include <libkern/OSCrossEndian.h>
#include <libkern/OSAtomic.h>
#include <mach/boolean.h>
#include <mach/clock_types.h>
#include <mach/clock.h>
#include <mach/exception.h>
#include <mach/mach.h>
#include <mach/mach_error.h>
#include <mach/mach_host.h>
#include <mach/mach_interface.h>
#include <mach/mach_time.h>
#include <mach/mach_traps.h>
#include <mach/message.h>
#include <mach/mig_errors.h>
#include <mach/host_info.h>
#include <mach/notify.h>
#include <malloc/malloc.h>
#include <sys/event.h>
#include <sys/mount.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/syslimits.h>
#include <sys/socket.h>
#include <netinet/in.h>
#ifdef __BLOCKS__
#include <Block_private.h>
#include <Block.h>
#endif
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <search.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <unistd.h>
#define DISPATCH_NOINLINE __attribute__((noinline))
#ifdef NSEC_PER_SEC
#undef NSEC_PER_SEC
#endif
#ifdef USEC_PER_SEC
#undef USEC_PER_SEC
#endif
#ifdef NSEC_PER_USEC
#undef NSEC_PER_USEC
#endif
#define NSEC_PER_SEC 1000000000ull
#define USEC_PER_SEC 1000000ull
#define NSEC_PER_USEC 1000ull
#define fastpath(x) ((typeof(x))__builtin_expect((long)(x), ~0l))
#define slowpath(x) ((typeof(x))__builtin_expect((long)(x), 0l))
void _dispatch_bug(size_t line, long val) __attribute__((__noinline__));
void _dispatch_abort(size_t line, long val) __attribute__((__noinline__,__noreturn__));
void _dispatch_log(const char *msg, ...) __attribute__((__noinline__,__format__(printf,1,2)));
void _dispatch_logv(const char *msg, va_list) __attribute__((__noinline__,__format__(printf,1,0)));
#define dispatch_assert(e) do { \
if (__builtin_constant_p(e)) { \
char __compile_time_assert__[(bool)(e) ? 1 : -1] __attribute__((unused)); \
} else { \
typeof(e) _e = fastpath(e); \
if (DISPATCH_DEBUG && !_e) { \
_dispatch_abort(__LINE__, (long)_e); \
} \
} \
} while (0)
#define dispatch_assert_zero(e) do { \
if (__builtin_constant_p(e)) { \
char __compile_time_assert__[(bool)(!(e)) ? 1 : -1] __attribute__((unused)); \
} else { \
typeof(e) _e = slowpath(e); \
if (DISPATCH_DEBUG && _e) { \
_dispatch_abort(__LINE__, (long)_e); \
} \
} \
} while (0)
#define dispatch_assume(e) ({ \
typeof(e) _e = fastpath(e); \
if (!_e) { \
if (__builtin_constant_p(e)) { \
char __compile_time_assert__[(e) ? 1 : -1]; \
(void)__compile_time_assert__; \
} \
_dispatch_bug(__LINE__, (long)_e); \
} \
_e; \
})
#define dispatch_assume_zero(e) ({ \
typeof(e) _e = slowpath(e); \
if (_e) { \
if (__builtin_constant_p(e)) { \
char __compile_time_assert__[(e) ? -1 : 1]; \
(void)__compile_time_assert__; \
} \
_dispatch_bug(__LINE__, (long)_e); \
} \
_e; \
})
#define dispatch_debug_assert(e, msg, args...) do { \
if (__builtin_constant_p(e)) { \
char __compile_time_assert__[(bool)(e) ? 1 : -1] __attribute__((unused)); \
} else { \
typeof(e) _e = fastpath(e); \
if (DISPATCH_DEBUG && !_e) { \
_dispatch_log("%s() 0x%lx: " msg, __func__, (long)_e, ##args); \
abort(); \
} \
} \
} while (0)
#ifdef __BLOCKS__
dispatch_block_t _dispatch_Block_copy(dispatch_block_t block);
void _dispatch_call_block_and_release(void *block);
void _dispatch_call_block_and_release2(void *block, void *ctxt);
#endif
void dummy_function(void);
long dummy_function_r0(void);
#define _dispatch_debug(x, args...) \
({ \
if (DISPATCH_DEBUG) { \
_dispatch_log("libdispatch: %u\t%p\t" x, __LINE__, _dispatch_thread_self(), ##args); \
} \
})
#if DISPATCH_DEBUG
void dispatch_debug_kevents(struct kevent* kev, size_t count, const char* str);
#else
#define dispatch_debug_kevents(x, y, z)
#endif
uint64_t _dispatch_get_nanoseconds(void);
void _dispatch_source_drain_kevent(struct kevent *);
dispatch_source_t
_dispatch_source_create2(dispatch_source_t ds,
dispatch_source_attr_t attr,
void *context,
dispatch_source_handler_function_t handler);
void _dispatch_update_kq(const struct kevent *);
void _dispatch_run_timers(void);
struct timespec *_dispatch_get_next_timer_fire(struct timespec *howsoon);
dispatch_semaphore_t _dispatch_get_thread_semaphore(void);
void _dispatch_put_thread_semaphore(dispatch_semaphore_t);
bool _dispatch_source_testcancel(dispatch_source_t);
uint64_t _dispatch_timeout(dispatch_time_t when);
__private_extern__ bool _dispatch_safe_fork;
__private_extern__ struct _dispatch_hw_config_s {
uint32_t cc_max_active;
uint32_t cc_max_logical;
uint32_t cc_max_physical;
} _dispatch_hw_config;
#include "object_internal.h"
#include "hw_shims.h"
#include "os_shims.h"
#include "queue_internal.h"
#include "semaphore_internal.h"
#include "source_internal.h"
#define DISPATCH_VERIFY_MIG(x) do { \
if ((x) == MIG_REPLY_MISMATCH) { \
__crashreporter_info__ = "MIG_REPLY_MISMATCH"; \
_dispatch_hardware_crash(); \
} \
} while (0)
#if defined(__x86_64__) || defined(__i386__)
#define DISPATCH_CRASH(x) do { \
asm("mov %1, %0" : "=m" (__crashreporter_info__) : "c" ("BUG IN LIBDISPATCH: " x)); \
_dispatch_hardware_crash(); \
} while (0)
#define DISPATCH_CLIENT_CRASH(x) do { \
asm("mov %1, %0" : "=m" (__crashreporter_info__) : "c" ("BUG IN CLIENT OF LIBDISPATCH: " x)); \
_dispatch_hardware_crash(); \
} while (0)
#else
#define DISPATCH_CRASH(x) do { \
__crashreporter_info__ = "BUG IN LIBDISPATCH: " x; \
_dispatch_hardware_crash(); \
} while (0)
#define DISPATCH_CLIENT_CRASH(x) do { \
__crashreporter_info__ = "BUG IN CLIENT OF LIBDISPATCH: " x; \
_dispatch_hardware_crash(); \
} while (0)
#endif
#endif