NXContextReinit

Initializes a previously allocated context structure.

Library:LibC
Classification:NKS
Service:Threads

Syntax

  #include <nks/thread.h> 
   
  int NXContextReinit (
     NXContext_t     ctx, 
     void          (*start_routine)(void  *arg), 
     void           *arg, 
     int             priority, 
     unsigned long   flags);
  

Parameters

ctx

(IN) Points to the context to be initialized.

start_routine

(IN) Points to the start function to be executed.

arg

(IN) Points to the parameter for start_routine.

priority

(IN) Specifies the priority of the context:

Flag

Value

Description

NX_PRIO_HIGH

10

High priority

NX_PRIO_MED

5

Medium priority

NX_PRIO_LOW

1

Low priority

flags

(IN) Specifies the context flags:

Flag

Value

Description

NX_CTX_NORMAL

0

Normal context-can be bound to an application thread. Only contexts of this type may be passed to NXThreadCreate.

NX_CTX_WORK

1

Work context-can be bound only to an anonymous thread. Only contexts of this type may be passed to NXWorkSchedule and NXDelayedWorkSchedule

Return Values

If successful, returns 0; otherwise, returns a nonzero error code:

Decimal

Hex

Constant

Description

9

0x09

NX_EINVAL

The specified priority, context, or flags argument is invalid

62

0x3E

NX_EBUSY

The specified context is currently in use (bound to a thread)

Remarks

NXContextReinit can be called to modify any of the attributes of a previously allocated context structure—except the stack size (see NXContextAlloc). The specified context must be idle because it is illegal to call NXContextReinit on a context that is currently being hosted by a thread.

To allocate a context for the ctx parameter, you must call NXContextAlloc.

NXContextReinit performs the following actions as part of initialization:

  • All active key/value pairs that are associated with the context are cleaned up. The destructor associated with each allocated key is called and the value associated with the key is set to NULL. All values associated with keys of the context being reset are lost.

  • The context's stack is reset to the state it was in when the context was created.

You can call NXContextReinit to change an existing context's type to either NX_CTX_NORMAL or NX_CTX_WORK.

For sample code, see ThrDestr.c.

See Also