![]() |
librnr
1.14.5
RoadNarrows Robotics Common Library 1
|
Shared memory interface. More...
Go to the source code of this file.
Classes | |
| struct | shm_t |
| Shared memory structure type. More... | |
Macros | |
| #define | SHM_MUTEX_N_TRIES 3 |
| maximum number of tries to acquire lock | |
| #define | SHM_MUTEX_T_TRIES 50000 |
| usec time between tries to acquire lock | |
Typedefs | |
| typedef shm_t | shm_mutex_t |
| Shared memory pthread mutex structure type. | |
| typedef void(* | shm_mem_init_func_t) (key_t key, void *add, size_t size) |
| User-supplied shared memory initialization function. More... | |
Functions | |
| int | shm_open (key_t key, size_t size, shm_mem_init_func_t mem_init, shm_t *pshm) |
| Open shared memory segement. More... | |
| int | shm_close (shm_t *pshm) |
| Close shared memory segement. More... | |
| int | shm_mutex_init (key_t key, shm_mutex_t *pshmmutex) |
| Create and initialize a shared memory mutex. More... | |
| int | shm_mutex_destroy (shm_mutex_t *pshmmutex) |
| Destroy a shared memory mutex. More... | |
| int | shm_mutex_lock (shm_mutex_t *pshmmutex) |
| Lock the mutex. More... | |
| int | shm_mutex_trylock (shm_mutex_t *pshmmutex) |
| Try to lock the mutex. More... | |
| int | shm_mutex_unlock (shm_mutex_t *pshmmutex) |
| Unlock a lock the mutex. More... | |
Shared memory interface.
—
Definition in file shm.h.
| typedef void(* shm_mem_init_func_t) (key_t key, void *add, size_t size) |
| int shm_close | ( | shm_t * | pshm | ) |
Close shared memory segement.
The segment is marked for deletion, and is actually destroy after the last process detaches.
| [in,out] | pshm | Pointer to shared memory structure defined in caller's space. |
Definition at line 178 of file shm.c.
References LOGDIAG3, LOGERROR, LOGSYSERROR, shm_t::m_shmAddr, shm_t::m_shmId, shm_t::m_shmKey, shm_t::m_shmSize, NULL, OK, and RC_ERROR.
Referenced by shm_mutex_destroy().
| int shm_mutex_destroy | ( | shm_mutex_t * | pshmmutex | ) |
Destroy a shared memory mutex.
The mutex is actually only destroyed when the last process attached to this mutex calls destroy.
| [in,out] | pshmmutex | Pointer to shared memory mutext structure defined in caller's space. |
Definition at line 300 of file shm.c.
References shm_close().
Referenced by runExample().
| int shm_mutex_init | ( | key_t | key, |
| shm_mutex_t * | pshmmutex | ||
| ) |
Create and initialize a shared memory mutex.
| key | Shared memory key. | |
| [in,out] | pshmmutex | Pointer to shared memory mutext structure defined in caller's space. |
Definition at line 277 of file shm.c.
References LOGDIAG3, LOGERROR, LOGSYSERROR, NULL, OK, RC_ERROR, shm_mutex_create(), and shm_open().
Referenced by runExample().
| int shm_mutex_lock | ( | shm_mutex_t * | pshmmutex | ) |
Lock the mutex.
| [in] | pshmmutex | Pointer to shared memory mutext structure defined in caller's space. |
Definition at line 305 of file shm.c.
References LOGERROR, shm_t::m_shmAddr, NULL, OK, SHM_MUTEX_N_TRIES, and SHM_MUTEX_T_TRIES.
Referenced by lock().
| int shm_mutex_trylock | ( | shm_mutex_t * | pshmmutex | ) |
Try to lock the mutex.
| [in] | pshmmutex | Pointer to shared memory mutext structure defined in caller's space. |
Definition at line 350 of file shm.c.
References LOGERROR, shm_t::m_shmAddr, NULL, OK, SHM_MUTEX_N_TRIES, and SHM_MUTEX_T_TRIES.
| int shm_mutex_unlock | ( | shm_mutex_t * | pshmmutex | ) |
Unlock a lock the mutex.
| [in] | pshmmutex | Pointer to shared memory mutext structure defined in caller's space. |
Definition at line 396 of file shm.c.
References LOGERROR, shm_t::m_shmAddr, main(), and NULL.
Referenced by unlock().
| int shm_open | ( | key_t | key, |
| size_t | size, | ||
| shm_mem_init_func_t | mem_init, | ||
| shm_t * | pshm | ||
| ) |
Open shared memory segement.
If the segment, associated by key, does not exist, then the shared memory is created and, optionally, initialized.
The shared memory segment is attached to the application address space.
| key | Shared memory key. | |
| size | Shared memory size. | |
| mem_init | Optional memory initializer function. Set to NULL for no initialization. | |
| [in,out] | pshm | Pointer to shared memory structure defined in caller's space. |
Definition at line 74 of file shm.c.
References LOGDIAG3, LOGERROR, LOGSYSERROR, shm_t::m_shmAddr, shm_t::m_shmId, shm_t::m_shmKey, shm_t::m_shmSize, NULL, OK, and RC_ERROR.
Referenced by shm_mutex_init().