Initialization

The Name Server is a task, which means it must be created to execute its main function. It is achieved with PxNamesrvInit().

PxNamesrvInit

PxTask_t PxNamesrvInit(PxPrio_t srvprio, PxMc_t stk_mc, PxUInt_t entries);

Parameters:

  • srvprio - the priority of the Name Server task

  • stk_mc - memory class from which the Name Server task stack will be allocated

  • entries - number of records to be held by Name Server

Error codes:

  • PXERR_NAME_MEM - not enough memory

  • all errors from PxTaskCreate()

  • all errors from PxMcRequest()

  • all errors from PxMsgRequest()

  • all errors from PxMsgSend()

Return values:

  • valid task handle on success

  • invalid task handle on failure

Description:

The stack for Name Server task will be allocated from the memory class which the user provides as an argument. This memory class will also be set as Name Server task default memory class (used later for all dynamic memory allocations). The hash table is a Name Server’s local variable, so it is statically allocated on the Name Server task stack. The remaining memory relevant to the Name Server is allocated at run time. One big block is allocated from the Name Server task default memory class based on the number of entries. A second block of flags is allocated from the same memory class to keep track of the memory usage. This memory flag could be a member of the original memory block instead of being allocated separately. But to save the allocated memory usage and to avoid memory padding & packing, we are allocating it separately. The records in the Name Server are then mapped to these allocated blocks and are managed according to the user’s requests.

nameserver init
Fig. 1. Name Server initialization flow

The following code snippet shows how to initialize Name Server with a defined number of entries as NAMESERVER_MAX_ENTRIES.

Code 1. Example of initializing Name Server
#define NAMESERVER_MAX_ENTRIES	50

...

/* Create Name Server service task */
NameSrv = PxNamesrvInit(NAMESRV_PRIO, PXMcTaskdefault, NAMESERVER_MAX_ENTRIES);
if (PxTaskIdError(NameSrv) != PXERR_NOERROR)
    PxPanic();

...