Skip to content

Commit

Permalink
Small setitimer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
afxgroup committed Oct 2, 2023
1 parent d6e5c7c commit 6bcd209
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
1 change: 0 additions & 1 deletion library/math/init_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ MATH_CONSTRUCTOR(math_init) {
single_x = (union ieee_single *) &__clib4->__nan;
single_x->raw[0] = 0x7fc00001;

SHOWVALUE(success);
LEAVE();

CONSTRUCTOR_SUCCEED();
Expand Down
22 changes: 18 additions & 4 deletions library/time/itimer_tasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ int itimer_real_task() {
struct Process *thisTask = (struct Process *) FindTask(NULL);
struct itimer *_itimer = (struct itimer *) thisTask->pr_Task.tc_UserData;

struct _clib4 *__clib4 = _itimer->__clib4;
struct _clib4 *__clib4 = __CLIB4;

SHOWPOINTER(__clib4);
SHOWVALUE(_itimer->which);

SHOWMSG("AllocSysObjectTags ASOT_PORT");
/* Create itimer timers and message ports */
tmr_real_mp = AllocSysObjectTags(ASOT_PORT,
ASOPORT_Action, PA_SIGNAL,
Expand All @@ -46,17 +46,21 @@ int itimer_real_task() {
if (!tmr_real_mp) {
goto out;
}
SHOWMSG("AllocSysObjectTags ASOT_IOREQUEST");
tmr_real_tr = AllocSysObjectTags(ASOT_IOREQUEST,
ASOIOR_ReplyPort, tmr_real_mp,
ASOIOR_Size, sizeof(struct TimeRequest),
TAG_END);
if (!tmr_real_tr) {
goto out;
}

SHOWMSG("OpenDevice");
if (OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *) tmr_real_tr, 0) != OK) {
goto out;
}

SHOWMSG("Setting Request");
tmr_real_tr->Request.io_Command = TR_ADDREQUEST;
tmr_real_tr->Time.Seconds = __clib4->tmr_time.it_value.tv_sec;
tmr_real_tr->Time.Microseconds = __clib4->tmr_time.it_value.tv_usec;
Expand Down Expand Up @@ -91,19 +95,25 @@ int itimer_real_task() {
tmr_real_tr->Time.Seconds = __clib4->tmr_time.it_value.tv_sec;
tmr_real_tr->Time.Microseconds = __clib4->tmr_time.it_value.tv_usec;
} else {
if (CheckIO((struct IORequest *) tmr_real_tr))
SHOWMSG("CheckIO");
if (CheckIO((struct IORequest *) tmr_real_tr)) {
SHOWMSG("WaitIO");
WaitIO((struct IORequest *) tmr_real_tr);
}

tmr_real_tr->Time.Seconds += __clib4->tmr_time.it_interval.tv_sec;
tmr_real_tr->Time.Microseconds += __clib4->tmr_time.it_interval.tv_usec;

/* If SIGALRM is blocked kill the timer */
SHOWMSG("CHECK SIGALRM");
if (FLAG_IS_SET(__clib4->__signals_blocked, (1 << SIGALRM))) {
break;
}

SHOWMSG("Raise SIGALRM");
raise(SIGALRM);

SHOWMSG("CHECK SIGALRM AGAIN");
/* Check again if SIGALRM is blocked and then kill the timer */
if (FLAG_IS_SET(__clib4->__signals_blocked, (1 << SIGALRM))) {
break;
Expand All @@ -115,11 +125,15 @@ int itimer_real_task() {

out:
/* Free itimer objects */
SHOWMSG("FreeSysObject ASOT_PORT");
FreeSysObject(ASOT_PORT, tmr_real_mp);

if (tmr_real_tr) {
if (tmr_real_tr->Request.io_Device != NULL)
if (tmr_real_tr->Request.io_Device != NULL) {
SHOWMSG("CloseDevice");
CloseDevice((struct IORequest *) tmr_real_tr);
}
SHOWMSG("FreeSysObject ASOT_IOREQUEST");
FreeSysObject(ASOT_IOREQUEST, tmr_real_tr);
}

Expand Down
6 changes: 2 additions & 4 deletions library/time/setitimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ setitimer(int which, const struct itimerval *new_value, struct itimerval *old_va
}

_itimer.which = which;
_itimer.__clib4 = __clib4;

switch (which) {
case ITIMER_REAL:
Expand All @@ -53,11 +52,10 @@ setitimer(int which, const struct itimerval *new_value, struct itimerval *old_va
/* Create timer tasks */
if ((new_value->it_value.tv_sec != 0 || new_value->it_value.tv_usec != 0)) {
__clib4->tmr_real_task = CreateNewProcTags(
NP_Name, "CLIB4_ITIMER_REAL_TASK",
NP_Name, "ITIMER_TASK",
NP_Entry, itimer_real_task,
NP_EntryData, GetEntryData(),
NP_Child, TRUE,
NP_UserData, (struct _clib4 *) &_itimer,
NP_UserData, (struct _itimer *) &_itimer,
NP_Output, DupFileHandle(Output()),
NP_CloseOutput, TRUE,
TAG_END);
Expand Down
1 change: 0 additions & 1 deletion library/time/time_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@
#endif /* _DEBUG_H */

struct itimer {
struct _clib4 *__clib4;
int which;
};

Expand Down

0 comments on commit 6bcd209

Please sign in to comment.