]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/frr_pthread.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / lib / frr_pthread.c
index 898fe98aada9f712e25dcb3df7b917779f2883ac..c4ead01bf6eaae97adc76564c4966344eb1127ed 100644 (file)
@@ -1,20 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Utilities and interfaces for managing POSIX threads within FRR.
  * Copyright (C) 2017  Cumulus Networks, Inc.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * 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 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
  */
 
 #include <zebra.h>
@@ -55,7 +42,7 @@ static struct list *frr_pthread_list;
 
 void frr_pthread_init(void)
 {
-       frr_with_mutex(&frr_pthread_list_mtx) {
+       frr_with_mutex (&frr_pthread_list_mtx) {
                frr_pthread_list = list_new();
        }
 }
@@ -64,7 +51,7 @@ void frr_pthread_finish(void)
 {
        frr_pthread_stop_all();
 
-       frr_with_mutex(&frr_pthread_list_mtx) {
+       frr_with_mutex (&frr_pthread_list_mtx) {
                struct listnode *n, *nn;
                struct frr_pthread *fpt;
 
@@ -88,7 +75,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
        /* initialize mutex */
        pthread_mutex_init(&fpt->mtx, NULL);
        /* create new thread master */
-       fpt->master = thread_master_create(name);
+       fpt->master = event_master_create(name);
        /* set attributes */
        fpt->attr = *attr;
        name = (name ? name : "Anonymous thread");
@@ -105,7 +92,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
        pthread_mutex_init(fpt->running_cond_mtx, NULL);
        pthread_cond_init(fpt->running_cond, NULL);
 
-       frr_with_mutex(&frr_pthread_list_mtx) {
+       frr_with_mutex (&frr_pthread_list_mtx) {
                listnode_add(frr_pthread_list, fpt);
        }
 
@@ -114,7 +101,7 @@ struct frr_pthread *frr_pthread_new(const struct frr_pthread_attr *attr,
 
 static void frr_pthread_destroy_nolock(struct frr_pthread *fpt)
 {
-       thread_master_free(fpt->master);
+       event_master_free(fpt->master);
        pthread_mutex_destroy(&fpt->mtx);
        pthread_mutex_destroy(fpt->running_cond_mtx);
        pthread_cond_destroy(fpt->running_cond);
@@ -126,7 +113,7 @@ static void frr_pthread_destroy_nolock(struct frr_pthread *fpt)
 
 void frr_pthread_destroy(struct frr_pthread *fpt)
 {
-       frr_with_mutex(&frr_pthread_list_mtx) {
+       frr_with_mutex (&frr_pthread_list_mtx) {
                listnode_delete(frr_pthread_list, fpt);
        }
 
@@ -193,7 +180,7 @@ int frr_pthread_run(struct frr_pthread *fpt, const pthread_attr_t *attr)
 
 void frr_pthread_wait_running(struct frr_pthread *fpt)
 {
-       frr_with_mutex(fpt->running_cond_mtx) {
+       frr_with_mutex (fpt->running_cond_mtx) {
                while (!fpt->running)
                        pthread_cond_wait(fpt->running_cond,
                                          fpt->running_cond_mtx);
@@ -202,7 +189,7 @@ void frr_pthread_wait_running(struct frr_pthread *fpt)
 
 void frr_pthread_notify_running(struct frr_pthread *fpt)
 {
-       frr_with_mutex(fpt->running_cond_mtx) {
+       frr_with_mutex (fpt->running_cond_mtx) {
                fpt->running = true;
                pthread_cond_signal(fpt->running_cond);
        }
@@ -219,7 +206,7 @@ int frr_pthread_stop(struct frr_pthread *fpt, void **result)
 
 void frr_pthread_stop_all(void)
 {
-       frr_with_mutex(&frr_pthread_list_mtx) {
+       frr_with_mutex (&frr_pthread_list_mtx) {
                struct listnode *n;
                struct frr_pthread *fpt;
                for (ALL_LIST_ELEMENTS_RO(frr_pthread_list, n, fpt)) {
@@ -237,24 +224,22 @@ void frr_pthread_stop_all(void)
  */
 
 /* dummy task for sleeper pipe */
-static int fpt_dummy(struct thread *thread)
+static void fpt_dummy(struct event *thread)
 {
-       return 0;
 }
 
 /* poison pill task to end event loop */
-static int fpt_finish(struct thread *thread)
+static void fpt_finish(struct event *thread)
 {
-       struct frr_pthread *fpt = THREAD_ARG(thread);
+       struct frr_pthread *fpt = EVENT_ARG(thread);
 
        atomic_store_explicit(&fpt->running, false, memory_order_relaxed);
-       return 0;
 }
 
 /* stop function, called from other threads to halt this one */
 static int fpt_halt(struct frr_pthread *fpt, void **res)
 {
-       thread_add_event(fpt->master, &fpt_finish, fpt, 0, NULL);
+       event_add_event(fpt->master, &fpt_finish, fpt, 0, NULL);
        pthread_join(fpt->thread, res);
 
        return 0;
@@ -296,7 +281,7 @@ static void *fpt_run(void *arg)
 
        int sleeper[2];
        pipe(sleeper);
-       thread_add_read(fpt->master, &fpt_dummy, NULL, sleeper[0], NULL);
+       event_add_read(fpt->master, &fpt_dummy, NULL, sleeper[0], NULL);
 
        fpt->master->handle_signals = false;
 
@@ -304,11 +289,11 @@ static void *fpt_run(void *arg)
 
        frr_pthread_notify_running(fpt);
 
-       struct thread task;
+       struct event task;
        while (atomic_load_explicit(&fpt->running, memory_order_relaxed)) {
                pthread_testcancel();
-               if (thread_fetch(fpt->master, &task)) {
-                       thread_call(&task);
+               if (event_fetch(fpt->master, &task)) {
+                       event_call(&task);
                }
        }