1290001Sglebius/*
2290001Sglebius * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
3290001Sglebius *
4290001Sglebius * Redistribution and use in source and binary forms, with or without
5290001Sglebius * modification, are permitted provided that the following conditions
6290001Sglebius * are met:
7290001Sglebius * 1. Redistributions of source code must retain the above copyright
8290001Sglebius *    notice, this list of conditions and the following disclaimer.
9290001Sglebius * 2. Redistributions in binary form must reproduce the above copyright
10290001Sglebius *    notice, this list of conditions and the following disclaimer in the
11290001Sglebius *    documentation and/or other materials provided with the distribution.
12290001Sglebius * 3. The name of the author may not be used to endorse or promote products
13290001Sglebius *    derived from this software without specific prior written permission.
14290001Sglebius *
15290001Sglebius * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16290001Sglebius * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17290001Sglebius * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18290001Sglebius * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19290001Sglebius * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20290001Sglebius * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21290001Sglebius * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22290001Sglebius * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23290001Sglebius * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24290001Sglebius * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25290001Sglebius */
26290001Sglebius
27290001Sglebius#ifndef REGRESS_THREAD_H_INCLUDED_
28290001Sglebius#define REGRESS_THREAD_H_INCLUDED_
29290001Sglebius
30290001Sglebius#ifdef EVENT__HAVE_PTHREADS
31290001Sglebius#define THREAD_T pthread_t
32290001Sglebius#define THREAD_FN void *
33290001Sglebius#define THREAD_RETURN() return (NULL)
34290001Sglebius#define THREAD_START(threadvar, fn, arg) \
35290001Sglebius	pthread_create(&(threadvar), NULL, fn, arg)
36290001Sglebius#define THREAD_JOIN(th) pthread_join(th, NULL)
37290001Sglebius#else
38290001Sglebius#define THREAD_T HANDLE
39290001Sglebius#define THREAD_FN unsigned __stdcall
40290001Sglebius#define THREAD_RETURN() return (0)
41290001Sglebius#define THREAD_START(threadvar, fn, arg) do {		\
42290001Sglebius	uintptr_t threadhandle = _beginthreadex(NULL,0,fn,(arg),0,NULL); \
43290001Sglebius	(threadvar) = (HANDLE) threadhandle; \
44290001Sglebius	} while (0)
45290001Sglebius#define THREAD_JOIN(th) WaitForSingleObject(th, INFINITE)
46290001Sglebius#endif
47290001Sglebius
48290001Sglebius#endif
49