diff options
author | 2012-01-29 16:36:21 -0800 | |
---|---|---|
committer | 2012-01-29 16:36:21 -0800 | |
commit | f243cd86c98bf07cd2b22339f27e9fde5dad979f (patch) | |
tree | 439e6f293e0283ebf4ca3b5c437e0eede87e14c7 /proc.h | |
parent | 1a5d866a916ab0f7e0630c4205f3fff9b6375a3e (diff) |
Convert jobs list to std::list
Diffstat (limited to 'proc.h')
-rw-r--r-- | proc.h | 50 |
1 files changed, 41 insertions, 9 deletions
@@ -15,6 +15,7 @@ #include <signal.h> #include <unistd.h> #include <sys/time.h> +#include <list> #include "util.h" #include "io.h" @@ -233,14 +234,15 @@ typedef struct process A struct represeting a job. A job is basically a pipeline of one or more processes and a couple of flags. */ -typedef struct job +class job_t { + public: /** The original command which led to the creation of this job. It is used for displaying messages about job status on the terminal. */ - const wchar_t *command; + const wchar_t *command; /** A linked list of all the processes in this job. @@ -276,15 +278,14 @@ typedef struct job /** A pointer to the next job in the job queue */ - struct job *next; + //struct job *next; /** Bitset containing information about the job. A combination of the JOB_* constants. */ int flags; -} - job_t; +}; /** Whether we are running a subshell command @@ -316,10 +317,35 @@ extern int is_login; */ extern int is_event; -/** - Linked list of all living jobs -*/ -extern job_t *first_job; + +/** List of all living jobs */ +typedef std::list<job_t *> job_list_t; +job_list_t &job_list(void); + +/** A class to aid iteration over jobs list */ +class job_iterator_t { + job_list_t::iterator current, end; + public: + + void reset(void) { + job_list_t &jobs = job_list(); + this->current = jobs.begin(); + this->end = jobs.end(); + } + + job_t *next() { + job_t *job = NULL; + if (current != end) { + job = *current; + ++current; + } + return job; + } + + job_iterator_t() { + this->reset(); + } +}; /** Whether a universal variable barrier roundtrip has already been @@ -378,6 +404,11 @@ int proc_get_last_status(); void job_free( job_t* j ); /** + Promotes a job to the front of the job list. +*/ +void job_promote(job_t *job); + +/** Create a new job. Job struct is allocated using halloc, so anything that should be freed with the job can uset it as a halloc context when allocating. @@ -390,6 +421,7 @@ job_t *job_create(); */ job_t *job_get(int id); + /** Return the job with the specified pid. */ |