1 /* 2 * Copyright (C) 2016 YunOS Project. All rights reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MBOX_H 18 #define MBOX_H 19 20 #if defined(__cplusplus) 21 extern "C" 22 { 23 #endif 24 25 #define K_MBOX_SIZE 128 26 27 #define SYS_ARCH_TIMEOUT 0xffffffffUL 28 #define SYS_MBOX_EMPTY SYS_ARCH_TIMEOUT 29 30 typedef struct k_mbox { 31 int first, last; 32 void *msgs[K_MBOX_SIZE]; 33 struct k_sem not_empty; 34 struct k_sem not_full; 35 struct k_sem mutex; 36 int wait_send; 37 } k_mbox_t; 38 39 int k_mbox_new(k_mbox_t **mb, int size); 40 void k_mbox_free(k_mbox_t *mb); 41 void k_mbox_post(k_mbox_t *mb, void *msg); 42 int k_mbox_trypost(k_mbox_t *mb, void *msg); 43 int k_mbox_fetch(k_mbox_t *mb, void **msg, uint32_t timeout); 44 int k_mbox_tryfetch(k_mbox_t *mb, void **msg); 45 46 #ifdef __cplusplus 47 } 48 #endif 49 50 #endif /* MBOX_H */ 51 52