MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / timer_create

Function timer_create

components/libc/compilers/common/ctime.c:946–1044  ·  view source on GitHub ↗

* @brief Create a per-process timer. * * This API does not accept SIGEV_THREAD as valid signal event notification * type. * * See IEEE 1003.1 */

Source from the content-addressed store, hash-verified

944 * See IEEE 1003.1
945 */
946int timer_create(clockid_t clockid, struct sigevent *evp, timer_t *timerid)
947{
948 static int num = 0;
949 int _timerid = 0;
950 struct timer_obj *timer;
951 char timername[RT_NAME_MAX] = {0};
952
953 if (evp == RT_NULL || timerid == RT_NULL)
954 {
955 rt_set_errno(EINVAL);
956 return -1;
957 }
958
959 if (evp->sigev_notify == SIGEV_THREAD) // TODO need to implement
960 {
961 rt_set_errno(EINVAL);
962 return -1;
963 }
964
965 switch (clockid)
966 {
967 case CLOCK_REALTIME:
968 case CLOCK_REALTIME_ALARM:
969 case CLOCK_MONOTONIC:
970 case CLOCK_BOOTTIME:
971 case CLOCK_BOOTTIME_ALARM:
972 case CLOCK_PROCESS_CPUTIME_ID:
973 case CLOCK_THREAD_CPUTIME_ID:
974 break; // Only these ids are supported
975 default:
976 rt_set_errno(EINVAL);
977 return -1;
978 }
979
980 timer = rt_malloc(sizeof(struct timer_obj));
981 if(timer == RT_NULL)
982 {
983 rt_set_errno(ENOMEM);
984 return -1;
985 }
986
987 rt_snprintf(timername, RT_NAME_MAX, "psx_tm%02d", num++);
988 num %= 100;
989 timer->sigev_signo = evp->sigev_signo;
990#ifdef RT_USING_SMART
991 struct rt_work *work;
992 struct rt_lwp *lwp = lwp_self();
993 struct lwp_timer_event_param *param;
994 param = rt_malloc(sizeof(struct lwp_timer_event_param));
995 work = &param->work;
996
997 if (!work)
998 {
999 rt_set_errno(ENOMEM);
1000 return -1;
1001 }
1002
1003 if (lwp)

Callers 2

lwp_signal_setitimerFunction · 0.85
sys_timer_createFunction · 0.85

Calls 9

rt_set_errnoFunction · 0.85
rt_mallocFunction · 0.85
rt_snprintfFunction · 0.85
lwp_selfFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_ktime_hrtimer_initFunction · 0.85
resource_id_getFunction · 0.85
rt_freeFunction · 0.85
rt_ktime_hrtimer_detachFunction · 0.85

Tested by

no test coverage detected