* @brief Create a per-process timer. * * This API does not accept SIGEV_THREAD as valid signal event notification * type. * * See IEEE 1003.1 */
| 944 | * See IEEE 1003.1 |
| 945 | */ |
| 946 | int 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 = ¶m->work; |
| 996 | |
| 997 | if (!work) |
| 998 | { |
| 999 | rt_set_errno(ENOMEM); |
| 1000 | return -1; |
| 1001 | } |
| 1002 | |
| 1003 | if (lwp) |
no test coverage detected