diff options
Diffstat (limited to 'lib/thread.c')
| -rw-r--r-- | lib/thread.c | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/lib/thread.c b/lib/thread.c index aef9ac5cf9..2843a9211e 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -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 */ /* #define DEBUG */ @@ -777,7 +776,7 @@ fd_clear_read_write (struct thread *thread) } /* Add new read thread. */ -void +struct thread * funcname_thread_add_read_write (int dir, struct thread_master *m, int (*func) (struct thread *), void *arg, int fd, struct thread **t_ptr, debugargdef) @@ -789,7 +788,7 @@ funcname_thread_add_read_write (int dir, struct thread_master *m, if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule { pthread_mutex_unlock (&m->mtx); - return; + return NULL; } #if defined (HAVE_POLL_CALL) @@ -839,9 +838,11 @@ funcname_thread_add_read_write (int dir, struct thread_master *m, } } pthread_mutex_unlock (&m->mtx); + + return thread; } -static void +static struct thread * funcname_thread_add_timer_timeval (struct thread_master *m, int (*func) (struct thread *), int type, void *arg, struct timeval *time_relative, struct thread **t_ptr, debugargdef) @@ -859,7 +860,7 @@ funcname_thread_add_timer_timeval (struct thread_master *m, if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule { pthread_mutex_unlock (&m->mtx); - return; + return NULL; } queue = ((type == THREAD_TIMER) ? m->timer : m->background); @@ -879,11 +880,13 @@ funcname_thread_add_timer_timeval (struct thread_master *m, pthread_mutex_unlock (&thread->mtx); } pthread_mutex_unlock (&m->mtx); + + return thread; } /* Add timer event thread. */ -void +struct thread * funcname_thread_add_timer (struct thread_master *m, int (*func) (struct thread *), void *arg, long timer, struct thread **t_ptr, debugargdef) @@ -900,7 +903,7 @@ funcname_thread_add_timer (struct thread_master *m, } /* Add timer event thread with "millisecond" resolution */ -void +struct thread * funcname_thread_add_timer_msec (struct thread_master *m, int (*func) (struct thread *), void *arg, long timer, struct thread **t_ptr, debugargdef) @@ -912,22 +915,22 @@ funcname_thread_add_timer_msec (struct thread_master *m, trel.tv_sec = timer / 1000; trel.tv_usec = 1000*(timer % 1000); - funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel, - t_ptr, debugargpass); + return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, &trel, + t_ptr, debugargpass); } /* Add timer event thread with "millisecond" resolution */ -void +struct thread * funcname_thread_add_timer_tv (struct thread_master *m, int (*func) (struct thread *), void *arg, struct timeval *tv, struct thread **t_ptr, debugargdef) { - funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, tv, t_ptr, - debugargpass); + return funcname_thread_add_timer_timeval (m, func, THREAD_TIMER, arg, tv, + t_ptr, debugargpass); } /* Add a background thread, with an optional millisec delay */ -void +struct thread * funcname_thread_add_background (struct thread_master *m, int (*func) (struct thread *), void *arg, long delay, struct thread **t_ptr, debugargdef) @@ -947,12 +950,12 @@ funcname_thread_add_background (struct thread_master *m, trel.tv_usec = 0; } - funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg, &trel, - t_ptr, debugargpass); + return funcname_thread_add_timer_timeval (m, func, THREAD_BACKGROUND, arg, &trel, + t_ptr, debugargpass); } /* Add simple event thread. */ -void +struct thread * funcname_thread_add_event (struct thread_master *m, int (*func) (struct thread *), void *arg, int val, struct thread **t_ptr, debugargdef) @@ -966,7 +969,7 @@ funcname_thread_add_event (struct thread_master *m, if (t_ptr && *t_ptr) // thread is already scheduled; don't reschedule { pthread_mutex_unlock (&m->mtx); - return; + return NULL; } thread = thread_get (m, THREAD_EVENT, func, arg, debugargpass); @@ -984,6 +987,8 @@ funcname_thread_add_event (struct thread_master *m, } } pthread_mutex_unlock (&m->mtx); + + return thread; } static void @@ -1211,14 +1216,13 @@ check_pollfds(struct thread_master *m, fd_set *readfd, int num) ready++; /* POLLIN / POLLOUT process event */ - if (m->handler.pfds[i].revents & POLLIN) + if (m->handler.pfds[i].revents & (POLLIN | POLLHUP)) thread_process_fds_helper(m, m->read[m->handler.pfds[i].fd], NULL, POLLIN, i); if (m->handler.pfds[i].revents & POLLOUT) thread_process_fds_helper(m, m->write[m->handler.pfds[i].fd], NULL, POLLOUT, i); /* remove fd from list on POLLNVAL */ - if (m->handler.pfds[i].revents & POLLNVAL || - m->handler.pfds[i].revents & POLLHUP) + if (m->handler.pfds[i].revents & POLLNVAL) { memmove(m->handler.pfds+i, m->handler.pfds+i+1, |
