Crinit -- Configurable Rootfs Init
Loading...
Searching...
No Matches
taskdb.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
6#ifndef __TASKDB_H__
7#define __TASKDB_H__
8
9#include <pthread.h>
10#include <stddef.h>
11
12#include "task.h"
13
14#define CRINIT_MONITOR_DEP_NAME "@crinitmon"
15#define CRINIT_PROVIDE_DEP_NAME "@provided"
16#define CRINIT_TASKDB_INITIAL_SIZE 256
17
25
29typedef struct crinitTaskDB_t {
31 size_t taskSetSize;
32 size_t taskSetItems;
33
36
37 bool
39
40 pthread_mutex_t lock;
42 pthread_cond_t changed;
44
51#define crinitTaskDbForEach(taskDb, task) \
52 for ((task) = (taskDb)->taskSet; (task) != (taskDb)->taskSet + (taskDb)->taskSetItems; (task)++)
53
69int crinitTaskDBInsert(crinitTaskDB_t *ctx, const crinitTask_t *t, bool overwrite);
75#define crinitTaskDBUpdate(ctx, t) crinitTaskDBInsert(ctx, t, true)
76
91int crinitTaskDBFulfillDep(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const crinitTask_t *target);
118int crinitTaskDBProvideFeatureByTaskName(crinitTaskDB_t *ctx, const char *taskName, crinitTaskState_t newState);
131int crinitTaskDBAddDepToTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName);
146int crinitTaskDBRemoveDepFromTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName);
147
158int crinitTaskDBGetTaskByName(crinitTaskDB_t *ctx, crinitTask_t **task, const char *taskName);
159
175int crinitTaskDBSetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t s, const char *taskName);
189int crinitTaskDBGetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t *s, const char *taskName);
190
204int crinitTaskDBSetTaskPID(crinitTaskDB_t *ctx, pid_t pid, const char *taskName);
219int crinitTaskDBGetTaskPID(crinitTaskDB_t *ctx, pid_t *pid, const char *taskName);
220
236int crinitTaskDBGetTaskStateAndPID(crinitTaskDB_t *ctx, crinitTaskState_t *s, pid_t *pid, const char *taskName);
237
255crinitTask_t *crinitTaskDBBorrowTask(crinitTaskDB_t *ctx, const char *taskName);
265
296
310 int (*spawnFunc)(crinitTaskDB_t *ctx, const crinitTask_t *,
312 size_t initialSize);
318#define crinitTaskDBInit(ctx, spawnFunc) crinitTaskDBInitWithSize(ctx, spawnFunc, CRINIT_TASKDB_INITIAL_SIZE);
319
330
343int crinitTaskDBExportTaskNamesToArray(crinitTaskDB_t *ctx, char **tasks[], size_t *numTasks);
344
345#endif /* __TASKDB_H__ */
unsigned long crinitTaskState_t
Type to store Task state bitmask.
Definition crinit-sdefs.h:14
Definition taskdb.h:29
bool spawnInhibit
Specifies if process spawning is currently inhibited, respected by crinitTaskDBSpawnReady().
Definition taskdb.h:38
size_t taskSetSize
Current maximum size of the task array.
Definition taskdb.h:31
int(* spawnFunc)(struct crinitTaskDB_t *ctx, const crinitTask_t *, crinitDispatchThreadMode_t mode)
Definition taskdb.h:35
pthread_cond_t changed
Condition variable to be signalled if taskSet or spawnInhibit is changed.
Definition taskdb.h:42
pthread_mutex_t lock
Definition taskdb.h:40
size_t taskSetItems
Number of elements in the task array.
Definition taskdb.h:32
crinitTask_t * taskSet
Dynamic array of tasks, corresponds to task configs specified in the series config.
Definition taskdb.h:30
Definition task.h:61
Definition task.h:77
Header defining the data structures belonging to a single task and related functions.
int crinitTaskDBInsert(crinitTaskDB_t *ctx, const crinitTask_t *t, bool overwrite)
Definition taskdb.c:102
int crinitTaskDBDestroy(crinitTaskDB_t *ctx)
Definition taskdb.c:82
int crinitTaskDBGetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t *s, const char *taskName)
Definition taskdb.c:311
int crinitTaskDBExportTaskNamesToArray(crinitTaskDB_t *ctx, char **tasks[], size_t *numTasks)
Definition taskdb.c:575
int crinitTaskDBSetTaskPID(crinitTaskDB_t *ctx, pid_t pid, const char *taskName)
Definition taskdb.c:331
int crinitTaskDBAddDepToTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName)
Definition taskdb.c:422
int crinitTaskDBSpawnReady(crinitTaskDB_t *ctx, crinitDispatchThreadMode_t mode)
Definition taskdb.c:162
int crinitTaskDBInitWithSize(crinitTaskDB_t *ctx, int(*spawnFunc)(crinitTaskDB_t *ctx, const crinitTask_t *, crinitDispatchThreadMode_t mode), size_t initialSize)
Definition taskdb.c:42
int crinitTaskDBGetTaskPID(crinitTaskDB_t *ctx, pid_t *pid, const char *taskName)
Definition taskdb.c:350
int crinitTaskDBProvideFeature(crinitTaskDB_t *ctx, const crinitTask_t *provider, crinitTaskState_t newState)
Definition taskdb.c:531
int crinitTaskDBSetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t s, const char *taskName)
Definition taskdb.c:241
int crinitTaskDBSetSpawnInhibit(crinitTaskDB_t *ctx, bool inh)
Definition taskdb.c:200
int crinitTaskDBGetTaskStateAndPID(crinitTaskDB_t *ctx, crinitTaskState_t *s, pid_t *pid, const char *taskName)
Definition taskdb.c:370
int crinitTaskDBGetTaskByName(crinitTaskDB_t *ctx, crinitTask_t **task, const char *taskName)
Definition taskdb.c:218
int crinitTaskDBRemoveDepFromTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName)
Definition taskdb.c:471
crinitDispatchThreadMode_t
Definition taskdb.h:21
@ CRINIT_DISPATCH_THREAD_MODE_START
Definition taskdb.h:22
@ CRINIT_DISPATCH_THREAD_MODE_STOP
Definition taskdb.h:23
int crinitTaskDBRemit(crinitTaskDB_t *ctx)
Definition taskdb.c:409
int crinitTaskDBFulfillDep(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const crinitTask_t *target)
Definition taskdb.c:500
int crinitTaskDBProvideFeatureByTaskName(crinitTaskDB_t *ctx, const char *taskName, crinitTaskState_t newState)
Definition taskdb.c:557
crinitTask_t * crinitTaskDBBorrowTask(crinitTaskDB_t *ctx, const char *taskName)
Definition taskdb.c:392