Lines Matching +full:data +full:- +full:timeout
4 * SPDX-License-Identifier: Apache-2.0
35 z_handle_obj_poll_events(&msgq->poll_events, state); in handle_poll_events()
42 msgq->msg_size = msg_size; in k_msgq_init()
43 msgq->max_msgs = max_msgs; in k_msgq_init()
44 msgq->buffer_start = buffer; in k_msgq_init()
45 msgq->buffer_end = buffer + (max_msgs * msg_size); in k_msgq_init()
46 msgq->read_ptr = buffer; in k_msgq_init()
47 msgq->write_ptr = buffer; in k_msgq_init()
48 msgq->used_msgs = 0; in k_msgq_init()
49 msgq->flags = 0; in k_msgq_init()
50 z_waitq_init(&msgq->wait_q); in k_msgq_init()
51 msgq->lock = (struct k_spinlock) {}; in k_msgq_init()
53 sys_dlist_init(&msgq->poll_events); in k_msgq_init()
75 ret = -EINVAL; in z_impl_k_msgq_alloc_init()
80 msgq->flags = K_MSGQ_FLAG_ALLOC; in z_impl_k_msgq_alloc_init()
83 ret = -ENOMEM; in z_impl_k_msgq_alloc_init()
107 CHECKIF(z_waitq_head(&msgq->wait_q) != NULL) { in k_msgq_cleanup()
108 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, cleanup, msgq, -EBUSY); in k_msgq_cleanup()
110 return -EBUSY; in k_msgq_cleanup()
113 if ((msgq->flags & K_MSGQ_FLAG_ALLOC) != 0U) { in k_msgq_cleanup()
114 k_free(msgq->buffer_start); in k_msgq_cleanup()
115 msgq->flags &= ~K_MSGQ_FLAG_ALLOC; in k_msgq_cleanup()
124 int z_impl_k_msgq_put(struct k_msgq *msgq, const void *data, k_timeout_t timeout) in z_impl_k_msgq_put() argument
126 __ASSERT(!arch_is_in_isr() || K_TIMEOUT_EQ(timeout, K_NO_WAIT), ""); in z_impl_k_msgq_put()
132 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_put()
134 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, put, msgq, timeout); in z_impl_k_msgq_put()
136 if (msgq->used_msgs < msgq->max_msgs) { in z_impl_k_msgq_put()
138 pending_thread = z_unpend_first_thread(&msgq->wait_q); in z_impl_k_msgq_put()
140 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, 0); in z_impl_k_msgq_put()
143 (void)memcpy(pending_thread->base.swap_data, data, in z_impl_k_msgq_put()
144 msgq->msg_size); in z_impl_k_msgq_put()
148 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_put()
152 __ASSERT_NO_MSG(msgq->write_ptr >= msgq->buffer_start && in z_impl_k_msgq_put()
153 msgq->write_ptr < msgq->buffer_end); in z_impl_k_msgq_put()
154 (void)memcpy(msgq->write_ptr, (char *)data, msgq->msg_size); in z_impl_k_msgq_put()
155 msgq->write_ptr += msgq->msg_size; in z_impl_k_msgq_put()
156 if (msgq->write_ptr == msgq->buffer_end) { in z_impl_k_msgq_put()
157 msgq->write_ptr = msgq->buffer_start; in z_impl_k_msgq_put()
159 msgq->used_msgs++; in z_impl_k_msgq_put()
165 } else if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { in z_impl_k_msgq_put()
167 result = -ENOMSG; in z_impl_k_msgq_put()
169 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, put, msgq, timeout); in z_impl_k_msgq_put()
171 /* wait for put message success, failure, or timeout */ in z_impl_k_msgq_put()
172 arch_current_thread()->base.swap_data = (void *) data; in z_impl_k_msgq_put()
174 result = z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); in z_impl_k_msgq_put()
175 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, result); in z_impl_k_msgq_put()
179 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, put, msgq, timeout, result); in z_impl_k_msgq_put()
181 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_put()
187 static inline int z_vrfy_k_msgq_put(struct k_msgq *msgq, const void *data, in z_vrfy_k_msgq_put() argument
188 k_timeout_t timeout) in z_vrfy_k_msgq_put() argument
191 K_OOPS(K_SYSCALL_MEMORY_READ(data, msgq->msg_size)); in z_vrfy_k_msgq_put()
193 return z_impl_k_msgq_put(msgq, data, timeout); in z_vrfy_k_msgq_put()
200 attrs->msg_size = msgq->msg_size; in z_impl_k_msgq_get_attrs()
201 attrs->max_msgs = msgq->max_msgs; in z_impl_k_msgq_get_attrs()
202 attrs->used_msgs = msgq->used_msgs; in z_impl_k_msgq_get_attrs()
216 int z_impl_k_msgq_get(struct k_msgq *msgq, void *data, k_timeout_t timeout) in z_impl_k_msgq_get() argument
218 __ASSERT(!arch_is_in_isr() || K_TIMEOUT_EQ(timeout, K_NO_WAIT), ""); in z_impl_k_msgq_get()
224 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_get()
226 SYS_PORT_TRACING_OBJ_FUNC_ENTER(k_msgq, get, msgq, timeout); in z_impl_k_msgq_get()
228 if (msgq->used_msgs > 0U) { in z_impl_k_msgq_get()
230 (void)memcpy((char *)data, msgq->read_ptr, msgq->msg_size); in z_impl_k_msgq_get()
231 msgq->read_ptr += msgq->msg_size; in z_impl_k_msgq_get()
232 if (msgq->read_ptr == msgq->buffer_end) { in z_impl_k_msgq_get()
233 msgq->read_ptr = msgq->buffer_start; in z_impl_k_msgq_get()
235 msgq->used_msgs--; in z_impl_k_msgq_get()
238 pending_thread = z_unpend_first_thread(&msgq->wait_q); in z_impl_k_msgq_get()
240 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, get, msgq, timeout); in z_impl_k_msgq_get()
243 __ASSERT_NO_MSG(msgq->write_ptr >= msgq->buffer_start && in z_impl_k_msgq_get()
244 msgq->write_ptr < msgq->buffer_end); in z_impl_k_msgq_get()
245 (void)memcpy(msgq->write_ptr, (char *)pending_thread->base.swap_data, in z_impl_k_msgq_get()
246 msgq->msg_size); in z_impl_k_msgq_get()
247 msgq->write_ptr += msgq->msg_size; in z_impl_k_msgq_get()
248 if (msgq->write_ptr == msgq->buffer_end) { in z_impl_k_msgq_get()
249 msgq->write_ptr = msgq->buffer_start; in z_impl_k_msgq_get()
251 msgq->used_msgs++; in z_impl_k_msgq_get()
256 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_get()
258 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, 0); in z_impl_k_msgq_get()
263 } else if (K_TIMEOUT_EQ(timeout, K_NO_WAIT)) { in z_impl_k_msgq_get()
265 result = -ENOMSG; in z_impl_k_msgq_get()
267 SYS_PORT_TRACING_OBJ_FUNC_BLOCKING(k_msgq, get, msgq, timeout); in z_impl_k_msgq_get()
269 /* wait for get message success or timeout */ in z_impl_k_msgq_get()
270 arch_current_thread()->base.swap_data = data; in z_impl_k_msgq_get()
272 result = z_pend_curr(&msgq->lock, key, &msgq->wait_q, timeout); in z_impl_k_msgq_get()
273 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, result); in z_impl_k_msgq_get()
277 SYS_PORT_TRACING_OBJ_FUNC_EXIT(k_msgq, get, msgq, timeout, result); in z_impl_k_msgq_get()
279 k_spin_unlock(&msgq->lock, key); in z_impl_k_msgq_get()
285 static inline int z_vrfy_k_msgq_get(struct k_msgq *msgq, void *data, in z_vrfy_k_msgq_get() argument
286 k_timeout_t timeout) in z_vrfy_k_msgq_get() argument
289 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, msgq->msg_size)); in z_vrfy_k_msgq_get()
291 return z_impl_k_msgq_get(msgq, data, timeout); in z_vrfy_k_msgq_get()
296 int z_impl_k_msgq_peek(struct k_msgq *msgq, void *data) in z_impl_k_msgq_peek() argument
301 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_peek()
303 if (msgq->used_msgs > 0U) { in z_impl_k_msgq_peek()
305 (void)memcpy((char *)data, msgq->read_ptr, msgq->msg_size); in z_impl_k_msgq_peek()
309 result = -ENOMSG; in z_impl_k_msgq_peek()
314 k_spin_unlock(&msgq->lock, key); in z_impl_k_msgq_peek()
320 static inline int z_vrfy_k_msgq_peek(struct k_msgq *msgq, void *data) in z_vrfy_k_msgq_peek() argument
323 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, msgq->msg_size)); in z_vrfy_k_msgq_peek()
325 return z_impl_k_msgq_peek(msgq, data); in z_vrfy_k_msgq_peek()
330 int z_impl_k_msgq_peek_at(struct k_msgq *msgq, void *data, uint32_t idx) in z_impl_k_msgq_peek_at() argument
338 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_peek_at()
340 if (msgq->used_msgs > idx) { in z_impl_k_msgq_peek_at()
341 bytes_to_end = (msgq->buffer_end - msgq->read_ptr); in z_impl_k_msgq_peek_at()
342 byte_offset = idx * msgq->msg_size; in z_impl_k_msgq_peek_at()
343 start_addr = msgq->read_ptr; in z_impl_k_msgq_peek_at()
347 byte_offset -= bytes_to_end; in z_impl_k_msgq_peek_at()
348 /* wrap-around is required */ in z_impl_k_msgq_peek_at()
349 start_addr = msgq->buffer_start; in z_impl_k_msgq_peek_at()
351 (void)memcpy(data, start_addr + byte_offset, msgq->msg_size); in z_impl_k_msgq_peek_at()
355 result = -ENOMSG; in z_impl_k_msgq_peek_at()
360 k_spin_unlock(&msgq->lock, key); in z_impl_k_msgq_peek_at()
366 static inline int z_vrfy_k_msgq_peek_at(struct k_msgq *msgq, void *data, uint32_t idx) in z_vrfy_k_msgq_peek_at() argument
369 K_OOPS(K_SYSCALL_MEMORY_WRITE(data, msgq->msg_size)); in z_vrfy_k_msgq_peek_at()
371 return z_impl_k_msgq_peek_at(msgq, data, idx); in z_vrfy_k_msgq_peek_at()
381 key = k_spin_lock(&msgq->lock); in z_impl_k_msgq_purge()
386 for (pending_thread = z_unpend_first_thread(&msgq->wait_q); pending_thread != NULL; in z_impl_k_msgq_purge()
387 pending_thread = z_unpend_first_thread(&msgq->wait_q)) { in z_impl_k_msgq_purge()
388 arch_thread_return_value_set(pending_thread, -ENOMSG); in z_impl_k_msgq_purge()
392 msgq->used_msgs = 0; in z_impl_k_msgq_purge()
393 msgq->read_ptr = msgq->write_ptr; in z_impl_k_msgq_purge()
395 z_reschedule(&msgq->lock, key); in z_impl_k_msgq_purge()