修改多线程重复映射同一块共享内存,可能导致进程的线性地址耗尽问题。
一个线程映射共享内存后,将地址存储,其它线程可直接使用,不用重复映射
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
#define MESA_SHM_RING_QUEUE_HALF_IDLE 2
|
||||
#define MESA_SHM_RING_QUEUE_USED 3
|
||||
|
||||
#define MESA_SEM_KEY 35719
|
||||
|
||||
#define MESA_CONSUMER_RUNNING 1
|
||||
#define MESA_CONSUMER_NOT_RUNNING 0
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
struct MESA_shm_overview *MESA_shm_ovw = NULL;
|
||||
int *MESA_consumer_status = NULL;
|
||||
struct MESA_shm_queue_head *MESA_ring_queue_head[MESA_SHM_RING_QUEUE_NUM] = {NULL};
|
||||
|
||||
|
||||
void MESA_shm_init_ring_queue_mutex(struct MESA_shm_overview *ovw)
|
||||
{
|
||||
@@ -131,15 +133,21 @@ struct MESA_shm_queue_head *MESA_shm_alloc_new_ring_queue(struct MESA_shm_overvi
|
||||
}
|
||||
MESA_shm_init_new_ring_queue(head, ovw);
|
||||
ovw->shmid = shmid;
|
||||
MESA_ring_queue_head[ovw->idx] = head;
|
||||
return head;
|
||||
}
|
||||
|
||||
struct MESA_shm_queue_head *MESA_shm_try_reuse_ring_queue(struct MESA_shm_overview *ovw)
|
||||
{
|
||||
struct MESA_shm_queue_head *head = NULL;
|
||||
head = (struct MESA_shm_queue_head *)shmat(ovw->shmid, NULL, 0);
|
||||
if(head == (struct MESA_shm_queue_head *)-1){
|
||||
return NULL;
|
||||
if(MESA_ring_queue_head[ovw->idx] != NULL){
|
||||
head = MESA_ring_queue_head[ovw->idx];
|
||||
}else{
|
||||
head = (struct MESA_shm_queue_head *)shmat(ovw->shmid, NULL, 0);
|
||||
if(head == (struct MESA_shm_queue_head *)-1){
|
||||
return NULL;
|
||||
}
|
||||
MESA_ring_queue_head[ovw->idx] = head;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user