fix: use list to store children in ufd
This commit is contained in:
parent
0639823009
commit
e292bd7797
@ -1,18 +1,20 @@
|
||||
#include "ufd.h"
|
||||
#include "debug.h"
|
||||
#include "stdlib.h"
|
||||
#include <sys/queue.h>
|
||||
|
||||
|
||||
void ufd__init(struct ufd_t* ufd, struct context_entry_t* thread)
|
||||
inline 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;
|
||||
ufd->child = NULL;
|
||||
}
|
||||
|
||||
|
||||
void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
||||
inline 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);
|
||||
@ -20,29 +22,35 @@ void ufd__join(struct ufd_t* th1, struct ufd_t* th2)
|
||||
if (a != b)
|
||||
{
|
||||
a->parent = th2;
|
||||
th2->child = a;
|
||||
a->repr = b;
|
||||
TAILQ_INSERT_TAIL(&a->repr->children, a, link);
|
||||
TAILQ_INSERT_TAIL(&b->repr->children, a, link);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct ufd_t* ufd__find(struct ufd_t* th)
|
||||
inline struct ufd_t* ufd__find(struct ufd_t* th)
|
||||
{
|
||||
if (th->repr == th)
|
||||
return th;
|
||||
|
||||
struct ufd_t* nrepr = ufd__find(th->repr);
|
||||
TAILQ_REMOVE(&th->repr->children, th, link);
|
||||
TAILQ_INSERT_TAIL(&nrepr->children, th, link);
|
||||
th->repr = nrepr;
|
||||
return nrepr;
|
||||
}
|
||||
|
||||
|
||||
void ufd__delete(struct ufd_t* th)
|
||||
inline void ufd__delete(struct ufd_t* th)
|
||||
{
|
||||
struct ufd_t* child;
|
||||
struct ufd_t* child = NULL;
|
||||
|
||||
TAILQ_FOREACH(child, &th->children, link) {
|
||||
child->parent = NULL;
|
||||
child->repr = child;
|
||||
TAILQ_FOREACH(child, &th->children, link)
|
||||
{
|
||||
if (child->parent == th)
|
||||
child->parent = th->child;
|
||||
if (child->repr == th)
|
||||
child->repr = th->child;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ TAILQ_HEAD(ufd_children_t, ufd_t);
|
||||
struct ufd_t {
|
||||
struct ufd_t* parent;
|
||||
struct ufd_t* repr;
|
||||
struct ufd_t* child;
|
||||
struct context_entry_t* thread;
|
||||
struct ufd_children_t children;
|
||||
TAILQ_ENTRY(ufd_t) link;
|
||||
|
Loading…
x
Reference in New Issue
Block a user