修改线程获取缓冲区失败问题。
修改共享内存地址映射失败时的判错条件,shmat失败会返回(void *)-1而不是NULL
This commit is contained in:
@@ -529,7 +529,8 @@ int main(int argc, char **argv)
|
||||
}
|
||||
if(ring_queue_head[i] == NULL){
|
||||
ring_queue_head[i] = shmat(tmp_ovw->shmid, NULL, 0);
|
||||
if(ring_queue_head[i] == NULL){
|
||||
if(ring_queue_head[i] == (struct MESA_shm_queue_head *)-1){
|
||||
ring_queue_head[i] = NULL;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ struct MESA_shm_overview *MESA_shm_alloc_overview()
|
||||
return NULL;
|
||||
}else{
|
||||
shm_overview = (struct MESA_shm_overview *)shmat(shmid, NULL, 0);
|
||||
if(shm_overview == NULL){
|
||||
if(shm_overview == (struct MESA_shm_overview *)-1){
|
||||
return NULL;
|
||||
}
|
||||
memset((void *)shm_overview, 0, shmsize);
|
||||
@@ -51,6 +51,9 @@ struct MESA_shm_overview *MESA_shm_alloc_overview()
|
||||
}
|
||||
}else{
|
||||
shm_overview = (struct MESA_shm_overview *)shmat(shmid, NULL, 0);
|
||||
if(shm_overview == (struct MESA_shm_overview *)-1){
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
return shm_overview;
|
||||
}
|
||||
@@ -100,9 +103,6 @@ struct MESA_shm_queue_head *MESA_shm_alloc_new_ring_queue(struct MESA_shm_overvi
|
||||
struct MESA_shm_queue_head *head = NULL;
|
||||
int shmid = -1;
|
||||
int shmsize = sizeof(struct MESA_shm_queue_head) + (MESA_SHM_RING_QUEUE_BLOCK_NUM * MESA_SHM_RING_QUEUE_BLOCK_SIZE);
|
||||
if(!MESA_shm_mutex_trylock_success(ovw)){
|
||||
return NULL;
|
||||
}
|
||||
shmid = shmget(ovw->shmkey, 0, 0);
|
||||
if(shmid == -1){
|
||||
shmid = shmget(ovw->shmkey, shmsize, (SHM_R|SHM_W|IPC_CREAT));
|
||||
@@ -113,31 +113,20 @@ struct MESA_shm_queue_head *MESA_shm_alloc_new_ring_queue(struct MESA_shm_overvi
|
||||
}else{
|
||||
head = (struct MESA_shm_queue_head *)shmat(shmid, NULL, 0);
|
||||
}
|
||||
if(head != NULL){
|
||||
MESA_shm_init_new_ring_queue(head, ovw);
|
||||
ovw->shmid = shmid;
|
||||
}else{
|
||||
pthread_mutex_unlock(&ovw->mutex);
|
||||
if(head == (struct MESA_shm_queue_head *)-1){
|
||||
return NULL;
|
||||
}
|
||||
MESA_shm_init_new_ring_queue(head, ovw);
|
||||
ovw->shmid = shmid;
|
||||
return head;
|
||||
}
|
||||
|
||||
struct MESA_shm_queue_head *MESA_shm_try_ring_queue(struct MESA_shm_overview *ovw)
|
||||
struct MESA_shm_queue_head *MESA_shm_try_reuse_ring_queue(struct MESA_shm_overview *ovw)
|
||||
{
|
||||
struct MESA_shm_queue_head *head = NULL;
|
||||
if(ovw->shmid == -1){
|
||||
return NULL;
|
||||
}
|
||||
if(!MESA_shm_mutex_trylock_success(ovw)){
|
||||
return NULL;
|
||||
}
|
||||
head = (struct MESA_shm_queue_head *)shmat(ovw->shmid, NULL, 0);
|
||||
if(head == NULL){
|
||||
pthread_mutex_unlock(&ovw->mutex);
|
||||
}
|
||||
if(!MESA_shm_ring_queue_is_empty(head)){
|
||||
pthread_mutex_unlock(&ovw->mutex);
|
||||
head == NULL;
|
||||
if(head == (struct MESA_shm_queue_head *)-1){
|
||||
return NULL;
|
||||
}
|
||||
return head;
|
||||
}
|
||||
@@ -151,13 +140,22 @@ struct MESA_shm_queue_head *MESA_shm_get_ring_queue(int pid)
|
||||
}
|
||||
for(i = 0; i < MESA_SHM_RING_QUEUE_NUM; i++){
|
||||
tmp_ovw = MESA_shm_ovw + i;
|
||||
if(!MESA_shm_mutex_trylock_success(tmp_ovw)){
|
||||
continue ;
|
||||
}
|
||||
if(tmp_ovw->shmid == -1){
|
||||
head = MESA_shm_alloc_new_ring_queue(tmp_ovw);
|
||||
if(head == NULL){
|
||||
pthread_mutex_unlock(&tmp_ovw->mutex);
|
||||
}
|
||||
break;
|
||||
}
|
||||
head = MESA_shm_try_ring_queue(tmp_ovw);
|
||||
head = MESA_shm_try_reuse_ring_queue(tmp_ovw);
|
||||
if(head != NULL){
|
||||
break;
|
||||
break ;
|
||||
}else{
|
||||
pthread_mutex_unlock(&tmp_ovw->mutex);
|
||||
continue ;
|
||||
}
|
||||
}
|
||||
if(head != NULL){
|
||||
|
||||
Reference in New Issue
Block a user