diff mbox

[API-NEXT,PATCHv6,09/13] linux-gen: shm: add flag and function to share memory between ODP instances

Message ID 1477903945-39693-10-git-send-email-christophe.milard@linaro.org
State Superseded
Headers show

Commit Message

Christophe Milard Oct. 31, 2016, 8:52 a.m. UTC
Implemented by calling the related functions from _ishm.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>

---
 platform/linux-generic/odp_shared_memory.c | 31 +++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

-- 
2.7.4
diff mbox

Patch

diff --git a/platform/linux-generic/odp_shared_memory.c b/platform/linux-generic/odp_shared_memory.c
index 2377f16..c1c37ed 100644
--- a/platform/linux-generic/odp_shared_memory.c
+++ b/platform/linux-generic/odp_shared_memory.c
@@ -24,6 +24,21 @@  static inline odp_shm_t to_handle(uint32_t index)
 	return _odp_cast_scalar(odp_shm_t, index + 1);
 }
 
+static uint32_t get_ishm_flags(uint32_t flags)
+{
+	uint32_t f = 0; /* internal ishm flags */
+
+	/* set internal ishm flags according to API flags:
+	 * note that both ODP_SHM_PROC and ODP_SHM_EXPORT maps to
+	 * _ODP_ISHM_LINK as in the linux-gen implementation there is
+	 * no difference between exporting to another ODP instance or
+	 * another linux process */
+	f |= (flags & (ODP_SHM_PROC | ODP_SHM_EXPORT)) ? _ODP_ISHM_EXPORT : 0;
+	f |= (flags & ODP_SHM_SINGLE_VA) ? _ODP_ISHM_SINGLE_VA : 0;
+
+	return f;
+}
+
 int odp_shm_capability(odp_shm_capability_t *capa)
 {
 	memset(capa, 0, sizeof(odp_shm_capability_t));
@@ -41,9 +56,7 @@  odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
 	int block_index;
 	int flgs = 0; /* internal ishm flags */
 
-	/* set internal ishm flags according to API flags: */
-	flgs |= (flags & ODP_SHM_PROC) ? _ODP_ISHM_EXPORT : 0;
-	flgs |= (flags & ODP_SHM_SINGLE_VA) ? _ODP_ISHM_SINGLE_VA : 0;
+	flgs = get_ishm_flags(flags);
 
 	/* all mem reserved through this interface is requested to be locked: */
 	flgs |= (flags & _ODP_ISHM_LOCK);
@@ -55,6 +68,18 @@  odp_shm_t odp_shm_reserve(const char *name, uint64_t size, uint64_t align,
 		return ODP_SHM_INVALID;
 }
 
+odp_shm_t odp_shm_find_exported(const char *remote_name,
+				odp_instance_t odp_inst,
+				const char *local_name)
+{
+	int ret;
+
+	ret =  _odp_ishm_find_exported(remote_name, (pid_t)odp_inst,
+				       local_name);
+
+	return to_handle(ret);
+}
+
 int odp_shm_free(odp_shm_t shm)
 {
 	return _odp_ishm_free_by_index(from_handle(shm));