diff options
| author | Russ White <russ@riw.us> | 2017-05-10 13:51:47 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-10 13:51:47 -0400 |
| commit | 00a1578051ceeb26b0b9c2c3344cac1f202e047d (patch) | |
| tree | 248b55b1ab56e39025d9902c53564286558eda60 /lib/thread.h | |
| parent | 0896b755080b300116d493444bfc05e2ef7ca9f6 (diff) | |
| parent | c94671b82f790492ceee226f98a65ad7e7e09967 (diff) | |
Merge pull request #408 from qlyoung/remove-thread-macros
*: remove THREAD_ON macros, add nullity check
Diffstat (limited to 'lib/thread.h')
| -rw-r--r-- | lib/thread.h | 117 |
1 files changed, 45 insertions, 72 deletions
diff --git a/lib/thread.h b/lib/thread.h index 6fb6ad7c9d..3eaae8883b 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -96,26 +96,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; - pthread_mutex_t mtx; + 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 @@ -153,30 +154,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) \ @@ -192,46 +169,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 void funcname_thread_add_read_write (int dir, struct thread_master *, + int (*)(struct thread *), void *, int, struct thread **, debugargdef); + +extern void funcname_thread_add_timer (struct thread_master *, + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + +extern void funcname_thread_add_timer_msec (struct thread_master *, + int (*)(struct thread *), void *, long, struct thread **, debugargdef); + +extern void funcname_thread_add_timer_tv (struct thread_master *, + int (*)(struct thread *), void *, struct timeval *, struct thread **, debugargdef); + +extern void funcname_thread_add_event (struct thread_master *, + int (*)(struct thread *), void *, int, struct thread **, debugargdef); + +extern void 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 *); |
