diff options
Diffstat (limited to 'lib/thread.h')
| -rw-r--r-- | lib/thread.h | 128 |
1 files changed, 53 insertions, 75 deletions
diff --git a/lib/thread.h b/lib/thread.h index 6cb7896e7d..218672c7bf 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -13,10 +13,9 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * - * You should have received a copy of the GNU General Public License - * along with GNU Zebra; see the file COPYING. If not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _ZEBRA_THREAD_H @@ -24,6 +23,7 @@ #include <zebra.h> #include "monotime.h" +#include <pthread.h> struct rusage_t { @@ -84,6 +84,10 @@ struct thread_master int fd_limit; struct fd_handler handler; unsigned long alloc; + long selectpoll_timeout; + bool spin; + bool handle_signals; + pthread_mutex_t mtx; }; typedef unsigned char thread_type; @@ -91,25 +95,27 @@ typedef unsigned char thread_type; /* Thread itself. */ struct thread { - thread_type type; /* thread type */ - thread_type add_type; /* thread type */ - struct thread *next; /* next pointer of the thread */ - struct thread *prev; /* previous pointer of the thread */ - struct thread_master *master; /* pointer to the struct thread_master. */ - int (*func) (struct thread *); /* event function */ - void *arg; /* event argument */ + thread_type type; /* thread type */ + thread_type add_type; /* thread type */ + struct thread *next; /* next pointer of the thread */ + struct thread *prev; /* previous pointer of the thread */ + struct thread **ref; /* external reference (if given) */ + struct thread_master *master; /* pointer to the struct thread_master */ + int (*func) (struct thread *); /* event function */ + void *arg; /* event argument */ union { - int val; /* second argument of the event. */ - int fd; /* file descriptor in case of read/write. */ - struct timeval sands; /* rest of time sands value. */ + int val; /* second argument of the event. */ + int fd; /* file descriptor in case of r/w */ + struct timeval sands; /* rest of time sands value. */ } u; - int index; /* used for timers to store position in queue */ + int index; /* queue position for timers */ struct timeval real; - struct cpu_thread_history *hist; /* cache pointer to cpu_history */ - unsigned long yield; /* yield time in us */ - const char *funcname; - const char *schedfrom; - int schedfrom_line; + struct cpu_thread_history *hist; /* cache pointer to cpu_history */ + unsigned long yield; /* yield time in microseconds */ + const char *funcname; /* name of thread function */ + const char *schedfrom; /* source file thread was scheduled from */ + int schedfrom_line; /* line number of source file */ + pthread_mutex_t mtx; /* mutex for thread.c functions */ }; struct cpu_thread_history @@ -147,30 +153,6 @@ struct cpu_thread_history #define THREAD_FD(X) ((X)->u.fd) #define THREAD_VAL(X) ((X)->u.val) -#define THREAD_READ_ON(master,thread,func,arg,sock) \ - do { \ - if (! thread) \ - thread = thread_add_read (master, func, arg, sock); \ - } while (0) - -#define THREAD_WRITE_ON(master,thread,func,arg,sock) \ - do { \ - if (! thread) \ - thread = thread_add_write (master, func, arg, sock); \ - } while (0) - -#define THREAD_TIMER_ON(master,thread,func,arg,time) \ - do { \ - if (! thread) \ - thread = thread_add_timer (master, func, arg, time); \ - } while (0) - -#define THREAD_TIMER_MSEC_ON(master,thread,func,arg,time) \ - do { \ - if (! thread) \ - thread = thread_add_timer_msec (master, func, arg, time); \ - } while (0) - #define THREAD_OFF(thread) \ do { \ if (thread) \ @@ -186,46 +168,42 @@ struct cpu_thread_history #define debugargdef const char *funcname, const char *schedfrom, int fromln -#define thread_add_read(m,f,a,v) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_write(m,f,a,v) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_timer(m,f,a,v) funcname_thread_add_timer(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_timer_msec(m,f,a,v) funcname_thread_add_timer_msec(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_timer_tv(m,f,a,v) funcname_thread_add_timer_tv(m,f,a,v,#f,__FILE__,__LINE__) -#define thread_add_event(m,f,a,v) funcname_thread_add_event(m,f,a,v,#f,__FILE__,__LINE__) +#define thread_add_read(m,f,a,v,t) funcname_thread_add_read_write(THREAD_READ,m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_write(m,f,a,v,t) funcname_thread_add_read_write(THREAD_WRITE,m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_timer(m,f,a,v,t) funcname_thread_add_timer(m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_timer_msec(m,f,a,v,t) funcname_thread_add_timer_msec(m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_timer_tv(m,f,a,v,t) funcname_thread_add_timer_tv(m,f,a,v,t,#f,__FILE__,__LINE__) +#define thread_add_event(m,f,a,v,t) funcname_thread_add_event(m,f,a,v,t,#f,__FILE__,__LINE__) #define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f,__FILE__,__LINE__) /* The 4th arg to thread_add_background is the # of milliseconds to delay. */ -#define thread_add_background(m,f,a,v) funcname_thread_add_background(m,f,a,v,#f,__FILE__,__LINE__) +#define thread_add_background(m,f,a,v,t) funcname_thread_add_background(m,f,a,v,t,#f,__FILE__,__LINE__) /* Prototypes. */ extern struct thread_master *thread_master_create (void); extern void thread_master_free (struct thread_master *); extern void thread_master_free_unused(struct thread_master *); -extern struct thread *funcname_thread_add_read_write (int dir, struct thread_master *, - int (*)(struct thread *), - void *, int, debugargdef); -extern struct thread *funcname_thread_add_timer (struct thread_master *, - int (*)(struct thread *), - void *, long, debugargdef); -extern struct thread *funcname_thread_add_timer_msec (struct thread_master *, - int (*)(struct thread *), - void *, long, debugargdef); -extern struct thread *funcname_thread_add_timer_tv (struct thread_master *, - int (*)(struct thread *), - void *, struct timeval *, - debugargdef); -extern struct thread *funcname_thread_add_event (struct thread_master *, - int (*)(struct thread *), - void *, int, debugargdef); -extern struct thread *funcname_thread_add_background (struct thread_master *, - int (*func)(struct thread *), - void *arg, - long milliseconds_to_delay, - debugargdef); -extern struct thread *funcname_thread_execute (struct thread_master *, - int (*)(struct thread *), - void *, int, debugargdef); +extern struct thread * funcname_thread_add_read_write (int dir, struct thread_master *, + int (*)(struct thread *), void *, int, struct thread **, debugargdef); + +extern struct thread * funcname_thread_add_timer (struct thread_master *, + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + +extern struct thread * funcname_thread_add_timer_msec (struct thread_master *, + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + +extern struct thread * funcname_thread_add_timer_tv (struct thread_master *, + int (*)(struct thread *), void *, struct timeval *, struct thread **, debugargdef); + +extern struct thread * funcname_thread_add_event (struct thread_master *, + int (*)(struct thread *), void *, int, struct thread **, debugargdef); + +extern struct thread * funcname_thread_add_background (struct thread_master *, + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + +extern void funcname_thread_execute (struct thread_master *, + int (*)(struct thread *), void *, int, debugargdef); #undef debugargdef extern void thread_cancel (struct thread *); |
