49 lines
860 B
C
49 lines
860 B
C
#include "ufd.h"
|
|
#include "stdlib.h"
|
|
#include <sys/queue.h>
|
|
|
|
|
|
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
|
{
|
|
TAILQ_INIT(&ufd->children);
|
|
ufd->thread = thread;
|
|
ufd->repr = ufd,
|
|
ufd->parent = NULL;
|
|
}
|
|
|
|
|
|
void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
|
{
|
|
struct ufd_t* a = ufd__find(th1);
|
|
struct ufd_t* b = ufd__find(th2);
|
|
|
|
if (a != b)
|
|
{
|
|
a->parent = th2;
|
|
a->repr = b;
|
|
TAILQ_INSERT_TAIL(&a->repr->children, a, link);
|
|
}
|
|
}
|
|
|
|
|
|
struct ufd_t* ufd__find(struct ufd_t* th)
|
|
{
|
|
if (th->repr == th)
|
|
return th;
|
|
|
|
struct ufd_t* nrepr = ufd__find(th->repr);
|
|
th->repr = nrepr;
|
|
return nrepr;
|
|
}
|
|
|
|
|
|
void ufd__delete(struct ufd_t* th)
|
|
{
|
|
struct ufd_t* child;
|
|
|
|
TAILQ_FOREACH(child, &th->children, link) {
|
|
child->parent = NULL;
|
|
child->repr = child;
|
|
}
|
|
}
|