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 17, 2018
1 parent 987172b commit 6d32bf6
Show file tree
Hide file tree
Showing 25 changed files with 81 additions and 96 deletions.
1 change: 0 additions & 1 deletion StateOS/README
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Features:
- modified context structures
- added dynamic tasks
- added create/destroy functions to c++ wrapper
- used flexible array members
---------
6.3
- merged test branch
Expand Down
7 changes: 4 additions & 3 deletions StateOS/kernel/inc/oseventqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: oseventqueue.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -56,6 +56,8 @@ 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;
};

/******************************************************************************
Expand Down Expand Up @@ -506,8 +508,7 @@ struct EventQueueT : public __evq
static
EventQueueT<limit_> *create( void )
{
struct __evq_data { evq_t evq; unsigned data[limit_]; };
static_assert(sizeof(__evq_data) == sizeof(EventQueueT<limit_>), "unexpected error!");
static_assert(sizeof(__evq) + limit_ * sizeof(unsigned) == sizeof(EventQueueT<limit_>), "unexpected error!");
return reinterpret_cast<EventQueueT<limit_> *>(evq_create(limit_));
}

Expand Down
10 changes: 5 additions & 5 deletions StateOS/kernel/inc/osjobqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osjobqueue.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -57,6 +57,8 @@ 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;
};

/******************************************************************************
Expand Down Expand Up @@ -505,8 +507,7 @@ struct JobQueueT : public __box
static
JobQueueT<limit_> *create( void )
{
struct __box_data { __box box; char data[limit_ * sizeof(FUN_t)]; };
static_assert(sizeof(__box_data) == sizeof(JobQueueT<limit_>), "unexpected error!");
static_assert(sizeof(__box) + limit_ * sizeof(FUN_t) == sizeof(JobQueueT<limit_>), "unexpected error!");
return reinterpret_cast<JobQueueT<limit_> *>(box_create(limit_, sizeof(FUN_t)));
}

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

Expand Down
10 changes: 5 additions & 5 deletions StateOS/kernel/inc/osmailboxqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osmailboxqueue.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -57,6 +57,8 @@ 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;
};

/******************************************************************************
Expand Down Expand Up @@ -554,8 +556,7 @@ struct MailBoxQueueT : public __box
static
MailBoxQueueT<limit_, size_> *create( void )
{
struct __box_data { __box box; char data[limit_ * size_]; };
static_assert(sizeof(__box_data) == sizeof(MailBoxQueueT<limit_, size_>), "unexpected error!");
static_assert(sizeof(__box) + limit_ * size_ == sizeof(MailBoxQueueT<limit_, size_>), "unexpected error!");
return reinterpret_cast<MailBoxQueueT<limit_, size_> *>(box_create(limit_, size_));
}

Expand Down Expand Up @@ -606,8 +607,7 @@ struct MailBoxQueueTT : public MailBoxQueueT<limit_, sizeof(T)>
static
MailBoxQueueTT<limit_, T> *create( void )
{
struct __box_data { __box box; char data[limit_ * sizeof(T)]; };
static_assert(sizeof(__box_data) == sizeof(MailBoxQueueTT<limit_, T>), "unexpected error!");
static_assert(sizeof(__box) + limit_ * sizeof(T) == sizeof(MailBoxQueueTT<limit_, T>), "unexpected error!");
return reinterpret_cast<MailBoxQueueTT<limit_, T> *>(box_create(limit_, sizeof(T)));
}

Expand Down
10 changes: 5 additions & 5 deletions StateOS/kernel/inc/osmemorypool.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osmemorypool.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -59,6 +59,8 @@ 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;
};

/******************************************************************************
Expand Down Expand Up @@ -440,8 +442,7 @@ struct MemoryPoolT : public __mem
static
MemoryPoolT<limit_, size_> *create( void )
{
struct __mem_data { __mem mem; que_t data[limit_ * (1 + MEM_SIZE(size_))]; };
static_assert(sizeof(__mem_data) == sizeof(MemoryPoolT<limit_, size_>), "unexpected error!");
static_assert(sizeof(__mem) + limit_ * (1 + MEM_SIZE(size_)) * sizeof(que_t) == sizeof(MemoryPoolT<limit_, size_>), "unexpected error!");
return reinterpret_cast<MemoryPoolT<limit_, size_> *>(mem_create(limit_, size_));
}

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

Expand Down
10 changes: 5 additions & 5 deletions StateOS/kernel/inc/osmessagebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osmessagebuffer.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -56,6 +56,8 @@ struct __msg
unsigned head; // inherited from stream buffer
unsigned tail; // inherited from stream buffer
char * data; // inherited from stream buffer

char :0;
};

/******************************************************************************
Expand Down Expand Up @@ -621,8 +623,7 @@ struct MessageBufferT : public __msg
static
MessageBufferT<limit_> *create( void )
{
struct __msg_data { __msg msg; char data[limit_]; };
static_assert(sizeof(__msg_data) == sizeof(MessageBufferT<limit_>), "unexpected error!");
static_assert(sizeof(__msg) + limit_ == sizeof(MessageBufferT<limit_>), "unexpected error!");
return reinterpret_cast<MessageBufferT<limit_> *>(msg_create(limit_));
}

Expand Down Expand Up @@ -675,8 +676,7 @@ struct MessageBufferTT : public MessageBufferT<limit_ * (sizeof(unsigned) + size
static
MessageBufferTT<limit_, T> *create( void )
{
struct __msg_data { __msg msg; char data[limit_ * (sizeof(unsigned) + sizeof(T))]; };
static_assert(sizeof(__msg_data) == sizeof(MessageBufferTT<limit_, T>), "unexpected error!");
static_assert(sizeof(__msg) + 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
10 changes: 5 additions & 5 deletions StateOS/kernel/inc/osstreambuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osstreambuffer.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -56,6 +56,8 @@ 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;
};

/******************************************************************************
Expand Down Expand Up @@ -596,8 +598,7 @@ struct StreamBufferT : public __stm
static
StreamBufferT<limit_> *create( void )
{
struct __stm_data { __stm stm; char data[limit_]; };
static_assert(sizeof(__stm_data) == sizeof(StreamBufferT<limit_>), "unexpected error!");
static_assert(sizeof(__stm) + limit_ == sizeof(StreamBufferT<limit_>), "unexpected error!");
return reinterpret_cast<StreamBufferT<limit_> *>(stm_create(limit_));
}

Expand Down Expand Up @@ -648,8 +649,7 @@ struct StreamBufferTT : public StreamBufferT<limit_ * sizeof(T)>
static
StreamBufferTT<limit_, T> *create( void )
{
struct __stm_data { __stm stm; char data[limit_ * sizeof(T)]; };
static_assert(sizeof(__stm_data) == sizeof(StreamBufferTT<limit_, T>), "unexpected error!");
static_assert(sizeof(__stm) + limit_ * sizeof(T) == sizeof(StreamBufferTT<limit_, T>), "unexpected error!");
return reinterpret_cast<StreamBufferTT<limit_, T> *>(stm_create(limit_ * sizeof(T)));
}

Expand Down
9 changes: 4 additions & 5 deletions StateOS/kernel/inc/ostask.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: ostask.h
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file contains definitions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -180,6 +180,7 @@ struct __tsk
#else
#define _TSK_EXTRA
#endif
stk_t :0;
};

/******************************************************************************
Expand Down Expand Up @@ -1316,8 +1317,7 @@ struct TaskT : public baseTask
{
CriticalSection cs;
TaskT<size_> *tsk;
struct __tsk_data { tsk_t tsk; stk_t data[STK_SIZE(size_)]; };
static_assert(sizeof(__tsk_data) == sizeof(TaskT<size_>), "unexpected error!");
static_assert(sizeof(__tsk) + STK_SIZE(size_) * sizeof(stk_t) == 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,8 +1332,7 @@ struct TaskT : public baseTask
{
CriticalSection cs;
TaskT<size_> *tsk;
struct __tsk_data { tsk_t tsk; stk_t data[STK_SIZE(size_)]; };
static_assert(sizeof(__tsk_data) == sizeof(TaskT<size_>), "unexpected error!");
static_assert(sizeof(__tsk) + STK_SIZE(size_) * sizeof(stk_t) == 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
4 changes: 2 additions & 2 deletions StateOS/kernel/src/osbarrier.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osbarrier.c
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -63,7 +63,7 @@ bar_t *bar_create( unsigned limit )

sys_lock();
{
bar = sys_alloc(sizeof(struct __bar));
bar = sys_alloc(sizeof(bar_t));
bar_init(bar, limit);
bar->obj.res = bar;
}
Expand Down
4 changes: 2 additions & 2 deletions StateOS/kernel/src/osconditionvariable.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osconditionvariable.c
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -59,7 +59,7 @@ cnd_t *cnd_create( void )

sys_lock();
{
cnd = sys_alloc(sizeof(struct __cnd));
cnd = sys_alloc(sizeof(cnd_t));
cnd_init(cnd);
cnd->obj.res = cnd;
}
Expand Down
4 changes: 2 additions & 2 deletions StateOS/kernel/src/osevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osevent.c
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -58,7 +58,7 @@ evt_t *evt_create( void )

sys_lock();
{
evt = sys_alloc(sizeof(struct __evt));
evt = sys_alloc(sizeof(evt_t));
evt_init(evt);
evt->obj.res = evt;
}
Expand Down
10 changes: 4 additions & 6 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 16.11.2018
@date 17.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -61,18 +61,16 @@ evq_t *evq_create( unsigned limit )
{
evq_t * evq;
unsigned bufsize;
struct __evq_data { evq_t evq; unsigned data[]; } *tmp;

assert_tsk_context();
assert(limit);

sys_lock();
{
bufsize = limit * sizeof(unsigned);
tmp = sys_alloc(sizeof(struct __evq_data) + bufsize);
evq = &tmp->evq;
evq_init(evq, tmp->data, bufsize);
evq->obj.res = tmp;
evq = sys_alloc(sizeof(evq_t) + bufsize);
evq_init(evq, (void *)(evq + 1), bufsize);
evq->obj.res = evq;
}
sys_unlock();

Expand Down
4 changes: 2 additions & 2 deletions StateOS/kernel/src/osfastmutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osfastmutex.c
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -59,7 +59,7 @@ mut_t *mut_create( void )

sys_lock();
{
mut = sys_alloc(sizeof(struct __mut));
mut = sys_alloc(sizeof(mut_t));
mut_init(mut);
mut->obj.res = mut;
}
Expand Down
4 changes: 2 additions & 2 deletions StateOS/kernel/src/osflag.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file StateOS: osflag.c
@author Rajmund Szymanski
@date 16.11.2018
@date 17.11.2018
@brief This file provides set of functions for StateOS.
******************************************************************************
Expand Down Expand Up @@ -62,7 +62,7 @@ flg_t *flg_create( unsigned init )

sys_lock();
{
flg = sys_alloc(sizeof(struct __flg));
flg = sys_alloc(sizeof(flg_t));
flg_init(flg, init);
flg->obj.res = flg;
}
Expand Down
Loading

0 comments on commit 6d32bf6

Please sign in to comment.