1/* 2 * Copyright 2016, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(D61_BSD) 11 */ 12 13#ifndef _REFOS_SYNC_H_ 14#define _REFOS_SYNC_H_ 15 16/*! @file 17 @brief Basic kernel synchronisation library. 18 19 Basic mutex functionality using a kernel lock. Based on Anna Lyons' sync library. Implemented 20 using a kernel async endpoint. Slow! 21*/ 22 23typedef struct sync_mutex_* sync_mutex_t; 24 25/*! @brief Create a mutex object. 26 @return The created mutex object. (Gives ownership. Must call sync_destroy_mutex on given obj) 27*/ 28sync_mutex_t sync_create_mutex(); 29 30/*! @brief Destroy a mutex object. 31 @param mutex The mutex object to destroy. (Takes ownership) 32*/ 33void sync_destroy_mutex(sync_mutex_t mutex); 34 35/*! @brief Lock a mutex. May block current program. 36 @param mutex The mutex to lock. (No ownership) 37*/ 38void sync_acquire(sync_mutex_t mutex); 39 40/*! @brief Release lock on a mutex. 41 @param mutex The mutex to release. (No ownership) 42*/ 43void sync_release(sync_mutex_t mutex); 44 45/*! @brief Poll on a mutex. 46 @param mutex The mutex to poll. (No ownership) 47 @return True if mutex was acquired, false otherwise. 48*/ 49int sync_try_acquire(sync_mutex_t mutex); 50 51#endif /* _REFOS_SYNC_H_ */ 52