CNDP  22.08.0
cne.h File Reference
#include <stdio.h>
#include <stdint.h>
#include <cne_common.h>

Go to the source code of this file.

Typedefs

typedef void(* on_exit_fn_t) (int sig, void *arg, int exit_type)
 

Enumerations

enum  { CNE_CAUGHT_SIGNAL , CNE_CALLED_EXIT , CNE_USER_EXIT , MAX_EXIT_TYPES }
 

Functions

CNDP_API int cne_init (void)
 
CNDP_API int cne_on_exit (on_exit_fn_t exit_fn, void *arg, int *signals, int nb_signals)
 
CNDP_API int cne_initial_uid (void)
 
CNDP_API int cne_entry_uid (void)
 
CNDP_API int cne_register (const char *name)
 
CNDP_API int cne_unregister (int tidx)
 
CNDP_API int cne_set_private (int tidx, void *v)
 
CNDP_API int cne_get_private (int tidx, void **v)
 
CNDP_API int cne_id (void)
 
CNDP_API int cne_max_threads (void)
 
CNDP_API int cne_next_id (int uid, int skip, int wrap)
 
CNDP_API int cne_active_threads (void)
 
CNDP_API void cne_dump (FILE *f)
 
static const char * copyright_msg (void)
 
static const char * copyright_msg_short (void)
 
static const char * powered_by (void)
 

Detailed Description

API for CNE setup routines.

Definition in file cne.h.

Typedef Documentation

◆ on_exit_fn_t

typedef void(* on_exit_fn_t) (int sig, void *arg, int exit_type)

The typedef for the on exit function pointer.

Parameters
sigThe signal number supplied in the signal handler function.
argThe user supplied argument used as an argument to the exit_fn function.
exit_typeThe type of exit signal or exit() was called, CNE_CAUGHT_SIGNAL or CNE_CALLED_EXIT

Definition at line 45 of file cne.h.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
CNE_CAUGHT_SIGNAL 

Application caught a signal

CNE_CALLED_EXIT 

Application called exit

CNE_USER_EXIT 

User type exit, when exit function is called by application

MAX_EXIT_TYPES 

Number of exit types.

Definition at line 26 of file cne.h.

Function Documentation

◆ cne_init()

CNDP_API int cne_init ( void  )

Set the get_id function pointer and finish initialization

The API initializes the UID and other basic system configuration to enable user application threads to work with CNDP APIs.

This API, needs to be only called once per process, during the main thread startup.

Returns
The initial UID for the main thread.
Examples
examples/cli/main.c, examples/cndpfwd/main.c, examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, examples/dlb_test/dlb_test.c, examples/helloworld/main.c, examples/ibroker/main.c, examples/l3fwd-graph/fwd.c, examples/phil/main.c, and examples/vpp-plugin/cndp/device.c.

◆ cne_on_exit()

CNDP_API int cne_on_exit ( on_exit_fn_t  exit_fn,
void *  arg,
int *  signals,
int  nb_signals 
)

Call signal handler and function pointer with argument, when a signal is caught or on exit.

Parameters
exit_fnThe function pointer to call when a signal is caught. If the signal is not in the signals array then standard system operations are performed.
argThe user supplied argument used as an argument to the exit_fn function.
signalsA integer array of signal value to handle via signal() function. Can be NULL pointer as long as the nb_signals is zero.
nb_signalsThe number of signal values in the signals array, can be zero.
Returns
0 on success or -1 if exit_fn is NULL or -1 if atexit() failed or -1 if signals is NULL with nb_signals non-zero.
Examples
examples/cli/main.c, examples/cndpfwd/main.c, examples/cnet-graph/cnet-graph.c, examples/cnet-quic/cnet-quic.c, examples/dlb_test/dlb_test.c, examples/ibroker/main.c, and examples/l3fwd-graph/fwd.c.

◆ cne_initial_uid()

CNDP_API int cne_initial_uid ( void  )

Return the initial UID value for the main thread.

Returns
The initial UID value.

◆ cne_entry_uid()

CNDP_API int cne_entry_uid ( void  )

Return the UID value for the current instance.

Returns
-1 if error or UID value for the instance.

◆ cne_register()

CNDP_API int cne_register ( const char *  name)

Register an instance/thread and return the uid value.

Not thread safe. Mutual exclusion needs to be assured by user. This API is used to register the main thread or when the developer uses some other type of threading model and not the lib/usr/clib/thread library.

Parameters
nameThe name of the instance used for debugging
Returns
UID value or -1 on error
Examples
examples/vpp-plugin/cndp/device.c, examples/vpp-plugin/cndp/input.c, and examples/vpp-plugin/cndp/output.c.

◆ cne_unregister()

CNDP_API int cne_unregister ( int  tidx)

Unregister the instance and reclaim the UID value.

Not thread safe. Mutual exclusion needs to be assured by user. Release the UID value for the given thread index value or use the current thread index value.

Parameters
tidxThe instance value from the cne_registers() call. When tidx is -1 then use the current thread id value.
Returns
-1 on error or 0 on success
Examples
examples/helloworld/main.c, and examples/ibroker/main.c.

◆ cne_set_private()

CNDP_API int cne_set_private ( int  tidx,
void *  v 
)

Set a private value with the uid value

Parameters
tidxThe uid index value, if -1 then use the current thread index value.
vThe private pointer value to save
Returns
0 in success or -1 on error

◆ cne_get_private()

CNDP_API int cne_get_private ( int  tidx,
void **  v 
)

Get a private value with the uid value

Parameters
tidxThe uid index value, if -1 then use the current thread index value.
vThe private pointer to pointer value to retrieve
Returns
0 in success or -1 on error

◆ cne_id()

◆ cne_max_threads()

CNDP_API int cne_max_threads ( void  )

Return the max number of threads allowed

Returns
The number of threads allowed or -1 on error.
Examples
examples/dlb_test/dlb_test.c, examples/helloworld/main.c, and examples/phil/phil.c.

◆ cne_next_id()

CNDP_API int cne_next_id ( int  uid,
int  skip,
int  wrap 
)

Return the next thread ID value

Parameters
uidStarting UID
skipSkip the initial thread if set.
wrapWrap the UID to the beginning
Returns
Return the next thread id or -1 on error

◆ cne_active_threads()

CNDP_API int cne_active_threads ( void  )

Return the number of active threads in the system.

Returns
-1 on error or the number of active threads

◆ cne_dump()

CNDP_API void cne_dump ( FILE *  f)

Dump out information about CNE environment

Parameters
fFile pointer to use to write the data, if NULL use stdout.

◆ copyright_msg()

static const char* copyright_msg ( void  )
inlinestatic

Function returning string for Copyright message."

Returns
string

Definition at line 207 of file cne.h.

◆ copyright_msg_short()

static const char* copyright_msg_short ( void  )
inlinestatic

Function returning short string for Copyright message."

Returns
string

Definition at line 218 of file cne.h.

◆ powered_by()

static const char* powered_by ( void  )
inlinestatic

Function returning string for Copyright message."

Returns
string

Definition at line 229 of file cne.h.