The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
Data Structures | Typedefs | Enumerations | Functions
thread.h File Reference

Common thread instantiation and detach for worker and coordinator threads. More...

#include <freeradius-devel/util/event.h>
#include <freeradius-devel/util/semaphore.h>
#include <freeradius-devel/util/talloc.h>
#include <freeradius-devel/util/dlist.h>
#include <pthread.h>
+ Include dependency graph for thread.h:

Go to the source code of this file.

Data Structures

struct  fr_thread_t
 

Typedefs

typedef void *(* fr_thread_entry_t) (void *)
 
typedef enum fr_thread_status_t fr_thread_status_t
 Track the child thread status.
 

Enumerations

enum  fr_thread_status_t {
  FR_THREAD_FREE = 0 ,
  FR_THREAD_INITIALIZING ,
  FR_THREAD_RUNNING ,
  FR_THREAD_EXITED ,
  FR_THREAD_FAIL
}
 Track the child thread status. More...
 

Functions

int fr_thread_create (pthread_t *thread, fr_thread_entry_t func, void *arg))
 Create a joinable thread.
 
void fr_thread_detach (void)
 Detach thread-specific data for modules, virtual servers, xlats.
 
void fr_thread_exit (fr_thread_t *thread, fr_thread_status_t status, fr_sem_t *sem)
 Signal the parent that we're done.
 
int fr_thread_instantiate (TALLOC_CTX *ctx, fr_event_list_t *el)
 Instantiate thread-specific data for modules, virtual servers, xlats, unlang, and TLS.
 
int fr_thread_setup (fr_thread_t *out, char const *name)
 Common setup for child threads: block signals, allocate a talloc context, and create an event list.
 
void fr_thread_start (fr_thread_t *thread, fr_sem_t *sem)
 Signal the parent that we're done.
 
int fr_thread_wait_list (fr_sem_t *sem, fr_dlist_head_t *head)
 Wait for multiple threads to signal readiness via a semaphore.
 

Detailed Description

Common thread instantiation and detach for worker and coordinator threads.

Id
58e4b0f3796b48c488841a74922653cce1cb4cf2

Definition in file thread.h.


Data Structure Documentation

◆ fr_thread_t

struct fr_thread_t

Definition at line 46 of file thread.h.

+ Collaboration diagram for fr_thread_t:
Data Fields
TALLOC_CTX * ctx our allocation ctx
fr_event_list_t * el our event list
fr_dlist_t entry entry into the parent linked list of threads
int id unique ID for this thread
char const * name of this thread
pthread_t pthread_id of this thread
fr_thread_status_t status running, etc.

Typedef Documentation

◆ fr_thread_entry_t

typedef void *(* fr_thread_entry_t) (void *)

Definition at line 61 of file thread.h.

◆ fr_thread_status_t

Track the child thread status.

Enumeration Type Documentation

◆ fr_thread_status_t

Track the child thread status.

Enumerator
FR_THREAD_FREE 

child is free

FR_THREAD_INITIALIZING 

initialized, but not running

FR_THREAD_RUNNING 

running, and in the running queue

FR_THREAD_EXITED 

exited, and in the exited queue

FR_THREAD_FAIL 

failed, and in the exited queue

Definition at line 38 of file thread.h.

Function Documentation

◆ fr_thread_create()

int fr_thread_create ( pthread_t *  thread,
fr_thread_entry_t  func,
void *  arg 
)

Create a joinable thread.

Parameters
[out]threadhandle that was created by pthread_create.
[in]funcentry point for the thread.
[in]argArgument to pass to func.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 46 of file thread.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_thread_detach()

void fr_thread_detach ( void  )

Detach thread-specific data for modules, virtual servers, xlats.

Calls detach in reverse order of instantiation.

Definition at line 190 of file thread.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_thread_exit()

void fr_thread_exit ( fr_thread_t thread,
fr_thread_status_t  status,
fr_sem_t sem 
)

Signal the parent that we're done.

Parameters
[out]threadwhich is exiting
[in]statusto write
[in]semsemaphore to signal.

Definition at line 218 of file thread.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_thread_instantiate()

int fr_thread_instantiate ( TALLOC_CTX *  ctx,
fr_event_list_t el 
)

Instantiate thread-specific data for modules, virtual servers, xlats, unlang, and TLS.

Parameters
[in]ctxto allocate thread-specific data in.
[in]elevent list for this thread.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 165 of file thread.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_thread_setup()

int fr_thread_setup ( fr_thread_t out,
char const *  name 
)

Common setup for child threads: block signals, allocate a talloc context, and create an event list.

Parameters
[out]outstructure describing the thread
[in]nameHuman-readable name used for the talloc context and error messages.
Returns
  • 0 on success.
  • <0 on failure

Definition at line 112 of file thread.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_thread_start()

void fr_thread_start ( fr_thread_t thread,
fr_sem_t sem 
)

Signal the parent that we're done.

Parameters
[out]threadwhich is starting
[in]semsemaphore to signal.

Definition at line 203 of file thread.c.

+ Here is the caller graph for this function:

◆ fr_thread_wait_list()

int fr_thread_wait_list ( fr_sem_t sem,
fr_dlist_head_t head 
)

Wait for multiple threads to signal readiness via a semaphore.

Parameters
[in]semsemaphore to wait on.
[in]headhead of the list to wait for
Returns
  • 0 for success
  • <0 negative number of threads which failed to start

Definition at line 79 of file thread.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function: