NXDelayedWorkSchedule

Schedules work to be executed at a specified time.

Library:LibC
Classification:NKS
Service:Threads

Syntax

  #include <nks/thread.h>
   
  int NXDelayedWorkSchedule (
     NXContext_t    ctx, 
     NXTimerVal_t  *timerval, 
     NXBool_t       bind, 
     NXWorkId_t    *wid);
  

Parameters

ctx

(IN) Points to the context that specifies the work to be scheduled, which must be of type NX_CTX_WORK (see NXContextAlloc).

timerval

(IN) Points to the time interval after which the work is scheduled.

bind

(IN) Specifies whether the work is to be bound:

TRUE

Bind the scheduled work to the CPU from which the function is called. This flag only sends the system a preference; the system is free to ignore it.

FALSE

No binding is specified.

wid

(OUT) Points to the location that will be set to the ID of the scheduled work once the work is successfully scheduled. This ID can be subsequently used to cancel the scheduled work.

Return Values

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

Decimal

Hex

Constant

Description

9

0x09

NX_EINVAL

The context specified is invalid.

24

0x18

NX_EAGAIN

Insufficient resources.

62

0x3E

NX_EBUSY

The specified context is not idle.

Remarks

NXDelayedWorkSchedule schedules the execution of the specified context.

On expiration of the timer, the specified context is scheduled. In the case of periodic execution, the tvCurrent field is reloaded only after the scheduled work completes, which is indicated from a return of the initial context function.

If a request for a binding is to be meaningful, you should be in a nonpreemptible context or you must be bound to the CPU from which the function is called.

The semantics of normal NKS work functions are different from NetWare's work-to-do functions. With NetWare functions, you can reschedule a work item once it is known that it has already started executing. However, with NKS functions, you can reschedule a work context if and only if it has finished executing. If you want to use the NetWare style of work scheduling, use the NKS light-weight work functions (NXLwWorkSchedule).

If you call NXThreadExit during the execution of a work context, the execution stops and the work context is reset so that it is available for reuse by the application. Even if the work context was scheduled as periodic work, the work context is not rescheduled.

If a thread that is executing a work context returns from the function specified in the work context (and doesn't encounter a call to NXThreadExit), the work execution stops, the work context is reset, and periodic work is rescheduled.

See Also