thread data structure

Discussions and support about ChibiOS/RT, the free embedded RTOS.
Post Reply
Khan
Posts: 9
Joined: Thu Mar 02, 2017 12:54 pm
Has thanked: 1 time

thread data structure

Post by Khan »

Hi
I'm trying to implement data structure in scheduler, but when I initialize it in:
chschd.c
void _scheduler_init(void) {
ch.rlist.dl = (systime_t)50;
}
I get big number in:
thread_t *chSchReadyI(thread_t *tp) {
cp = (thread_t *)&ch.rlist.queue;
cp->dl //-> this is not 50
}

chschd.h
struct ch_thread{[/b]
systime_t dl;
}

struct ch_ready_list{
systime_t dl;
}
I thing that problem is in allocate memory but I don't find out issue.
When I try:
chschd.c
void _scheduler_init(void) {
thread_t *cp;
queue_init(&ch.rlist.queue);

ch.rlist.prio = 0;
ch.rlist.dl = (systime_t)50;
cp = (thread_t *)&ch.rlist.queue;
cp->dl -> this is 0 and not 50.
}
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: thread data structure

Post by Giovanni »

I can only point out that the first fields of the thread structure and ready list structure must be the same because list handling, apparently this is not the case in your modification.

Giovanni
Khan
Posts: 9
Joined: Thu Mar 02, 2017 12:54 pm
Has thanked: 1 time

Re: thread data structure

Post by Khan »

Hi,

When i copied lines in structures (thread, ready list), it solved my problem. Can you explain it to me ? I thought that in c it does no matter how is structure written. Is it because I cast it in pointer of thread like: cp = (thread_t *)&ch.rlist.queue;

Thank you

Khan
Khan
Posts: 9
Joined: Thu Mar 02, 2017 12:54 pm
Has thanked: 1 time

Re: thread data structure

Post by Khan »

Hi

What is difference between preempt and time in thread data structure ?

Khan.
User avatar
Giovanni
Site Admin
Posts: 14891
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: thread data structure

Post by Giovanni »

Preempt is the number of ticks until next round robin event, time is the time consumed by the thread in ticks.

Giovanni
Post Reply