brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 1 | #ifndef _SHARED_MEM_H_ |
| 2 | #define _SHARED_MEM_H_ |
| 3 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 4 | #include <stddef.h> |
| 5 | #include <unistd.h> |
Brian Silverman | 08661c7 | 2013-09-01 17:24:38 -0700 | [diff] [blame] | 6 | #include <time.h> |
| 7 | |
John Park | 398c74a | 2018-10-20 21:17:39 -0700 | [diff] [blame] | 8 | #include "aos/ipc_lib/shared_mem_types.h" |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 9 | |
Brian Silverman | a6d1b56 | 2013-09-01 14:39:39 -0700 | [diff] [blame] | 10 | #ifdef __cplusplus |
| 11 | extern "C" { |
| 12 | #endif |
| 13 | |
Brian Silverman | 08661c7 | 2013-09-01 17:24:38 -0700 | [diff] [blame] | 14 | void init_shared_mem_core(aos_shm_core *shm_core); |
| 15 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 16 | ptrdiff_t aos_core_get_mem_usage(void); |
| 17 | |
| 18 | // Takes the specified memory address and uses it as the shared memory. |
| 19 | // address is the memory address, and size is the size of the memory. |
| 20 | // global_core needs to point to an instance of struct aos_core, and owner |
| 21 | // should be set correctly there. |
| 22 | // The owner should verify that the first sizeof(mutex) of data is set to 0 |
| 23 | // before passing the memory to this function. |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 24 | void aos_core_use_address_as_shared_mem(void *address, size_t size); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 25 | |
Brian Silverman | 8a6dac9 | 2015-02-21 20:08:24 -0500 | [diff] [blame] | 26 | // create is true to remove any existing shm to create a fresh one or false to |
| 27 | // fail if it does not already exist. |
| 28 | // lock is true to lock shared memory into RAM or false to not. |
| 29 | void aos_core_create_shared_mem(int create, int lock); |
Brian Silverman | 01be000 | 2014-05-10 15:44:38 -0700 | [diff] [blame] | 30 | void aos_core_free_shared_mem(void); |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 31 | |
Brian Silverman | b263d30 | 2014-02-16 00:01:43 -0800 | [diff] [blame] | 32 | // Returns whether or not the shared memory system is active. |
| 33 | int aos_core_is_init(void); |
| 34 | |
brians | 343bc11 | 2013-02-10 01:53:46 +0000 | [diff] [blame] | 35 | #ifdef __cplusplus |
| 36 | } |
| 37 | #endif |
| 38 | |
| 39 | #endif |