-#if DEPLOYMENT_TARGET_WINDOWS
-struct _args {
- void *func;
- void *arg;
- HANDLE handle;
-};
-static unsigned __stdcall __CFWinThreadFunc(void *arg) {
- struct _args *args = (struct _args*)arg;
- ((void (*)(void *))args->func)(args->arg);
- CloseHandle(args->handle);
- CFAllocatorDeallocate(kCFAllocatorSystemDefault, arg);
- _endthreadex(0);
- return 0;
-}
-#endif
-
-CF_PRIVATE void *__CFStartSimpleThread(void *func, void *arg) {
-#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI || DEPLOYMENT_TARGET_LINUX || DEPLOYMENT_TARGET_FREEBSD
- pthread_attr_t attr;
- pthread_t tid = 0;
- pthread_attr_init(&attr);
- pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- pthread_attr_setstacksize(&attr, 60 * 1024); // 60K stack for our internal threads is sufficient
- OSMemoryBarrier(); // ensure arg is fully initialized and set in memory
- pthread_create(&tid, &attr, func, arg);
- pthread_attr_destroy(&attr);
-//warning CF: we dont actually know that a pthread_t is the same size as void *
- return (void *)tid;
-#elif DEPLOYMENT_TARGET_WINDOWS
- unsigned tid;
- struct _args *args = (struct _args*)CFAllocatorAllocate(kCFAllocatorSystemDefault, sizeof(struct _args), 0);
- if (__CFOASafe) __CFSetLastAllocationEventName(args, "CFUtilities (thread-args)");
- HANDLE handle;
- args->func = func;
- args->arg = arg;
- /* The thread is created suspended, because otherwise there would be a race between the assignment below of the handle field, and it's possible use in the thread func above. */
- args->handle = (HANDLE)_beginthreadex(NULL, 0, __CFWinThreadFunc, args, CREATE_SUSPENDED, &tid);
- handle = args->handle;
- ResumeThread(handle);
- return handle;
-#endif
-}
-
-