libubox
C utility functions for OpenWrt.
runqueue.h File Reference
#include "list.h"
#include "safe_list.h"
#include "uloop.h"

Go to the source code of this file.

Data Structures

struct  runqueue
 
struct  runqueue_task_type
 
struct  runqueue_task
 
struct  runqueue_process
 

Macros

#define RUNQUEUE_INIT(_name, _max_running)
 
#define RUNQUEUE(_name, _max_running)    struct runqueue _name = RUNQUEUE_INIT(_name, _max_running)
 

Functions

void runqueue_init (struct runqueue *q)
 
void runqueue_cancel (struct runqueue *q)
 
void runqueue_cancel_active (struct runqueue *q)
 
void runqueue_cancel_pending (struct runqueue *q)
 
void runqueue_kill (struct runqueue *q)
 
void runqueue_stop (struct runqueue *q)
 
void runqueue_resume (struct runqueue *q)
 
void runqueue_task_add (struct runqueue *q, struct runqueue_task *t, bool running)
 
void runqueue_task_add_first (struct runqueue *q, struct runqueue_task *t, bool running)
 
void runqueue_task_complete (struct runqueue_task *t)
 
void runqueue_task_cancel (struct runqueue_task *t, int type)
 
void runqueue_task_kill (struct runqueue_task *t)
 
void runqueue_process_add (struct runqueue *q, struct runqueue_process *p, pid_t pid)
 
void runqueue_process_cancel_cb (struct runqueue *q, struct runqueue_task *t, int type)
 
void runqueue_process_kill_cb (struct runqueue *q, struct runqueue_task *t)
 

Macro Definition Documentation

◆ RUNQUEUE

#define RUNQUEUE (   _name,
  _max_running 
)     struct runqueue _name = RUNQUEUE_INIT(_name, _max_running)

Definition at line 99 of file runqueue.h.

◆ RUNQUEUE_INIT

#define RUNQUEUE_INIT (   _name,
  _max_running 
)
Value:
{ \
.tasks_active = SAFE_LIST_INIT(_name.tasks_active), \
.tasks_inactive = SAFE_LIST_INIT(_name.tasks_inactive), \
.max_running_tasks = _max_running \
}
#define SAFE_LIST_INIT(_name)
Definition: safe_list.h:54

Definition at line 93 of file runqueue.h.

Function Documentation

◆ runqueue_cancel()

void runqueue_cancel ( struct runqueue q)

Definition at line 102 of file runqueue.c.

103 {
106 }
void runqueue_cancel_active(struct runqueue *q)
Definition: runqueue.c:92
void runqueue_cancel_pending(struct runqueue *q)
Definition: runqueue.c:97
static struct runqueue q
Definition: test-runqueue.c:27
Here is the call graph for this function:

◆ runqueue_cancel_active()

void runqueue_cancel_active ( struct runqueue q)

Definition at line 92 of file runqueue.c.

93 {
95 }
static int __runqueue_cancel(void *ctx, struct safe_list *list)
Definition: runqueue.c:82
int safe_list_for_each(struct safe_list *head, int(*cb)(void *ctx, struct safe_list *list), void *ctx)
Definition: safe_list.c:62
struct safe_list tasks_active
Definition: runqueue.h:31
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runqueue_cancel_pending()

void runqueue_cancel_pending ( struct runqueue q)

Definition at line 97 of file runqueue.c.

98 {
100 }
struct safe_list tasks_inactive
Definition: runqueue.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runqueue_init()

void runqueue_init ( struct runqueue q)

Definition at line 31 of file runqueue.c.

32 {
35 }
#define INIT_SAFE_LIST(_head)
Definition: safe_list.h:48
Here is the caller graph for this function:

◆ runqueue_kill()

void runqueue_kill ( struct runqueue q)

Definition at line 108 of file runqueue.c.

109 {
110  struct runqueue_task *t;
111 
112  while (!list_empty(&q->tasks_active.list)) {
115  }
118 }
static bool list_empty(const struct list_head *head)
Definition: list.h:69
#define list_first_entry(ptr, type, field)
Definition: list.h:121
void runqueue_task_kill(struct runqueue_task *t)
Definition: runqueue.c:191
struct safe_list list
Definition: runqueue.h:72
struct uloop_timeout timeout
Definition: runqueue.h:33
struct list_head list
Definition: safe_list.h:36
int uloop_timeout_cancel(struct uloop_timeout *timeout)
Definition: uloop.c:348
Here is the call graph for this function:

◆ runqueue_process_add()

void runqueue_process_add ( struct runqueue q,
struct runqueue_process p,
pid_t  pid 
)

Definition at line 269 of file runqueue.c.

270 {
271  if (p->proc.pending)
272  return;
273 
274  p->proc.pid = pid;
276  if (!p->task.type)
278  uloop_process_add(&p->proc);
279  if (!p->task.running)
280  runqueue_task_add(q, &p->task, true);
281 }
void runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running)
Definition: runqueue.c:181
static const struct runqueue_task_type runqueue_proc_type
Definition: runqueue.c:263
static void __runqueue_proc_cb(struct uloop_process *p, int ret)
Definition: runqueue.c:238
struct runqueue_task task
Definition: runqueue.h:89
struct uloop_process proc
Definition: runqueue.h:90
const struct runqueue_task_type * type
Definition: runqueue.h:73
bool running
Definition: runqueue.h:84
pid_t pid
Definition: uloop.h:87
uloop_process_handler cb
Definition: uloop.h:86
bool pending
Definition: uloop.h:84
int uloop_process_add(struct uloop_process *p)
Definition: uloop.c:391
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runqueue_process_cancel_cb()

void runqueue_process_cancel_cb ( struct runqueue q,
struct runqueue_task t,
int  type 
)

Definition at line 245 of file runqueue.c.

246 {
247  struct runqueue_process *p = container_of(t, struct runqueue_process, task);
248 
249  if (!type)
250  type = SIGTERM;
251 
252  kill(p->proc.pid, type);
253 }
#define container_of(ptr, type, member)
Definition: list.h:38
uint8_t type
Definition: udebug-proto.h:0
Here is the caller graph for this function:

◆ runqueue_process_kill_cb()

void runqueue_process_kill_cb ( struct runqueue q,
struct runqueue_task t 
)

Definition at line 255 of file runqueue.c.

256 {
257  struct runqueue_process *p = container_of(t, struct runqueue_process, task);
258 
260  kill(p->proc.pid, SIGKILL);
261 }
int uloop_process_delete(struct uloop_process *p)
Definition: uloop.c:412
Here is the caller graph for this function:

◆ runqueue_resume()

void runqueue_resume ( struct runqueue q)

Definition at line 210 of file runqueue.c.

211 {
212  q->stopped = false;
214 }
static void runqueue_start_next(struct runqueue *q)
Definition: runqueue.c:73
bool stopped
Definition: runqueue.h:37
Here is the call graph for this function:

◆ runqueue_stop()

void runqueue_stop ( struct runqueue q)

Definition at line 205 of file runqueue.c.

206 {
207  q->stopped = true;
208 }

◆ runqueue_task_add()

void runqueue_task_add ( struct runqueue q,
struct runqueue_task t,
bool  running 
)

Definition at line 181 of file runqueue.c.

182 {
183  _runqueue_task_add(q, t, running, 0);
184 }
static void _runqueue_task_add(struct runqueue *q, struct runqueue_task *t, bool running, bool first)
Definition: runqueue.c:148
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runqueue_task_add_first()

void runqueue_task_add_first ( struct runqueue q,
struct runqueue_task t,
bool  running 
)

Definition at line 186 of file runqueue.c.

187 {
188  _runqueue_task_add(q, t, running, 1);
189 }
Here is the call graph for this function:

◆ runqueue_task_cancel()

void runqueue_task_cancel ( struct runqueue_task t,
int  type 
)

Definition at line 120 of file runqueue.c.

121 {
122  if (!t->queued)
123  return;
124 
125  if (!t->running) {
127  return;
128  }
129 
130  t->cancelled = true;
131  if (t->cancel_timeout)
133  if (t->type->cancel)
134  t->type->cancel(t->q, t, type);
135 }
void runqueue_task_complete(struct runqueue_task *t)
Definition: runqueue.c:216
void(* cancel)(struct runqueue *q, struct runqueue_task *t, int type)
Definition: runqueue.h:62
bool cancelled
Definition: runqueue.h:85
bool queued
Definition: runqueue.h:83
struct runqueue * q
Definition: runqueue.h:74
struct uloop_timeout timeout
Definition: runqueue.h:78
int cancel_timeout
Definition: runqueue.h:80
int uloop_timeout_set(struct uloop_timeout *timeout, int msecs)
Definition: uloop.c:328
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runqueue_task_complete()

void runqueue_task_complete ( struct runqueue_task t)

Definition at line 216 of file runqueue.c.

217 {
218  struct runqueue *q = t->q;
219 
220  if (!t->queued)
221  return;
222 
223  if (t->running)
224  t->q->running_tasks--;
225 
227 
228  safe_list_del(&t->list);
229  t->queued = false;
230  t->running = false;
231  t->cancelled = false;
232  if (t->complete)
233  t->complete(q, t);
235 }
void safe_list_del(struct safe_list *list)
Definition: safe_list.c:95
void(* complete)(struct runqueue *q, struct runqueue_task *t)
Definition: runqueue.h:76
int running_tasks
Definition: runqueue.h:35
Here is the call graph for this function:
Here is the caller graph for this function:

◆ runqueue_task_kill()

void runqueue_task_kill ( struct runqueue_task t)

Definition at line 191 of file runqueue.c.

192 {
193  struct runqueue *q = t->q;
194  bool running = t->running;
195 
196  if (!t->queued)
197  return;
198 
199  if (running && t->type->kill)
200  t->type->kill(q, t);
201 
203 }
void(* kill)(struct runqueue *q, struct runqueue_task *t)
Definition: runqueue.h:68
Here is the call graph for this function:
Here is the caller graph for this function: