Crinit -- Configurable Rootfs Init
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 
21 typedef struct crinitTaskDB_t {
23  size_t taskSetSize;
24  size_t taskSetItems;
25 
27  int (*spawnFunc)(struct crinitTaskDB_t *ctx, const crinitTask_t *);
28 
29  bool
31 
32  pthread_mutex_t lock;
34  pthread_cond_t changed;
36 
43 #define crinitTaskDbForEach(taskDb, task) \
44  for ((task) = (taskDb)->taskSet; (task) != (taskDb)->taskSet + (taskDb)->taskSetItems; (task)++)
45 
61 int crinitTaskDBInsert(crinitTaskDB_t *ctx, const crinitTask_t *t, bool overwrite);
67 #define crinitTaskDBUpdate(ctx, t) crinitTaskDBInsert(ctx, t, true)
68 
83 int crinitTaskDBFulfillDep(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const crinitTask_t *target);
97 int crinitTaskDBProvideFeature(crinitTaskDB_t *ctx, const crinitTask_t *provider, crinitTaskState_t newState);
110 int crinitTaskDBProvideFeatureByTaskName(crinitTaskDB_t *ctx, const char *taskName, crinitTaskState_t newState);
123 int crinitTaskDBAddDepToTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName);
138 int crinitTaskDBRemoveDepFromTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName);
139 
155 int crinitTaskDBSetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t s, const char *taskName);
169 int crinitTaskDBGetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t *s, const char *taskName);
170 
184 int crinitTaskDBSetTaskPID(crinitTaskDB_t *ctx, pid_t pid, const char *taskName);
199 int crinitTaskDBGetTaskPID(crinitTaskDB_t *ctx, pid_t *pid, const char *taskName);
200 
216 int crinitTaskDBGetTaskStateAndPID(crinitTaskDB_t *ctx, crinitTaskState_t *s, pid_t *pid, const char *taskName);
217 
246 int crinitTaskDBSetSpawnInhibit(crinitTaskDB_t *ctx, bool inh);
247 
261  size_t initialSize);
267 #define crinitTaskDBInit(ctx, spawnFunc) crinitTaskDBInitWithSize(ctx, spawnFunc, CRINIT_TASKDB_INITIAL_SIZE);
268 
279 
292 int crinitTaskDBExportTaskNamesToArray(crinitTaskDB_t *ctx, char **tasks[], size_t *numTasks);
293 
294 #endif /* __TASKDB_H__ */
unsigned long crinitTaskState_t
Type to store Task state bitmask.
Definition: crinit-sdefs.h:17
Definition: taskdb.h:21
int(* spawnFunc)(struct crinitTaskDB_t *ctx, const crinitTask_t *)
Definition: taskdb.h:27
bool spawnInhibit
Specifies if process spawning is currently inhibited, respected by crinitTaskDBSpawnReady().
Definition: taskdb.h:30
size_t taskSetSize
Current maximum size of the task array.
Definition: taskdb.h:23
pthread_cond_t changed
Condition variable to be signalled if taskSet or spawnInhibit is changed.
Definition: taskdb.h:34
pthread_mutex_t lock
Definition: taskdb.h:32
size_t taskSetItems
Number of elements in the task array.
Definition: taskdb.h:24
crinitTask_t * taskSet
Dynamic array of tasks, corresponds to task configs specified in the series config.
Definition: taskdb.h:22
Definition: task.h:38
Definition: task.h:54
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:96
int crinitTaskDBDestroy(crinitTaskDB_t *ctx)
Definition: taskdb.c:76
struct crinitTaskDB_t crinitTaskDB_t
int crinitTaskDBInitWithSize(crinitTaskDB_t *ctx, int(*spawnFunc)(crinitTaskDB_t *ctx, const crinitTask_t *), size_t initialSize)
Definition: taskdb.c:38
int crinitTaskDBGetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t *s, const char *taskName)
Definition: taskdb.c:231
int crinitTaskDBExportTaskNamesToArray(crinitTaskDB_t *ctx, char **tasks[], size_t *numTasks)
Definition: taskdb.c:460
int crinitTaskDBSetTaskPID(crinitTaskDB_t *ctx, pid_t pid, const char *taskName)
Definition: taskdb.c:251
int crinitTaskDBAddDepToTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName)
Definition: taskdb.c:312
int crinitTaskDBGetTaskPID(crinitTaskDB_t *ctx, pid_t *pid, const char *taskName)
Definition: taskdb.c:270
int crinitTaskDBProvideFeature(crinitTaskDB_t *ctx, const crinitTask_t *provider, crinitTaskState_t newState)
Definition: taskdb.c:421
int crinitTaskDBSetTaskState(crinitTaskDB_t *ctx, crinitTaskState_t s, const char *taskName)
Definition: taskdb.c:204
int crinitTaskDBSetSpawnInhibit(crinitTaskDB_t *ctx, bool inh)
Definition: taskdb.c:186
int crinitTaskDBSpawnReady(crinitTaskDB_t *ctx)
Definition: taskdb.c:148
int crinitTaskDBGetTaskStateAndPID(crinitTaskDB_t *ctx, crinitTaskState_t *s, pid_t *pid, const char *taskName)
Definition: taskdb.c:290
int crinitTaskDBRemoveDepFromTask(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const char *taskName)
Definition: taskdb.c:361
int crinitTaskDBFulfillDep(crinitTaskDB_t *ctx, const crinitTaskDep_t *dep, const crinitTask_t *target)
Definition: taskdb.c:390
int crinitTaskDBProvideFeatureByTaskName(crinitTaskDB_t *ctx, const char *taskName, crinitTaskState_t newState)
Definition: taskdb.c:442