shithub: lpa

ref: 1da09c81867fc8416f99b8d7a24d73b2e3acf6e6
dir: /module.c/

View raw version
#include <u.h>
#include <libc.h>
#include <thread.h>

#include "dat.h"
#include "fns.h"

Module *
addmodule(Session *s, char *name)
{
	static uvlong id = 1;

	Module *m = alloc(DataModule);
	m->name = strdup(name);
	m->symtab = allocsymtab();
	m->id = id++;

	wlock(&s->modules->lock);
	s->modules->count++;
	s->modules->modules = allocextra(s->modules, sizeof(Module *) * s->modules->count);
	s->modules->modules[s->modules->count-1] = m;
	wunlock(&s->modules->lock);

	return m;
}

Enumeration *
enummodules(Session *s)
{
	rlock(&s->modules->lock);
	Enumeration *e = allocenum(s->modules->count);
	for(uvlong i = 0; i < s->modules->count; i++)
		e->items[i] = s->modules->modules[i];
	runlock(&s->modules->lock);
	return e;
}