12b15cb3dSCy Schubert /* 22b15cb3dSCy Schubert * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 32b15cb3dSCy Schubert * 42b15cb3dSCy Schubert * Redistribution and use in source and binary forms, with or without 52b15cb3dSCy Schubert * modification, are permitted provided that the following conditions 62b15cb3dSCy Schubert * are met: 72b15cb3dSCy Schubert * 1. Redistributions of source code must retain the above copyright 82b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer. 92b15cb3dSCy Schubert * 2. Redistributions in binary form must reproduce the above copyright 102b15cb3dSCy Schubert * notice, this list of conditions and the following disclaimer in the 112b15cb3dSCy Schubert * documentation and/or other materials provided with the distribution. 122b15cb3dSCy Schubert * 3. The name of the author may not be used to endorse or promote products 132b15cb3dSCy Schubert * derived from this software without specific prior written permission. 142b15cb3dSCy Schubert * 152b15cb3dSCy Schubert * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 162b15cb3dSCy Schubert * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 172b15cb3dSCy Schubert * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 182b15cb3dSCy Schubert * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 192b15cb3dSCy Schubert * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 202b15cb3dSCy Schubert * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 212b15cb3dSCy Schubert * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 222b15cb3dSCy Schubert * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 232b15cb3dSCy Schubert * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 242b15cb3dSCy Schubert * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 252b15cb3dSCy Schubert */ 262b15cb3dSCy Schubert 272b15cb3dSCy Schubert #ifndef REGRESS_THREAD_H_INCLUDED_ 282b15cb3dSCy Schubert #define REGRESS_THREAD_H_INCLUDED_ 292b15cb3dSCy Schubert 30*a466cc55SCy Schubert #if defined(_WIN32) /** _WIN32 */ 31*a466cc55SCy Schubert #define THREAD_T void * /* HANDLE */ 32*a466cc55SCy Schubert #define THREAD_FN unsigned __stdcall 33*a466cc55SCy Schubert #define THREAD_RETURN() return (0) 34*a466cc55SCy Schubert #define THREAD_SELF() GetCurrentThreadId() 35*a466cc55SCy Schubert #define THREAD_START(threadvar, fn, arg) do { \ 36*a466cc55SCy Schubert uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ 37*a466cc55SCy Schubert (threadvar) = (THREAD_T)threadhandle; \ 38*a466cc55SCy Schubert thread_setup(threadvar); \ 39*a466cc55SCy Schubert } while (0) 40*a466cc55SCy Schubert #define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) 41*a466cc55SCy Schubert #else /* !_WIN32 */ 42*a466cc55SCy Schubert #include <pthread.h> 432b15cb3dSCy Schubert #define THREAD_T pthread_t 442b15cb3dSCy Schubert #define THREAD_FN void * 452b15cb3dSCy Schubert #define THREAD_RETURN() return (NULL) 46*a466cc55SCy Schubert #define THREAD_SELF() pthread_self() 472b15cb3dSCy Schubert #define THREAD_START(threadvar, fn, arg) do { \ 48*a466cc55SCy Schubert if (!pthread_create(&(threadvar), NULL, fn, arg)) \ 49*a466cc55SCy Schubert thread_setup(threadvar); \ 502b15cb3dSCy Schubert } while (0) 51*a466cc55SCy Schubert #define THREAD_JOIN(th) pthread_join(th, NULL) 52*a466cc55SCy Schubert #endif /* \!_WIN32 */ 53*a466cc55SCy Schubert 54*a466cc55SCy Schubert void thread_setup(THREAD_T pthread); 552b15cb3dSCy Schubert 562b15cb3dSCy Schubert #endif 57