diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2019-06-13 04:27:29 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2019-06-13 21:14:04 +0200 |
commit | 1ef14bee7aa063a939a3bffb11e2931c23fdf8f5 (patch) | |
tree | 976b5671274b10448ff2747c817a6ea34b9f830a /lib/thread.c | |
parent | lib: Prevent infinite loop in fd handling (diff) | |
download | frr-1ef14bee7aa063a939a3bffb11e2931c23fdf8f5.tar.xz frr-1ef14bee7aa063a939a3bffb11e2931c23fdf8f5.zip |
lib: Add check for non-preexisting thread
When adding a read/write poll event and we are using a developmental
build add a bit of code to ensure that we do not already have an read
or write event scheduled.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib/thread.c')
-rw-r--r-- | lib/thread.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/thread.c b/lib/thread.c index 2e7b0ca0e..9d00d7c52 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -756,6 +756,7 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m, debugargdef) { struct thread *thread = NULL; + struct thread **thread_array; assert(fd >= 0 && fd < m->fd_limit); pthread_mutex_lock(&m->mtx); @@ -770,11 +771,25 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m, /* default to a new pollfd */ nfds_t queuepos = m->handler.pfdcount; + if (dir == THREAD_READ) + thread_array = m->read; + else + thread_array = m->write; + /* if we already have a pollfd for our file descriptor, find and * use it */ for (nfds_t i = 0; i < m->handler.pfdcount; i++) if (m->handler.pfds[i].fd == fd) { queuepos = i; + +#ifdef DEV_BUILD + /* + * What happens if we have a thread already + * created for this event? + */ + if (thread_array[fd]) + assert(!"Thread already scheduled for file descriptor"); +#endif break; } @@ -794,10 +809,7 @@ struct thread *funcname_thread_add_read_write(int dir, struct thread_master *m, pthread_mutex_lock(&thread->mtx); { thread->u.fd = fd; - if (dir == THREAD_READ) - m->read[thread->u.fd] = thread; - else - m->write[thread->u.fd] = thread; + thread_array[thread->u.fd] = thread; } pthread_mutex_unlock(&thread->mtx); |