| 181 | } |
| 182 | |
| 183 | static int timerfd_do_create(int clockid, int flags) |
| 184 | { |
| 185 | struct rt_timerfd *tfd = RT_NULL; |
| 186 | struct dfs_file *df; |
| 187 | rt_err_t ret = -1; |
| 188 | int fd = -1; |
| 189 | |
| 190 | if ((flags & ~TFD_SHARED_FCNTL_FLAGS) || |
| 191 | (clockid != CLOCK_MONOTONIC && |
| 192 | clockid != CLOCK_REALTIME && |
| 193 | clockid != CLOCK_REALTIME_ALARM && |
| 194 | clockid != CLOCK_BOOTTIME && |
| 195 | clockid != CLOCK_BOOTTIME_ALARM)) |
| 196 | { |
| 197 | rt_set_errno(EINVAL); |
| 198 | return -1; |
| 199 | } |
| 200 | |
| 201 | if ((clockid == CLOCK_REALTIME_ALARM || |
| 202 | clockid == CLOCK_BOOTTIME_ALARM)) |
| 203 | { |
| 204 | rt_set_errno(EPERM); |
| 205 | return -1; |
| 206 | } |
| 207 | |
| 208 | fd = fd_new(); |
| 209 | if (fd < 0) |
| 210 | { |
| 211 | rt_set_errno(EINVAL); |
| 212 | return -1; |
| 213 | } |
| 214 | |
| 215 | ret = fd; |
| 216 | df = fd_get(fd); |
| 217 | |
| 218 | if (df) |
| 219 | { |
| 220 | df->flags |= flags; |
| 221 | |
| 222 | tfd = (struct rt_timerfd *)rt_calloc(1, sizeof(struct rt_timerfd)); |
| 223 | |
| 224 | if (tfd) |
| 225 | { |
| 226 | rt_mutex_init(&tfd->lock, TIMERFD_MUTEX_NAME, RT_IPC_FLAG_FIFO); |
| 227 | rt_wqueue_init(&tfd->timerfd_queue); |
| 228 | |
| 229 | tfd->isperiodic = INIT_PERIODIC; |
| 230 | tfd->ticks = 0; |
| 231 | tfd->timeout_num = 0; |
| 232 | tfd->tick_out = 0; |
| 233 | tfd->clockid = clockid; |
| 234 | tfd->timer = RT_NULL; |
| 235 | tfd->pre_time.tv_sec = 0; |
| 236 | tfd->pre_time.tv_nsec = 0; |
| 237 | tfd->wqn.polling_thread = rt_thread_self(); |
| 238 | rt_list_init(&(tfd->wqn.list)); |
| 239 | tfd->wqn.wakeup = timerfd_wqueue_callback; |
| 240 |
no test coverage detected