mirror of
https://github.com/rkd77/elinks.git
synced 2025-01-03 14:57:44 -05:00
IPC: simplification. Only one semaphore is required.
This commit is contained in:
parent
ab4e622452
commit
4cf3130b53
@ -64,7 +64,6 @@
|
||||
struct program program;
|
||||
int epoll_fd;
|
||||
int master_sem = -1;
|
||||
int slave_sem = -1;
|
||||
int shared_mem_ipc = -1;
|
||||
unsigned char *shared_mem = NULL;
|
||||
|
||||
@ -119,18 +118,16 @@ init_master_ipc(void)
|
||||
{
|
||||
#if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SEM_H) && defined(HAVE_SYS_SHM_H)
|
||||
struct string filename;
|
||||
key_t k1, k2, k3;
|
||||
key_t k1, k2;
|
||||
|
||||
if (!get_sun_path(&filename))
|
||||
return;
|
||||
k1 = ftok(filename.source, 1);
|
||||
k2 = ftok(filename.source, 2);
|
||||
k3 = ftok(filename.source, 3);
|
||||
master_sem = sem_create(k1, 0);
|
||||
slave_sem = sem_create(k2, 0);
|
||||
shared_mem_ipc = shmget(k3, 4096, 0600 | IPC_CREAT | IPC_EXCL);
|
||||
shared_mem_ipc = shmget(k2, 4096, 0600 | IPC_CREAT | IPC_EXCL);
|
||||
if (shared_mem_ipc == -1 && errno == EEXIST)
|
||||
shared_mem_ipc = shmget(k3, 4096, 0600);
|
||||
shared_mem_ipc = shmget(k2, 4096, 0600);
|
||||
if (shared_mem_ipc >= 0) {
|
||||
shared_mem = shmat(shared_mem_ipc, NULL, 0);
|
||||
}
|
||||
@ -143,16 +140,14 @@ init_slave_ipc(void)
|
||||
{
|
||||
#if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SEM_H) && defined(HAVE_SYS_SHM_H)
|
||||
struct string filename;
|
||||
key_t k1, k2, k3;
|
||||
key_t k1, k2;
|
||||
|
||||
if (!get_sun_path(&filename))
|
||||
return;
|
||||
k1 = ftok(filename.source, 1);
|
||||
k2 = ftok(filename.source, 2);
|
||||
k3 = ftok(filename.source, 3);
|
||||
master_sem = sem_open(k1);
|
||||
slave_sem = sem_open(k2);
|
||||
shared_mem_ipc = shmget(k3, 4096, 0600);
|
||||
shared_mem_ipc = shmget(k2, 4096, 0600);
|
||||
if (shared_mem_ipc >= 0) {
|
||||
shared_mem = shmat(shared_mem_ipc, NULL, 0);
|
||||
}
|
||||
@ -168,8 +163,6 @@ done_ipc(void)
|
||||
shmdt(shared_mem);
|
||||
if (master_sem >= 0)
|
||||
sem_close(master_sem);
|
||||
if (slave_sem >= 0)
|
||||
sem_close(slave_sem);
|
||||
/* shared_mem_ipc will be automatically done by sem_close() */
|
||||
#endif
|
||||
}
|
||||
|
@ -47,7 +47,6 @@
|
||||
#include "util/string.h"
|
||||
|
||||
extern int master_sem;
|
||||
extern int slave_sem;
|
||||
extern unsigned char *shared_mem;
|
||||
|
||||
struct mailcap_hash_item {
|
||||
@ -678,10 +677,12 @@ get_mime_handler_mailcap(unsigned char *type, struct terminal *term)
|
||||
unsigned char *desc, *data;
|
||||
int block, len;
|
||||
#endif
|
||||
if (!term || term->master || slave_sem == -1)
|
||||
if (!term || term->master || master_sem == -1)
|
||||
return get_mime_handler_mailcap_common(type);
|
||||
|
||||
#if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SEM_H) && defined(HAVE_SYS_SHM_H)
|
||||
if (!shared_mem)
|
||||
return NULL;
|
||||
len = strlen(type) + 1;
|
||||
data = fmem_alloc(2 + len);
|
||||
if (!data)
|
||||
@ -692,10 +693,7 @@ get_mime_handler_mailcap(unsigned char *type, struct terminal *term)
|
||||
hard_write(term->fdout, data, len + 2);
|
||||
fmem_free(data);
|
||||
|
||||
if (!shared_mem)
|
||||
return NULL;
|
||||
shared_mem[0] = '\0'; /* For unexpected death of slave. */
|
||||
sem_signal(slave_sem);
|
||||
sem_wait(master_sem);
|
||||
if (!*shared_mem)
|
||||
return NULL;
|
||||
@ -713,7 +711,6 @@ void
|
||||
get_slave_mailcap(unsigned char *type)
|
||||
{
|
||||
#if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SEM_H) && defined(HAVE_SYS_SHM_H)
|
||||
sem_wait(slave_sem);
|
||||
if (shared_mem) {
|
||||
struct mailcap_entry *entry;
|
||||
unsigned char *program;
|
||||
|
Loading…
Reference in New Issue
Block a user