]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: Add check for non-preexisting thread
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 13 Jun 2019 02:27:29 +0000 (22:27 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 13 Jun 2019 19:14:04 +0000 (15:14 -0400)
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>
lib/thread.c

index 2e7b0ca0ef7e613da6dbadaba436d59d0b165718..9d00d7c52d18e910854e1644e02aa72a1386ddc8 100644 (file)
@@ -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);