| 117 | static ssize_t timerfd_read(struct dfs_file *file, void *buf, size_t count) |
| 118 | #else |
| 119 | static ssize_t timerfd_read(struct dfs_file *file, void *buf, size_t count, off_t *pos) |
| 120 | #endif |
| 121 | { |
| 122 | struct rt_timerfd *tfd; |
| 123 | rt_uint64_t *buffer; |
| 124 | int ret = 0; |
| 125 | |
| 126 | buffer = (rt_uint64_t *)buf; |
| 127 | |
| 128 | if (sizeof(buffer) > count) |
| 129 | { |
| 130 | rt_set_errno(EINVAL); |
| 131 | return -1; |
| 132 | } |
| 133 | |
| 134 | tfd = file->vnode->data; |
| 135 | |
| 136 | if (!tfd) |
| 137 | { |
| 138 | rt_set_errno(EINVAL); |
| 139 | return -1; |
| 140 | } |
| 141 | |
| 142 | if ((rt_atomic_load(&(tfd->ticks)) == 0) && (file->flags & O_NONBLOCK)) |
| 143 | { |
| 144 | rt_set_errno(EAGAIN); |
| 145 | return -EAGAIN; |
| 146 | } |
| 147 | else |
| 148 | { |
| 149 | if (rt_atomic_load(&(tfd->ticks)) == 0) |
| 150 | { |
| 151 | tfd->wqn.polling_thread = rt_thread_self(); |
| 152 | |
| 153 | if (tfd->wqn.wqueue) |
| 154 | { |
| 155 | rt_wqueue_remove(&tfd->wqn); |
| 156 | } |
| 157 | rt_wqueue_add(&tfd->timerfd_queue, &tfd->wqn); |
| 158 | |
| 159 | ret = rt_thread_suspend_with_flag(tfd->wqn.polling_thread, RT_INTERRUPTIBLE); |
| 160 | if (ret == RT_EOK) |
| 161 | { |
| 162 | rt_schedule(); |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | return ret; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | (*buffer) = rt_atomic_load(&(tfd->timeout_num)); |
| 171 | rt_atomic_store(&(tfd->timeout_num), 0); |
| 172 | rt_atomic_store(&(tfd->ticks), 0); |
| 173 | } |
| 174 | |
| 175 | return sizeof(buffer); |
| 176 | } |
nothing calls this directly
no test coverage detected