Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions components/libc/compilers/common/ctime.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,11 @@ struct timer_obj
rt_uint32_t status;
int sigev_signo;
clockid_t clockid;
timer_t timer_id;
#ifdef RT_USING_SMART
pid_t pid;
struct rt_work *work;
rt_list_t lwp_node;
#endif
};

Expand Down Expand Up @@ -763,6 +765,17 @@ static void _lwp_timer_event_from_pid(struct rt_work *work, void *param)

rt_free(work);
}

int timer_list_free(rt_list_t *timer_list)
{
struct timer_obj *pos, *n;
rt_list_for_each_entry_safe(pos, n, timer_list, lwp_node)
{
timer_delete(pos->timer_id);
}
return 0;
}

#endif /* RT_USING_SMART */

static void rtthread_timer_wrapper(void *timerobj)
Expand Down Expand Up @@ -881,6 +894,7 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
if (lwp)
{
timer->pid = lwp_self()->pid;
rt_list_insert_after(&lwp->timer, &timer->lwp_node);
}
else
{
Expand Down Expand Up @@ -908,6 +922,8 @@ int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
return -1; /* todo:memory leak */
}
_g_timerid[_timerid] = timer;

timer->timer_id = (timer_t)(rt_ubase_t)_timerid;
*timerid = (timer_t)(rt_ubase_t)_timerid;

return 0;
Expand Down Expand Up @@ -953,6 +969,11 @@ int timer_delete(timer_t timerid)
}
rt_ktime_hrtimer_detach(&timer->hrtimer);

#ifdef RT_USING_SMART
if (timer->pid)
rt_list_remove(&timer->lwp_node);
#endif

rt_free(timer);
return 0;
}
Expand Down
4 changes: 4 additions & 0 deletions components/lwp/lwp.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct rt_lwp
pid_t tty_old_pgrp;
pid_t session;
rt_list_t t_grp;
rt_list_t timer; /* POSIX timer object binding to a process */

int leader; /*boolean value for session group_leader*/
struct dfs_fdtable fdt;
Expand Down Expand Up @@ -165,6 +166,9 @@ void lwp_user_setting_save(rt_thread_t thread);
void lwp_user_setting_restore(rt_thread_t thread);
int lwp_setaffinity(pid_t pid, int cpu);

/* ctime lwp API */
int timer_list_free(rt_list_t *timer_list);

#ifdef ARCH_MM_MMU
struct __pthread {
/* Part 1 -- these fields may be external or
Expand Down
2 changes: 2 additions & 0 deletions components/lwp/lwp_pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ struct rt_lwp* lwp_new(void)
lwp->session = -1;
lwp->tty = RT_NULL;
rt_list_init(&lwp->t_grp);
rt_list_init(&lwp->timer);
lwp_user_object_lock_init(lwp);
lwp->address_search_head = RT_NULL;
rt_wqueue_init(&lwp->wait_queue);
Expand Down Expand Up @@ -502,6 +503,7 @@ void lwp_free(struct rt_lwp* lwp)
}
}

timer_list_free(&lwp->timer);
lwp_pid_put(lwp_to_pid(lwp));
rt_hw_interrupt_enable(level);
rt_free(lwp);
Expand Down