summaryrefslogtreecommitdiffstats
path: root/lib/frr_pthread.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* *: generously apply constDavid Lamparter2019-12-021-2/+2
| | | | | | const const const your boat, merrily down the stream... Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: add frr_with_mutex() block-wrapperDavid Lamparter2019-09-031-0/+48
| | | | | | | | | frr_with_mutex(...) { ... } locks and automatically unlocks the listed mutex(es) when the block is exited. This adds a bit of safety against forgetting the unlock in error paths & co. and makes the code a slight bit more readable. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: RCUDavid Lamparter2019-07-311-0/+3
| | | | | | Please refer to doc/developer/rcu.rst for documentation. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: use MTYPE_STATICDavid Lamparter2019-06-211-3/+0
| | | | Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: add extern "C" {} blocks to all libfrr headersRenato Westphal2019-02-121-0/+8
| | | | | | | These are necessary to use functions defined in these headers from C++. Signed-off-by: David Lamparter <equinox@diac24.net> Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
* lib: make atomic ops C++ compatibleDavid Lamparter2019-02-111-1/+1
| | | | | | | C++ doesn't have ISO C11 stdatomic.h or "_Atomic inttype", so use std::atomic instead to get the headers compatible. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib, bgpd: Convert frr_pthread_set_name to only cause it to set os name of ↵Donald Sharp2019-01-091-6/+3
| | | | | | | | | | | | | | | | | | | | | | | | | the thread The current invocation of frr_pthread_set_name was causing it reset the os_name. There is no need for this, we now always create the pthread appropriately to have both name and os_name. So convert this function to a simple call through of the pthread call now. Before(any of these changes): sharpd@robot ~/frr1> ps -L -p 16895 PID LWP TTY TIME CMD 16895 16895 ? 00:01:39 bgpd 16895 16896 ? 00:00:54 16895 16897 ? 00:00:07 bgpd_ka After: sharpd@donna ~/frr1> ps -L -p 1752 PID LWP TTY TIME CMD 1752 1752 ? 00:00:00 bgpd 1752 1753 ? 00:00:00 bgpd_io 1752 1754 ? 00:00:00 bgpd_ka Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* lib: remove unused frr_pthread_yield()David Lamparter2018-09-191-3/+0
| | | | | | | | | | | OS-level yield is generally a bad and possibly dangerous idea. If the thread should be suspended, there should always be something to wait on, or it turns into busy waiting. And if it's "just giving something else the chance to run" - that's the kernel's job to determine, and the kernel will do so while considering priorities, cgroups, and whatnot. Let it do its job. Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: remove frr_pthread->idDavid Lamparter2018-09-191-21/+0
| | | | | | | All I can see is an unneccessary complication. If there's some purpose here it needs to be documented... Signed-off-by: David Lamparter <equinox@diac24.net>
* lib: Detect if pthread_condattr_setclock is availableDonald Sharp2018-09-081-0/+4
| | | | | | | Auto-detect if pthread_condattr_setclock is available and if it is not allow the code to compile around the issue. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* *: pthread set name abstractionChirag Shah2018-08-301-2/+12
| | | | | | | | | | | | | | | Testing Done: TOR#cat /proc/2670/task/2672/comm bgpd_ka TOR# ps H -C bgpd -o 'pid tid cmd comm' PID TID CMD COMMAND 2670 2670 /usr/lib/frr/bgpd -M snmp - bgpd 2670 2671 /usr/lib/frr/bgpd -M snmp - bgpd 2670 2672 /usr/lib/frr/bgpd -M snmp - bgpd_ka Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
* lib: frr_pthread int size nitsQuentin Young2018-03-091-1/+1
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: some frr_pthread fixesQuentin Young2018-03-061-5/+29
| | | | | | | * Use atomic fixed-width thread identifiers * Add ability to change thread name at runtime Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: streamline frr_pthreads, add default loopQuentin Young2018-01-241-47/+99
| | | | | | | | | | | | | | | | | | | | | | | | | Some work on FRR's pthread wrapper. * Provide a built-in way to synchronize thread startup * Make utility functions take frr_pthread * instead of its integer ID * Pass frr_pthread * as pthread start function argument * Correct some comment styling * Rename some variables to match naming conventions in the file * Change parameter ordering in stop function prototype to follow the convention in the other functions * Default new frr_pthreads to using a vanilla event loop For the last point, the original goal when designing the implementation of pthreads into FRR was to be able to use the thread.c event based system inside pthreads. This code essentially encapuslates all the thread.c functionality into an easy to use pthread out of the box. Creating a new frr_pthread with a null attributes field will cause the created frr_pthread to run a thread.c event loop. The upshot of this is that it is now possible to safely run existing functions in a pthread in roughly 3 lines of code. It also serves as an example / starting point for others. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: add MTYPE for synchronization primitivesQuentin Young2018-01-091-0/+3
| | | | Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
* lib: Add pthread_yieldDonald Sharp2018-01-061-0/+3
| | | | Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
* *: reindentreindent-master-afterwhitespace / reindent2017-07-171-15/+16
| | | | | | indent.py `git ls-files | pcregrep '\.[ch]$' | pcregrep -v '^(ldpd|babeld|nhrpd)/'` Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* *: make consistent & update GPLv2 file headersDavid Lamparter2017-05-151-17/+16
| | | | | | | | | | | The FSF's address changed, and we had a mixture of comment styles for the GPL file header. (The style with * at the beginning won out with 580 to 141 in existing files.) Note: I've intentionally left intact other "variations" of the copyright header, e.g. whether it says "Zebra", "Quagga", "FRR", or nothing. Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
* lib: add pthread managerQuentin Young2017-04-291-0/+145
Adds infrastructure for keeping track of pthreads. The general idea is to maintain a daemon-wide table of all pthreads, running or not. A pthread is associated with its own thread master that can be used with existing thread.c code, which provides user-space timers, an event loop, non-blocking I/O callbacks and other facilities. Each frr_pthread has a unique identifier that can be used to fetch it from the table. This is to allow naming threads using a macro, for example: #define WRITE_THREAD 0 #define READ_THREAD 1 #define WORK_THREAD 2 The idea here is to be relatively flexible with regard to how daemons manage their collection of pthreads; the implementation could get away with just some #define'd constants, or keep a dynamically allocated data structure that provides organization, searching, prioritizing, etc. Overall this interface should provide a way to maintain the familiar thread.c userspace threading model while progressively introducing pthreads. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>