1 /* thread-util.h
2  * Definitions for thread utils
3  *
4  * Yersinia
5  * By David Barroso <tomac@yersinia.net> and Alfredo Andres <aandreswork@hotmail.com>
6  * Copyright 2005-2017 Alfredo Andres and David Barroso
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21  */
22 
23 #ifndef __THREAD_H__
24 #define __THREAD_H__
25 
26 #include <libnet.h>
27 
28 #ifdef HAVE_PTHREAD_H
29 #include <pthread.h>
30 #endif
31 
32 #define THREAD_TIMEOUT -2
33 
34 struct condsem {
35 	pthread_mutex_t mutex;
36 	pthread_cond_t condvar;
37 	u_int16_t value;
38 };
39 
40 typedef struct {
41     pthread_t id;
42     u_int8_t  stop;
43     pthread_mutex_t finished;
44 } THREAD;
45 
46 #define PTHREAD_JOIN(x) (pthread_mutex_lock(&(x)->finished))
47 
48 //int8_t  thread_create(pthread_t *, void *, void *);
49 int8_t  thread_create( THREAD *, void *, void *);
50 int8_t  thread_destroy_cancel(pthread_t);
51 int8_t  thread_destroy(THREAD *);
52 void    thread_error(char *, int8_t);
53 void    thread_libnet_error(char *, libnet_t *);
54 int8_t  thread_create_condsem(struct condsem *);
55 void    thread_delete_condsem(struct condsem *);
56 int8_t  thread_wait_cond(struct condsem *);
57 int8_t  thread_wait_cond_timed(struct condsem *, struct timeval *);
58 int8_t  thread_signal_cond(struct condsem *);
59 int8_t  thread_send_broadcast(struct condsem *, int8_t);
60 void   *thread_calloc_r(size_t);
61 void    thread_free_r(void *);
62 int     thread_usleep(unsigned long);
63 
64 #endif
65