Share Memory

概述

share memory 模块, 即一段内存,可供多核共享访问、申请和使用,当前采用 master/slave 方式共享内存,申请统一由master核申请,slave 核通过IPC交互使用。

功能特性

  • 支持默认共享master核内存作为共享使用。

  • 支持指定段作为共享内存段使用, 通过预定义宏 SHARE_MEMORY_START 和 SHARE_MEMORY_LENGTH。

  • 不支持在中断中申请内存,支持在中断中释放内存。

  • 支持统一管理,每块内存都用标签标记,存在在链表 m_sm_tag_list 中,可供增删改查。

  • 支持特定内存对齐的申请。

资源依赖

  • 依赖IPC 提供核间通信

  • 依赖heap 管理共享的堆内存

  • 依赖share task 处理中断下半部工作

  • 依赖semaphore 提供同步

用法流程

内存申请交互流程

../../_images/Share_Memory_Process.png

API 介绍

Functions

void wq_share_memory_init(void)

register port to malloc/free cross cores for share memory

void *wq_share_memory_malloc(size_t size)

Malloc memory from shere memory pool.

参数:

size -- [in] Size to malloc.

返回:

void* malloced pointer.

void wq_share_memory_free(void *ptr)

Free a malloced share memory pointer.

参数:

ptr -- [in] Share memory pointer returned by::wq_share_memory_malloc

void *wq_share_memory_aligned_malloc(size_t size, size_t alignment)

Aligned Malloc memory from shere memory pool.

参数:
  • size -- is number of bytes of memory to be allocated.

  • alignment -- is alignment number.

返回:

void* null(failure), otherwise(pointer of allocated memory).

void wq_share_memory_aligned_free(void *ptr)

This function is used to free memory.

参见

wq_share_memory_aligned_malloc.

备注

the ptr must be malloc from

参数:

ptr -- is alignement pointer to the memory to be free'd.

void *wq_share_memory_malloc_with_tag(const char *tag_name, size_t size)

Malloc memory from shere memory pool by tag.

参数:
  • tag_name -- is tag name of memory sign

  • size -- [in] Size to malloc.

返回:

void* malloced pointer.

void *wq_share_memory_aligned_malloc_with_tag(const char *tag_name, size_t size, size_t alignment)

Aligned Malloc memory from shere memory pool.

参数:
  • tag_name -- is tag name of memory sign

  • size -- is number of bytes of memory to be allocated.

  • alignment -- is alignment number.

返回:

void* null(failure), otherwise(pointer of allocated memory).

void wq_share_memory_free_with_tag(const char *tag_name)

Free a malloced share memory pointer by tag.

参数:

tag_name -- [in] is tag name of memory sign

void *wq_share_memory_get_by_tag(const char *tag_name)

Get a malloced share memory by tag.

参数:

tag_name -- [in] is tag name of memory sign