1c43e99fdSEd Maste /* 2c43e99fdSEd Maste * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3c43e99fdSEd Maste * 4c43e99fdSEd Maste * Redistribution and use in source and binary forms, with or without 5c43e99fdSEd Maste * modification, are permitted provided that the following conditions 6c43e99fdSEd Maste * are met: 7c43e99fdSEd Maste * 1. Redistributions of source code must retain the above copyright 8c43e99fdSEd Maste * notice, this list of conditions and the following disclaimer. 9c43e99fdSEd Maste * 2. Redistributions in binary form must reproduce the above copyright 10c43e99fdSEd Maste * notice, this list of conditions and the following disclaimer in the 11c43e99fdSEd Maste * documentation and/or other materials provided with the distribution. 12c43e99fdSEd Maste * 3. The name of the author may not be used to endorse or promote products 13c43e99fdSEd Maste * derived from this software without specific prior written permission. 14c43e99fdSEd Maste * 15c43e99fdSEd Maste * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16c43e99fdSEd Maste * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17c43e99fdSEd Maste * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18c43e99fdSEd Maste * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19c43e99fdSEd Maste * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20c43e99fdSEd Maste * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21c43e99fdSEd Maste * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22c43e99fdSEd Maste * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23c43e99fdSEd Maste * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24c43e99fdSEd Maste * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25c43e99fdSEd Maste */ 26c43e99fdSEd Maste 27c43e99fdSEd Maste #ifndef REGRESS_THREAD_H_INCLUDED_ 28c43e99fdSEd Maste #define REGRESS_THREAD_H_INCLUDED_ 29c43e99fdSEd Maste 30*b50261e2SCy Schubert #if defined(_WIN32) /** _WIN32 */ 31*b50261e2SCy Schubert #define THREAD_T void * /* HANDLE */ 32*b50261e2SCy Schubert #define THREAD_FN unsigned __stdcall 33*b50261e2SCy Schubert #define THREAD_RETURN() return (0) 34*b50261e2SCy Schubert #define THREAD_SELF() GetCurrentThreadId() 35*b50261e2SCy Schubert #define THREAD_START(threadvar, fn, arg) do { \ 36*b50261e2SCy Schubert uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ 37*b50261e2SCy Schubert (threadvar) = (THREAD_T)threadhandle; \ 38*b50261e2SCy Schubert thread_setup(threadvar); \ 39*b50261e2SCy Schubert } while (0) 40*b50261e2SCy Schubert #define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) 41*b50261e2SCy Schubert #else /* !_WIN32 */ 42*b50261e2SCy Schubert #include <pthread.h> 43c43e99fdSEd Maste #define THREAD_T pthread_t 44c43e99fdSEd Maste #define THREAD_FN void * 45c43e99fdSEd Maste #define THREAD_RETURN() return (NULL) 46*b50261e2SCy Schubert #define THREAD_SELF() pthread_self() 47c43e99fdSEd Maste #define THREAD_START(threadvar, fn, arg) do { \ 48*b50261e2SCy Schubert if (!pthread_create(&(threadvar), NULL, fn, arg)) \ 49*b50261e2SCy Schubert thread_setup(threadvar); \ 50c43e99fdSEd Maste } while (0) 51*b50261e2SCy Schubert #define THREAD_JOIN(th) pthread_join(th, NULL) 52*b50261e2SCy Schubert #endif /* \!_WIN32 */ 53*b50261e2SCy Schubert 54*b50261e2SCy Schubert void thread_setup(THREAD_T pthread); 55c43e99fdSEd Maste 56c43e99fdSEd Maste #endif 57