Write mark PCF types for thread PVT

This commit is contained in:
Rodrigo Arias 2024-06-14 16:05:43 +02:00
parent ea79c90c89
commit b4d445b378
3 changed files with 59 additions and 14 deletions

View File

@ -23,6 +23,7 @@ struct mark_label {
struct mark_type {
long type;
long prvtype;
long index; /* From 0 to ntypes - 1 */
enum chan_type ctype;
struct mark_label *labels; /* Hash table of labels */
@ -155,6 +156,7 @@ create_mark_type(struct ovni_mark_emu *m, long type, const char *chan_type, cons
}
t->type = type;
t->prvtype = type + PRV_OVNI_MARK;
t->index = m->ntypes;
int len = snprintf(t->title, MAX_PCF_LABEL, "%s", title);
@ -352,7 +354,7 @@ connect_thread_prv(struct emu *emu, struct thread *sth, struct prv *prv)
struct chan *ch = &mth->channels[i];
long row = sth->gindex;
long flags = 0;
long prvtype = type->type + PRV_OVNI_MARK;
long prvtype = type->prvtype;
if (prv_register(prv, row, prvtype, &emu->bay, ch, flags)) {
err("prv_register failed");
return -1;
@ -362,6 +364,41 @@ connect_thread_prv(struct emu *emu, struct thread *sth, struct prv *prv)
return 0;
}
static int
create_type(struct pcf *pcf, struct mark_type *type)
{
struct pcf_type *pcftype = pcf_add_type(pcf, type->prvtype, type->title);
if (pcftype == NULL) {
err("pcf_add_type failed");
return -1;
}
for (struct mark_label *l = type->labels; l; l = l->hh.next) {
if (pcf_add_value(pcftype, l->value, l->label) == NULL) {
err("pcf_add_value failed");
return -1;
}
}
return 0;
}
static int
init_pcf(struct emu *emu, struct pcf *pcf)
{
struct ovni_emu *oemu = EXT(emu, 'O');
struct ovni_mark_emu *m = &oemu->mark;
for (struct mark_type *type = m->types; type; type = type->hh.next) {
if (create_type(pcf, type) != 0) {
err("create_type failed");
return -1;
}
}
return 0;
}
static int
connect_thread(struct emu *emu)
{
@ -381,7 +418,13 @@ connect_thread(struct emu *emu)
}
}
/* TODO: Init thread PCF */
/* Init thread PCF */
struct pcf *pcf = pvt_get_pcf(pvt);
if (init_pcf(emu, pcf) != 0) {
err("init_pcf failed");
return -1;
}
return 0;
}

View File

@ -29,4 +29,4 @@ test_emu(dummy.c NAME "ovniver" DRIVER "ovniver.driver.sh")
test_emu(dummy.c NAME "match-doc-events" DRIVER "match-doc-events.sh")
test_emu(dummy.c NAME "match-doc-version" DRIVER "match-doc-version.sh")
test_emu(libovni-attr.c)
test_emu(libovni-mark.c)
test_emu(libovni-mark.c MP)

View File

@ -7,32 +7,34 @@
enum {
MARK_COLORS = 1,
COL_RED = 1,
COL_BLUE = 2,
COL_GREEN = 3,
COL_BLUE = 1,
COL_GRAY = 2,
COL_RED = 3,
};
/* Check ovni_mark_* API. */
int
main(void)
{
instr_start(0, 1);
int rank = atoi(getenv("OVNI_RANK"));
int nranks = atoi(getenv("OVNI_NRANKS"));
instr_start(rank, nranks);
ovni_mark_type(MARK_COLORS, OVNI_MARK_STACK, "Colors");
if(!ovni_attr_has("ovni.mark.1.title"))
die("missing mark title");
ovni_mark_label(MARK_COLORS, 1, "Blue");
ovni_mark_label(MARK_COLORS, 2, "Gray");
ovni_mark_label(MARK_COLORS, 3, "Red");
ovni_mark_label(MARK_COLORS, COL_BLUE, "Blue");
ovni_mark_label(MARK_COLORS, COL_GRAY, "Gray");
ovni_mark_label(MARK_COLORS, COL_RED, "Red");
sleep_us(10); ovni_mark_push(MARK_COLORS, COL_RED);
sleep_us(10); ovni_mark_push(MARK_COLORS, COL_BLUE);
sleep_us(10); ovni_mark_push(MARK_COLORS, COL_GREEN);
sleep_us(10); ovni_mark_pop(MARK_COLORS, COL_GREEN);
sleep_us(10); ovni_mark_push(MARK_COLORS, COL_GRAY);
sleep_us(10); ovni_mark_push(MARK_COLORS, COL_RED);
sleep_us(50); ovni_mark_pop(MARK_COLORS, COL_RED);
sleep_us(10); ovni_mark_pop(MARK_COLORS, COL_GRAY);
sleep_us(10); ovni_mark_pop(MARK_COLORS, COL_BLUE);
sleep_us(10); ovni_mark_pop(MARK_COLORS, COL_RED);
instr_end();