Skip to content

Commit

Permalink
updated create functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajmund Szymanski committed Nov 19, 2018
1 parent bfa5f66 commit 6c54169
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 54 deletions.
13 changes: 10 additions & 3 deletions StateOS/kernel/inc/oseventqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ struct __evq
unsigned head; // first element to read from data buffer
unsigned tail; // first element to write into data buffer
unsigned*data; // data buffer

unsigned :0;
};

#ifdef __cplusplus
}
template<unsigned limit_>
struct evq_T { evq_t evq; unsigned buf[limit_]; };
extern "C" {
#else
struct evq_T { evq_t evq; unsigned buf[]; };
#endif

/******************************************************************************
*
* Name : _EVQ_INIT
Expand Down Expand Up @@ -508,7 +515,7 @@ struct EventQueueT : public __evq
static
EventQueueT<limit_> *create( void )
{
static_assert(sizeof(__evq) + limit_ * sizeof(unsigned) == sizeof(EventQueueT<limit_>), "unexpected error!");
static_assert(sizeof(evq_T<limit_>) == sizeof(EventQueueT<limit_>), "unexpected error!");
return reinterpret_cast<EventQueueT<limit_> *>(evq_create(limit_));
}

Expand Down
15 changes: 11 additions & 4 deletions StateOS/kernel/inc/osjobqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ struct __job
unsigned head; // first element to read from data buffer
unsigned tail; // first element to write into data buffer
fun_t ** data; // data buffer

intptr_t :0;
};

#ifdef __cplusplus
}
template<unsigned limit_>
struct job_T { job_t job; fun_t *buf[limit_]; };
extern "C" {
#else
struct job_T { job_t job; fun_t *buf[]; };
#endif

/******************************************************************************
*
* Name : _JOB_INIT
Expand Down Expand Up @@ -507,7 +514,7 @@ struct JobQueueT : public __box
static
JobQueueT<limit_> *create( void )
{
static_assert(sizeof(__box) + limit_ * sizeof(FUN_t) == sizeof(JobQueueT<limit_>), "unexpected error!");
static_assert(sizeof(box_T<limit_, sizeof(FUN_t)>) == sizeof(JobQueueT<limit_>), "unexpected error!");
return reinterpret_cast<JobQueueT<limit_> *>(box_create(limit_, sizeof(FUN_t)));
}

Expand Down Expand Up @@ -549,7 +556,7 @@ struct JobQueueT : public __job
static
JobQueueT<limit_> *create( void )
{
static_assert(sizeof(__job) + limit_ * sizeof(FUN_t) == sizeof(JobQueueT<limit_>), "unexpected error!");
static_assert(sizeof(job_T<limit_>) == sizeof(JobQueueT<limit_>), "unexpected error!");
return reinterpret_cast<JobQueueT<limit_> *>(job_create(limit_));
}

Expand Down
15 changes: 11 additions & 4 deletions StateOS/kernel/inc/osmailboxqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ struct __box
unsigned head; // first element to read from data buffer
unsigned tail; // first element to write into data buffer
char * data; // data buffer

char :0;
};

#ifdef __cplusplus
}
template<unsigned limit_, unsigned size_>
struct box_T { box_t box; char buf[limit_ * size_]; };
extern "C" {
#else
struct box_T { box_t box; char buf[]; };
#endif

/******************************************************************************
*
* Name : _BOX_INIT
Expand Down Expand Up @@ -556,7 +563,7 @@ struct MailBoxQueueT : public __box
static
MailBoxQueueT<limit_, size_> *create( void )
{
static_assert(sizeof(__box) + limit_ * size_ == sizeof(MailBoxQueueT<limit_, size_>), "unexpected error!");
static_assert(sizeof(box_T<limit_, size_>) == sizeof(MailBoxQueueT<limit_, size_>), "unexpected error!");
return reinterpret_cast<MailBoxQueueT<limit_, size_> *>(box_create(limit_, size_));
}

Expand Down Expand Up @@ -607,7 +614,7 @@ struct MailBoxQueueTT : public MailBoxQueueT<limit_, sizeof(T)>
static
MailBoxQueueTT<limit_, T> *create( void )
{
static_assert(sizeof(__box) + limit_ * sizeof(T) == sizeof(MailBoxQueueTT<limit_, T>), "unexpected error!");
static_assert(sizeof(box_T<limit_, sizeof(T)>) == sizeof(MailBoxQueueTT<limit_, T>), "unexpected error!");
return reinterpret_cast<MailBoxQueueTT<limit_, T> *>(box_create(limit_, sizeof(T)));
}

Expand Down
15 changes: 11 additions & 4 deletions StateOS/kernel/inc/osmemorypool.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,17 @@ struct __mem
unsigned limit; // size of a memory pool (max number of objects)
unsigned size; // size of memory object (in sizeof(que_t) units)
que_t * data; // pointer to memory pool buffer

intptr_t :0;
};

#ifdef __cplusplus
}
template<unsigned limit_, unsigned size_>
struct mem_T { mem_t mem; que_t buf[limit_ * (1 + MEM_SIZE(size_))]; };
extern "C" {
#else
struct mem_T { mem_t mem; que_t buf[]; };
#endif

/******************************************************************************
*
* Name : _MEM_INIT
Expand Down Expand Up @@ -442,7 +449,7 @@ struct MemoryPoolT : public __mem
static
MemoryPoolT<limit_, size_> *create( void )
{
static_assert(sizeof(__mem) + limit_ * (1 + MEM_SIZE(size_)) * sizeof(que_t) == sizeof(MemoryPoolT<limit_, size_>), "unexpected error!");
static_assert(sizeof(mem_T<limit_, size_>) == sizeof(MemoryPoolT<limit_, size_>), "unexpected error!");
return reinterpret_cast<MemoryPoolT<limit_, size_> *>(mem_create(limit_, size_));
}

Expand Down Expand Up @@ -482,7 +489,7 @@ struct MemoryPoolTT : public MemoryPoolT<limit_, sizeof(T)>
static
MemoryPoolTT<limit_, T> *create( void )
{
static_assert(sizeof(__mem) + limit_ * (1 + MEM_SIZE(sizeof(T))) * sizeof(que_t) == sizeof(MemoryPoolTT<limit_, T>), "unexpected error!");
static_assert(sizeof(mem_T<limit_, sizeof(T)>) == sizeof(MemoryPoolTT<limit_, T>), "unexpected error!");
return reinterpret_cast<MemoryPoolTT<limit_, T> *>(mem_create(limit_, sizeof(T)));
}

Expand Down
15 changes: 11 additions & 4 deletions StateOS/kernel/inc/osmessagebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ struct __msg
unsigned head; // inherited from stream buffer
unsigned tail; // inherited from stream buffer
char * data; // inherited from stream buffer

char :0;
};

#ifdef __cplusplus
}
template<unsigned limit_>
struct msg_T { msg_t msg; char buf[limit_]; };
extern "C" {
#else
struct msg_T { msg_t msg; char buf[]; };
#endif

/******************************************************************************
*
* Name : _MSG_INIT
Expand Down Expand Up @@ -623,7 +630,7 @@ struct MessageBufferT : public __msg
static
MessageBufferT<limit_> *create( void )
{
static_assert(sizeof(__msg) + limit_ == sizeof(MessageBufferT<limit_>), "unexpected error!");
static_assert(sizeof(msg_T<limit_>) == sizeof(MessageBufferT<limit_>), "unexpected error!");
return reinterpret_cast<MessageBufferT<limit_> *>(msg_create(limit_));
}

Expand Down Expand Up @@ -676,7 +683,7 @@ struct MessageBufferTT : public MessageBufferT<limit_ * (sizeof(unsigned) + size
static
MessageBufferTT<limit_, T> *create( void )
{
static_assert(sizeof(__msg) + limit_ * (sizeof(unsigned) + sizeof(T)) == sizeof(MessageBufferTT<limit_, T>), "unexpected error!");
static_assert(sizeof(msg_T<limit_ * (sizeof(unsigned) + sizeof(T))>) == sizeof(MessageBufferTT<limit_, T>), "unexpected error!");
return reinterpret_cast<MessageBufferTT<limit_, T> *>(msg_create(limit_ * (sizeof(unsigned) + sizeof(T))));
}

Expand Down
15 changes: 11 additions & 4 deletions StateOS/kernel/inc/osstreambuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,17 @@ struct __stm
unsigned head; // first element to read from data buffer
unsigned tail; // first element to write into data buffer
char * data; // data buffer

char :0;
};

#ifdef __cplusplus
}
template<unsigned limit_>
struct stm_T { stm_t stm; char buf[limit_]; };
extern "C" {
#else
struct stm_T { stm_t stm; char buf[]; };
#endif

/******************************************************************************
*
* Name : _STM_INIT
Expand Down Expand Up @@ -598,7 +605,7 @@ struct StreamBufferT : public __stm
static
StreamBufferT<limit_> *create( void )
{
static_assert(sizeof(__stm) + limit_ == sizeof(StreamBufferT<limit_>), "unexpected error!");
static_assert(sizeof(stm_T<limit_>) == sizeof(StreamBufferT<limit_>), "unexpected error!");
return reinterpret_cast<StreamBufferT<limit_> *>(stm_create(limit_));
}

Expand Down Expand Up @@ -649,7 +656,7 @@ struct StreamBufferTT : public StreamBufferT<limit_ * sizeof(T)>
static
StreamBufferTT<limit_, T> *create( void )
{
static_assert(sizeof(__stm) + limit_ * sizeof(T) == sizeof(StreamBufferTT<limit_, T>), "unexpected error!");
static_assert(sizeof(stm_T<limit_ * sizeof(T)>) == sizeof(StreamBufferTT<limit_, T>), "unexpected error!");
return reinterpret_cast<StreamBufferTT<limit_, T> *>(stm_create(limit_ * sizeof(T)));
}

Expand Down
14 changes: 11 additions & 3 deletions StateOS/kernel/inc/ostask.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,17 @@ struct __tsk
#else
#define _TSK_EXTRA
#endif
stk_t :0;
};

#ifdef __cplusplus
}
template<unsigned limit_>
struct tsk_T { tsk_t tsk; stk_t buf[STK_SIZE(limit_)]; };
extern "C" {
#else
struct tsk_T { tsk_t tsk; stk_t buf[]; };
#endif

/******************************************************************************
*
* Name : _TSK_INIT
Expand Down Expand Up @@ -1317,7 +1325,7 @@ struct TaskT : public baseTask
{
CriticalSection cs;
TaskT<size_> *tsk;
static_assert(sizeof(__tsk) + STK_SIZE(size_) * sizeof(stk_t) == sizeof(TaskT<size_>), "unexpected error!");
static_assert(sizeof(tsk_T<size_>) == sizeof(TaskT<size_>), "unexpected error!");
#if OS_FUNCTIONAL
tsk = reinterpret_cast<TaskT<size_> *>(wrk_create(_prio, baseTask::fun_, size_));
tsk->__tsk::fun = _state;
Expand All @@ -1332,7 +1340,7 @@ struct TaskT : public baseTask
{
CriticalSection cs;
TaskT<size_> *tsk;
static_assert(sizeof(__tsk) + STK_SIZE(size_) * sizeof(stk_t) == sizeof(TaskT<size_>), "unexpected error!");
static_assert(sizeof(tsk_T<size_>) == sizeof(TaskT<size_>), "unexpected error!");
#if OS_FUNCTIONAL
tsk = reinterpret_cast<TaskT<size_> *>(wrk_detached(_prio, baseTask::fun_, size_));
tsk->__tsk::fun = _state;
Expand Down
11 changes: 7 additions & 4 deletions StateOS/kernel/src/oseventqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: oseventqueue.c
@author Rajmund Szymanski
@date 17.11.2018
@date 19.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -59,6 +59,8 @@ void evq_init( evq_t *evq, unsigned *data, unsigned bufsize )
evq_t *evq_create( unsigned limit )
/* -------------------------------------------------------------------------- */
{
struct
evq_T * tmp;
evq_t * evq;
unsigned bufsize;

Expand All @@ -68,9 +70,10 @@ evq_t *evq_create( unsigned limit )
sys_lock();
{
bufsize = limit * sizeof(unsigned);
evq = sys_alloc(sizeof(evq_t) + bufsize);
evq_init(evq, (void *)(evq + 1), bufsize);
evq->obj.res = evq;
tmp = sys_alloc(sizeof(struct evq_T) + bufsize);
evq = &tmp->evq;
evq_init(evq, tmp->buf, bufsize);
evq->obj.res = tmp;
}
sys_unlock();

Expand Down
11 changes: 7 additions & 4 deletions StateOS/kernel/src/osjobqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osjobqueue.c
@author Rajmund Szymanski
@date 17.11.2018
@date 19.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -59,6 +59,8 @@ void job_init( job_t *job, fun_t **data, unsigned bufsize )
job_t *job_create( unsigned limit )
/* -------------------------------------------------------------------------- */
{
struct
job_T * tmp;
job_t * job;
unsigned bufsize;

Expand All @@ -68,9 +70,10 @@ job_t *job_create( unsigned limit )
sys_lock();
{
bufsize = limit * sizeof(fun_t *);
job = sys_alloc(sizeof(job_t) + bufsize);
job_init(job, (void *)(job + 1), bufsize);
job->obj.res = job;
tmp = sys_alloc(sizeof(struct job_T) + bufsize);
job = &tmp->job;
job_init(job, tmp->buf, bufsize);
job->obj.res = tmp;
}
sys_unlock();

Expand Down
11 changes: 7 additions & 4 deletions StateOS/kernel/src/osmailboxqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osmailboxqueue.c
@author Rajmund Szymanski
@date 17.11.2018
@date 19.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -61,6 +61,8 @@ void box_init( box_t *box, unsigned size, void *data, unsigned bufsize )
box_t *box_create( unsigned limit, unsigned size )
/* -------------------------------------------------------------------------- */
{
struct
box_T * tmp;
box_t * box;
unsigned bufsize;

Expand All @@ -71,9 +73,10 @@ box_t *box_create( unsigned limit, unsigned size )
sys_lock();
{
bufsize = limit * size;
box = sys_alloc(sizeof(box_t) + bufsize);
box_init(box, size, (void *)(box + 1), bufsize);
box->obj.res = box;
tmp = sys_alloc(sizeof(struct box_T) + bufsize);
box = &tmp->box;
box_init(box, size, tmp->buf, bufsize);
box->obj.res = tmp;
}
sys_unlock();

Expand Down
11 changes: 7 additions & 4 deletions StateOS/kernel/src/osmemorypool.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osmemorypool.c
@author Rajmund Szymanski
@date 17.11.2018
@date 19.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -87,6 +87,8 @@ void mem_init( mem_t *mem, unsigned size, que_t *data, unsigned bufsize )
mem_t *mem_create( unsigned limit, unsigned size )
/* -------------------------------------------------------------------------- */
{
struct
mem_T * tmp;
mem_t * mem;
unsigned bufsize;

Expand All @@ -97,9 +99,10 @@ mem_t *mem_create( unsigned limit, unsigned size )
sys_lock();
{
bufsize = limit * (1 + MEM_SIZE(size)) * sizeof(que_t);
mem = sys_alloc(sizeof(mem_t) + bufsize);
mem_init(mem, size, (void *)(mem + 1), bufsize);
mem->lst.obj.res = mem;
tmp = sys_alloc(sizeof(struct mem_T) + bufsize);
mem = &tmp->mem;
mem_init(mem, size, tmp->buf, bufsize);
mem->lst.obj.res = tmp;
}
sys_unlock();

Expand Down
Loading

0 comments on commit 6c54169

Please sign in to comment.