Skip to content

Commit 8f5076f

Browse files
author
Rajmund Szymanski
committed
rebuilded sleep and suspend / resume functions
1 parent c31f242 commit 8f5076f

File tree

3 files changed

+50
-51
lines changed

3 files changed

+50
-51
lines changed

IntrOS/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Features:
5555
- reorganized kernel functions
5656
- changed timer / task header
5757
- added header init function
58+
- rebuilded sleep and suspend / resume functions
5859
---------
5960
4.1
6061
- updated mailbox queue object

IntrOS/kernel/inc/ostask.h

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -640,16 +640,14 @@ void tsk_give( tsk_t *tsk, unsigned flags );
640640
* IMMEDIATE: don't delay execution of current task
641641
* INFINITE: delay indefinitely execution of current task
642642
*
643-
* Return
644-
* E_SUCCESS : task object successfully finished countdown
645-
* E_FAILURE : task was resumed
643+
* Return : none
646644
*
647645
******************************************************************************/
648646

649-
unsigned tsk_sleepFor( cnt_t delay );
647+
void tsk_sleepFor( cnt_t delay );
650648

651649
__STATIC_INLINE
652-
unsigned tsk_delay( cnt_t delay ) { return tsk_sleepFor(delay); }
650+
void tsk_delay( cnt_t delay ) { tsk_sleepFor(delay); }
653651

654652
/******************************************************************************
655653
*
@@ -663,13 +661,11 @@ unsigned tsk_delay( cnt_t delay ) { return tsk_sleepFor(delay); }
663661
* IMMEDIATE: don't delay execution of current task
664662
* INFINITE: delay indefinitely execution of current task
665663
*
666-
* Return
667-
* E_SUCCESS : task object successfully finished countdown
668-
* E_FAILURE : task was resumed
664+
* Return : none
669665
*
670666
******************************************************************************/
671667

672-
unsigned tsk_sleepNext( cnt_t delay );
668+
void tsk_sleepNext( cnt_t delay );
673669

674670
/******************************************************************************
675671
*
@@ -680,35 +676,34 @@ unsigned tsk_sleepNext( cnt_t delay );
680676
* Parameters
681677
* time : timepoint value
682678
*
683-
* Return
684-
* E_SUCCESS : task object successfully finished countdown
685-
* E_FAILURE : task was resumed
679+
* Return : none
686680
*
687681
******************************************************************************/
688682

689-
unsigned tsk_sleepUntil( cnt_t time );
683+
void tsk_sleepUntil( cnt_t time );
690684

691685
/******************************************************************************
692686
*
693687
* Name : tsk_sleep
694688
*
695689
* Description : delay indefinitely execution of current task
690+
* execution of the task can be resumed
696691
*
697692
* Parameters : none
698693
*
699-
* Return
700-
* E_FAILURE : task was resumed
694+
* Return : none
701695
*
702696
******************************************************************************/
703697

704698
__STATIC_INLINE
705-
unsigned tsk_sleep( void ) { return tsk_sleepFor(INFINITE); }
699+
void tsk_sleep( void ) { tsk_sleepFor(INFINITE); }
706700

707701
/******************************************************************************
708702
*
709703
* Name : tsk_suspend
710704
*
711705
* Description : delay indefinitely execution of given task
706+
* execution of the task can be resumed
712707
*
713708
* Parameters
714709
* tsk : pointer to task object
@@ -725,11 +720,11 @@ unsigned tsk_suspend( tsk_t *tsk );
725720
*
726721
* Name : tsk_resume
727722
*
728-
* Description : resume execution of given delayed task
723+
* Description : resume execution of given suspended task
724+
* only suspended or indefinitely delayed tasks can be resumed
729725
*
730726
* Parameters
731727
* tsk : pointer to delayed task object
732-
* event : the value at which the given task is woken up
733728
*
734729
* Return
735730
* E_SUCCESS : task was successfully resumed
@@ -766,14 +761,15 @@ struct staticTaskT : public __tsk
766761
staticTaskT( fun_t *_state ): __tsk _TSK_INIT(_state, stack_, size_) {}
767762
~staticTaskT( void ) { assert(__tsk::hdr.id == ID_STOPPED); }
768763

769-
void kill ( void ) { tsk_kill (this); }
770-
void join ( void ) { tsk_join (this); }
771-
void start ( void ) { tsk_start (this); }
772-
void startFrom( fun_t *_state ) { tsk_startFrom(this, _state); }
773-
unsigned suspend ( void ) { return tsk_resume (this); }
774-
unsigned resume ( void ) { return tsk_resume (this); }
764+
void kill ( void ) { tsk_kill (this); }
765+
void join ( void ) { tsk_join (this); }
766+
void start ( void ) { tsk_start (this); }
767+
void startFrom( fun_t * _state ) { tsk_startFrom(this, _state); }
768+
void give ( unsigned _flags ) { tsk_give (this, _flags); }
769+
unsigned suspend ( void ) { return tsk_suspend (this); }
770+
unsigned resume ( void ) { return tsk_resume (this); }
775771

776-
bool operator!( void ) { return __tsk::hdr.id == ID_STOPPED; }
772+
bool operator!( void ) { return __tsk::hdr.id == ID_STOPPED; }
777773

778774
private:
779775
stk_t stack_[SSIZE(size_)];
@@ -849,21 +845,22 @@ typedef startTaskT<OS_STACK_SIZE> startTask;
849845

850846
namespace ThisTask
851847
{
852-
static inline void pass ( void ) { tsk_pass (); }
853-
static inline void yield ( void ) { tsk_yield (); }
848+
static inline void pass ( void ) { tsk_pass (); }
849+
static inline void yield ( void ) { tsk_yield (); }
854850
#if OS_FUNCTIONAL
855-
static inline void flip ( FUN_t _state ) { ((TaskT<>*)System.cur)->fun_ = _state;
856-
tsk_flip (TaskT<>::run_); }
851+
static inline void flip ( FUN_t _state ) { ((TaskT<>*)System.cur)->fun_ = _state;
852+
tsk_flip (TaskT<>::run_); }
857853
#else
858-
static inline void flip ( FUN_t _state ) { tsk_flip (_state); }
854+
static inline void flip ( FUN_t _state ) { tsk_flip (_state); }
859855
#endif
860-
static inline void stop ( void ) { tsk_stop (); }
861-
static inline unsigned sleepFor ( cnt_t _delay ) { return tsk_sleepFor (_delay); }
862-
static inline unsigned sleepNext ( cnt_t _delay ) { return tsk_sleepNext (_delay); }
863-
static inline unsigned sleepUntil( cnt_t _time ) { return tsk_sleepUntil(_time); }
864-
static inline unsigned sleep ( void ) { return tsk_sleep (); }
865-
static inline unsigned delay ( cnt_t _delay ) { return tsk_delay (_delay); }
866-
static inline void suspend ( void ) { tsk_suspend (System.cur); }
856+
static inline void stop ( void ) { tsk_stop (); }
857+
static inline void suspend ( void ) { tsk_suspend (System.cur); }
858+
static inline void wait ( unsigned _flags ) { tsk_wait (_flags); }
859+
static inline void sleepFor ( cnt_t _delay ) { tsk_sleepFor (_delay); }
860+
static inline void sleepNext ( cnt_t _delay ) { tsk_sleepNext (_delay); }
861+
static inline void sleepUntil( cnt_t _time ) { tsk_sleepUntil(_time); }
862+
static inline void sleep ( void ) { tsk_sleep (); }
863+
static inline void delay ( cnt_t _delay ) { tsk_delay (_delay); }
867864
}
868865

869866
#endif//__cplusplus

IntrOS/kernel/src/ostask.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,15 @@ void tsk_flip( fun_t *state )
144144

145145
/* -------------------------------------------------------------------------- */
146146
static
147-
unsigned priv_tsk_sleep( tsk_t *cur )
147+
void priv_tsk_sleep( tsk_t *cur )
148148
/* -------------------------------------------------------------------------- */
149149
{
150150
cur->hdr.id = ID_DELAYED;
151151
core_ctx_switch();
152-
153-
return cur->event;
154152
}
155153

156154
/* -------------------------------------------------------------------------- */
157-
unsigned tsk_sleepFor( cnt_t delay )
155+
void tsk_sleepFor( cnt_t delay )
158156
/* -------------------------------------------------------------------------- */
159157
{
160158
tsk_t *cur = System.cur;
@@ -163,25 +161,29 @@ unsigned tsk_sleepFor( cnt_t delay )
163161
{
164162
cur->start = core_sys_time();
165163
cur->delay = delay;
164+
165+
priv_tsk_sleep(cur);
166166
}
167167
sys_unlock();
168-
169-
return priv_tsk_sleep(cur);
170168
}
171169

172170
/* -------------------------------------------------------------------------- */
173-
unsigned tsk_sleepNext( cnt_t delay )
171+
void tsk_sleepNext( cnt_t delay )
174172
/* -------------------------------------------------------------------------- */
175173
{
176174
tsk_t *cur = System.cur;
177175

178-
cur->delay = delay;
176+
sys_lock();
177+
{
178+
cur->delay = delay;
179179

180-
return priv_tsk_sleep(cur);
180+
priv_tsk_sleep(cur);
181+
}
182+
sys_unlock();
181183
}
182184

183185
/* -------------------------------------------------------------------------- */
184-
unsigned tsk_sleepUntil( cnt_t time )
186+
void tsk_sleepUntil( cnt_t time )
185187
/* -------------------------------------------------------------------------- */
186188
{
187189
tsk_t *cur = System.cur;
@@ -192,10 +194,10 @@ unsigned tsk_sleepUntil( cnt_t time )
192194
cur->delay = time - cur->start;
193195
if (cur->delay > ((CNT_MAX)>>1))
194196
cur->delay = 0;
197+
198+
priv_tsk_sleep(cur);
195199
}
196200
sys_unlock();
197-
198-
return priv_tsk_sleep(cur);
199201
}
200202

201203
/* -------------------------------------------------------------------------- */
@@ -242,11 +244,10 @@ unsigned tsk_resume( tsk_t *tsk )
242244
{
243245
assert(tsk);
244246

245-
if (tsk->hdr.id != ID_DELAYED)
247+
if (tsk->hdr.id != ID_DELAYED || tsk->delay != INFINITE)
246248
return E_FAILURE;
247249

248250
tsk->hdr.id = ID_READY;
249-
tsk->event = E_FAILURE;
250251
return E_SUCCESS;
251252
}
252253

0 commit comments

Comments
 (0)