regress_thread.h revision 275970
1275970Scy/* 2275970Scy * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson 3275970Scy * 4275970Scy * Redistribution and use in source and binary forms, with or without 5275970Scy * modification, are permitted provided that the following conditions 6275970Scy * are met: 7275970Scy * 1. Redistributions of source code must retain the above copyright 8275970Scy * notice, this list of conditions and the following disclaimer. 9275970Scy * 2. Redistributions in binary form must reproduce the above copyright 10275970Scy * notice, this list of conditions and the following disclaimer in the 11275970Scy * documentation and/or other materials provided with the distribution. 12275970Scy * 3. The name of the author may not be used to endorse or promote products 13275970Scy * derived from this software without specific prior written permission. 14275970Scy * 15275970Scy * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16275970Scy * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17275970Scy * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18275970Scy * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19275970Scy * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20275970Scy * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21275970Scy * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22275970Scy * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23275970Scy * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24275970Scy * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25275970Scy */ 26275970Scy 27275970Scy#ifndef REGRESS_THREAD_H_INCLUDED_ 28275970Scy#define REGRESS_THREAD_H_INCLUDED_ 29275970Scy 30275970Scy#ifdef EVENT__HAVE_PTHREADS 31275970Scy#define THREAD_T pthread_t 32275970Scy#define THREAD_FN void * 33275970Scy#define THREAD_RETURN() return (NULL) 34275970Scy#define THREAD_START(threadvar, fn, arg) \ 35275970Scy pthread_create(&(threadvar), NULL, fn, arg) 36275970Scy#define THREAD_JOIN(th) pthread_join(th, NULL) 37275970Scy#else 38275970Scy#define THREAD_T HANDLE 39275970Scy#define THREAD_FN unsigned __stdcall 40275970Scy#define THREAD_RETURN() return (0) 41275970Scy#define THREAD_START(threadvar, fn, arg) do { \ 42275970Scy uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \ 43275970Scy (threadvar) = (HANDLE) threadhandle; \ 44275970Scy } while (0) 45275970Scy#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE) 46275970Scy#endif 47275970Scy 48275970Scy#endif 49