CNDP  22.08.0
cne_thread.h File Reference
#include <stdio.h>
#include <pthread.h>
#include <cne_common.h>
#include <stdint.h>
#include <uid.h>

Go to the source code of this file.

Typedefs

typedef void * thd_t
 
typedef void(* thd_func_t) (void *)
 

Functions

CNDP_API int thread_id (void)
 
CNDP_API thd_t thread_get (int tidx)
 
CNDP_API int thread_create (const char *name, thd_func_t func, void *arg)
 
CNDP_API int thread_register (const char *name, uint64_t pid)
 
CNDP_API int thread_unregister (int tidx)
 
CNDP_API int thread_wait (int tid, unsigned int checks, unsigned int usec)
 
CNDP_API int thread_wait_all (unsigned int checks, unsigned int usec, int skip)
 
CNDP_API int thread_stop_running (int tidx)
 
CNDP_API int thread_running (int tidx)
 
CNDP_API int thread_set_private (int tidx, void *priv_)
 
CNDP_API void * thread_get_private (int tidx)
 
CNDP_API int thread_set_affinity (int cpu)
 
CNDP_API const char * thread_name (int tidx)
 
CNDP_API void thread_dump (FILE *f)
 

Detailed Description

CNE Thread

This library provides the thread management service.

This library provides an interface to create, register, set affinity and schedule a thread. Also support the thread id query ops and debug ops.

See the CNE architecture documentation for more information about the design of this library.

Definition in file cne_thread.h.

Typedef Documentation

◆ thd_t

typedef void* thd_t

Thread data handle, opaque value

Definition at line 35 of file cne_thread.h.

◆ thd_func_t

typedef void(* thd_func_t) (void *)

Flags used to determine what type of thread Rx/Tx or Rx or Tx only

Definition at line 39 of file cne_thread.h.

Function Documentation

◆ thread_id()

CNDP_API int thread_id ( void  )

Return the thread ID or index value .

◆ thread_get()

CNDP_API thd_t thread_get ( int  tidx)

Returns the thd_t pointer give the thread IDX value.

Parameters
tidxThe thread index value
Returns
NULL if tidx is invalid or the thd_t pointer

◆ thread_create()

CNDP_API int thread_create ( const char *  name,
thd_func_t  func,
void *  arg 
)

Wrapper routine around pthread_create call to help setup CNDP state

Parameters
nameThe name of the thread that will be created.
funcThe function pointer to call when thread is started.
argThe argument passed to the function
Returns
-1 on error or 0 - N index value
Examples
examples/cndpfwd/parse-args.c, examples/cnet-graph/parse-args.c, examples/cnet-quic/parse-args.c, examples/dlb_test/parse-args.c, examples/helloworld/main.c, examples/ibroker/main.c, examples/l3fwd-graph/parse-args.c, and examples/phil/parse-args.c.

◆ thread_register()

CNDP_API int thread_register ( const char *  name,
uint64_t  pid 
)

Register a thread name and pid value, returning a thread index. Obtains a thread index value unique to this thread.

Parameters
nameThe name of the thread
pidThe thread identifier value, can be 0 if not required.
Returns
-1 on error or the thread index value

◆ thread_unregister()

CNDP_API int thread_unregister ( int  tidx)

Release a thread index value.

Parameters
tidxThe thread index value to release.
Returns
-1 on error or 0 on success

◆ thread_wait()

CNDP_API int thread_wait ( int  tid,
unsigned int  checks,
unsigned int  usec 
)

Wait for all threads to stop running

Parameters
tidThe thread id to wait on to complete
checksNumber of check to attempt, if zero wait forever.
usecNumber of micro-seconds to wait between checks.
Returns
Return when all are stopped or when the check rate is done. 0 on all stopped non-zero when checks are done.

◆ thread_wait_all()

CNDP_API int thread_wait_all ( unsigned int  checks,
unsigned int  usec,
int  skip 
)

Wait for all threads to stop running

Parameters
checksNumber of check to attempt, if zero wait forever.
usecNumber of micro-seconds to wait between checks.
skipSkip the first initial thread.
Returns
Return when all are stopped or when the check rate is done. 0 on all stopped non-zero when checks are done.
Examples
examples/helloworld/main.c.

◆ thread_stop_running()

CNDP_API int thread_stop_running ( int  tidx)

Stop a thread running by clearing the running flag

Parameters
tidxClear the running flag for the thread index value, if -1 then stop self
Returns
0 on successfully clearing the running flag

◆ thread_running()

CNDP_API int thread_running ( int  tidx)

Return the state of the thread.

Parameters
tidxreturn the running flag for the thread index value, if -1 then self
Returns
-1 on error or the state of running flag

◆ thread_set_private()

CNDP_API int thread_set_private ( int  tidx,
void *  priv_ 
)

Set a user specific private value or pointer.

Parameters
tidxThe thread index to store the private value.
priv_The void pointer value to store in the thread state struct.
Returns
0 on success or -1 on error

◆ thread_get_private()

CNDP_API void* thread_get_private ( int  tidx)

Returns the thread private data stored with thread_set_private()

Parameters
tidxThe thread index value to return the private value
Returns
NULL or the thread private data pointer

◆ thread_set_affinity()

CNDP_API int thread_set_affinity ( int  cpu)

Set the CPU affinity for the current thread.

Examples
examples/dlb_test/dlb_test.c.

◆ thread_name()

CNDP_API const char* thread_name ( int  tidx)

Return thread name.

Parameters
tidxIf tidx is -1 then return current thread name, otherwise tidx name.
Returns
NULL on error or the thread name
Examples
examples/ibroker/main.c.

◆ thread_dump()

CNDP_API void thread_dump ( FILE *  f)

Dump out all threads currently active/allocated

Parameters
fThe file pointer to write the text output or NULL if stdout