mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
shmem: add top-level function for allocating samples
This commit is contained in:
parent
67d835b520
commit
faa0763d64
2 changed files with 14 additions and 2 deletions
|
@ -108,13 +108,25 @@ int shmem_int_read(struct shmem_int *shm, struct sample *smps[], unsigned cnt);
|
|||
|
||||
/** Write samples to the interface.
|
||||
* @param shm The shared memory interface.
|
||||
* @param smps The samples to be written. Must be allocated from shm->pool.
|
||||
* @param smps The samples to be written. Must be allocated from shm_int_alloc.
|
||||
* @param cnt Number of samples to write.
|
||||
* @retval >=0 Number of samples that were successfully written. Can be less than cnt (including 0) in case of a full queue.
|
||||
* @retval -1 The write failed for some reason; no more samples can be written.
|
||||
*/
|
||||
int shmem_int_write(struct shmem_int *shm, struct sample *smps[], unsigned cnt);
|
||||
|
||||
/** Allocate samples to be written to the interface. The writing process must
|
||||
* not free the samples; only the receiving process should free them using
|
||||
* sample_put after use.
|
||||
* @param shm The shared memory interface.
|
||||
* @param smps Array where pointers to newly allocated samples will be returned.
|
||||
* @param cnt Number of samples to allocate.
|
||||
* @returns Number of samples that were successfully allocated (may be less then cnt).
|
||||
*/
|
||||
inline int shmem_int_alloc(struct shmem_int *shm, struct sample *smps[], unsigned cnt) {
|
||||
return sample_alloc(&shm->write.shared->pool, smps, cnt);
|
||||
}
|
||||
|
||||
/** Returns the total size of the shared memory region with the given size of
|
||||
* the input/output queues (in elements) and the given number of data elements
|
||||
* per struct sample. */
|
||||
|
|
|
@ -86,7 +86,7 @@ int main(int argc, char* argv[])
|
|||
break;
|
||||
}
|
||||
|
||||
avail = sample_alloc(&shm.write.shared->pool, outsmps, readcnt);
|
||||
avail = shmem_int_alloc(&shm, outsmps, readcnt);
|
||||
if (avail < readcnt)
|
||||
warn("Pool underrun: %d / %d\n", avail, readcnt);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue