skip to content
[readonly]
==> src/internal.h <==
1/* mesh-jobd's own state: the events on sh->blobs, the area's state in sh->jobs_ext, the threads. */
2#ifndef MESH_JOBD_INTERNAL_H
3#define MESH_JOBD_INTERNAL_H
4#include "mesh/blobd/blobd.h"
5#include "mesh/jobd/jobd.h"
6#include "mesh/jobd/store.h"
7#include "mesh/reply.h"
8
9#include <pthread.h>
10#include <stdatomic.h>
11
12/* The blob thread's events (blobd.rs BlobEvent). */
13typedef enum {
14    MJD_BEV_LOCAL,   /* job, hash, bytes: this member's own payload */
15    MJD_BEV_PUSH,    /* to, job, hash */
16    MJD_BEV_FETCH,   /* job, hash, holders */
17    MJD_BEV_DONE,    /* job, hash */
18    MJD_BEV_FRAME,   /* from, ty, bytes: the body after the length */
19    MJD_BEV_TABLE,   /* news */
20    MJD_BEV_RENDER,  /* words, reply */
21    MJD_BEV_WRITTEN, /* job, hash, why, from, ok, err */
22} mjd_bev_kind;
23
24typedef struct {
25    mjd_bev_kind k;
26    uint32_t from, to, holders;
27    uint8_t ty;
28    mj_job_id job;
29    mj_hash hash;
30    uint8_t *bytes;
31    size_t n;
32    mbd_news *news;
33    char **words;
34    size_t nwords;
35    mesh_reply *reply;
36    mbd_why why;
37    bool ok;
38    char *err;
39} mjd_bev;
40
41void mjd_bev_free(void *e);
42/* Sends on sh->blobs (an event that cannot be sent is freed). */
43void mjd_blobs_send(mesh_shared *sh, mjd_bev *e);
44
45/* sh->jobs_ext: what the fleet thread and the blob thread give the jobs thread. */
46typedef struct {
47    pthread_mutex_t mu;
48    mj_view view;
49    mj_sched *sched;    /* the scheduler's model not picked up yet */
50    mj_job_id *watch;   /* the images assembled here (blobd: render_watch) */
51    size_t nwatch, capwatch;
52} mjd_ext;
53
54static inline mjd_ext *mjd_ext_of(mesh_shared *sh) { return sh->jobs_ext; }
55mj_view mjd_ext_view(mesh_shared *sh);
56/* A copy of the watch set (free it). */
57size_t mjd_ext_watch(mesh_shared *sh, mj_job_id **out);
58void mjd_ext_set_watch(mesh_shared *sh, mj_job_id id, bool on);
59
60struct mjd {
61    mesh_shared *sh;
62    mjd_ext *ext;
63    mj_cfg cfg;
64    mjd_store *store;
65    mj_replica rep; /* the jobs thread's node takes it */
66    mb_store *bstore; /* the blob thread's mbd takes it */
67    mesh_chan *wq;    /* mbd_write, to the writers */
68    pthread_t jobs_t, blobs_t, writers[MESH_BLOBD_WRITERS];
69    _Atomic bool stop;
70    bool started;
71};
72
73void *mjd_jobs_main(void *d);
74void *mjd_blobs_main(void *d);
75void *mjd_writer_main(void *d);
76
77#endif