#include "nsd.h"Data Structures | |
| struct | Job |
| struct | JobQueue |
| struct | ThreadPool |
Defines | |
| #define | NS_JOB_DEFAULT_MAXTHREADS 4 |
Enumerations | |
| enum | JobStates { JOB_SCHEDULED = 0, JOB_RUNNING, JOB_DONE } |
| enum | JobTypes { JOB_NON_DETACHED = 0, JOB_DETACHED } |
| enum | JobRequests { JOB_NONE = 0, JOB_WAIT, JOB_CANCEL } |
| enum | QueueRequests { QUEUE_REQ_NONE = 0, QUEUE_REQ_DELETE } |
| enum | ThreadPoolRequests { THREADPOOL_REQ_NONE = 0, THREADPOOL_REQ_STOP } |
Functions | |
| void | NsTclInitQueueType (void) |
| void | NsStartJobsShutdown (void) |
| void | NsWaitJobsShutdown (Ns_Time *toPtr) |
| int | NsTclJobObjCmd (ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv) |
| #define NS_JOB_DEFAULT_MAXTHREADS 4 |
Default Max Threads
| enum JobRequests |
| enum JobStates |
| enum JobTypes |
| enum QueueRequests |
| enum ThreadPoolRequests |
| void NsStartJobsShutdown | ( | void | ) |
----------------------------------------------------------------------
NsStartJobsShutdown --
Signal stop of the Tcl job threads.
Results: None.
Side effects: All pending jobs are cancelled and waiting threads interrupted.
----------------------------------------------------------------------
| void NsTclInitQueueType | ( | void | ) |
----------------------------------------------------------------------
NsInitTclQueueType --
Initialize the Tcl job queue.
Results: None.
Side effects: None.
----------------------------------------------------------------------
| int NsTclJobObjCmd | ( | ClientData | arg, | |
| Tcl_Interp * | interp, | |||
| int | objc, | |||
| Tcl_Obj ** | objv | |||
| ) |
----------------------------------------------------------------------
NsTclJobCmd --
Implement the ns_job command to manage background tasks.
Results: Standard Tcl result.
Side effects: Jobs may be queued to run in another thread.
----------------------------------------------------------------------
ns_job create
Create a new thread pool queue.
ns_job delete
Request that the specified queue be deleted. The queue will only be deleted when all jobs are removed.
ns_job queue
Add a new job the specified queue.
Create a new job and add to the Thread Pool's list of jobs.
Add the job to the thread pool's job list.
Start a new thread if there are less than maxThreads currently running and there currently no idle threads.
Add the job to queue.
ns_job wait
Wait for the specified job.
Set the timeout time. This is an absolute time.
At this point the job we were waiting on has completed, so we return the job's results and errorcodes, then clean up the job.
The following is a sanity check that ensures no other process removed this job's entry.
ns_job cancel
Cancel the specified job.
ns_job waitany
Wait for any job on the queue complete.
Set the timeout time. This is an absolute time.
While there are jobs in queue or no jobs are "done", wait on the queue condition variable.
ns_job jobs
Returns a list of job IDs in arbitrary order.
ns_job queues
Returns a list of the current queues.
ns_job joblist
Returns a list of all the jobs in the queue. The "job" consists of:
Job ID Job State (Scheduled, Running, or Done) Job Results (or job script, if job has not yet completed). Job Code (TCL_OK, TCL_ERROR, TCL_RETURN, TCL_BREAK, TCL_CONTINE) Job Running Time (TBD)
Create a Tcl List to hold the list of jobs.
Create a Tcl List to hold the list of job fields.
Add Job ID
AppendField sets results if an error occurs.
Add the job to the job list
ns_job queuelist
Returns a list of all the queues and the queue information.
Create a Tcl List to hold the list of jobs.
Create a Tcl List to hold the list of queue fields.
Add queue name
AppendField sets results if an error occurs.
Add the job to the job list
ns_job genID
Generate a unique queue name.
ns_job threadlist
Return a list of the thread pool's fields.
Create a Tcl List to hold the list of thread fields.
Add queue name
AppendField sets results if an error occurs.
| void NsWaitJobsShutdown | ( | Ns_Time * | toPtr | ) |
----------------------------------------------------------------------
NsWaitJobsShutdown --
Wait for Tcl job threads to exit.
Results: None.
Side effects: None.
----------------------------------------------------------------------
1.5.1