version 1.1, 2010/08/25 16:40:57
|
version 1.13, 2011/06/21 15:26:35
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.0.18 |
RPL/2 (R) version 4.1.0.prerelease.2 |
Copyright (C) 1989-2010 Dr. BERTRAND Joël |
Copyright (C) 1989-2011 Dr. BERTRAND Joël |
|
|
This file is part of RPL/2. |
This file is part of RPL/2. |
|
|
Line 30
|
Line 30
|
|
|
static int *fifos; |
static int *fifos; |
static int markov; |
static int markov; |
static int segment; |
|
static sem_t *semaphores[nombre_queues]; |
static sem_t *semaphores[nombre_queues]; |
static sem_t *semaphore_global; |
static sem_t *semaphore_global; |
|
|
#ifdef IPCS_SYSV |
#ifdef IPCS_SYSV |
|
#ifndef OS2 |
static unsigned char *chemin = NULL; |
static unsigned char *chemin = NULL; |
#endif |
#endif |
|
#endif |
|
|
|
#ifdef OS2 |
|
PVOID ptr_os2; |
|
#else |
|
static int segment; |
|
#endif |
|
|
static unsigned char * |
static unsigned char * |
nom_segment(unsigned char *chemin, pid_t pid) |
nom_segment(unsigned char *chemin, pid_t pid) |
Line 44 nom_segment(unsigned char *chemin, pid_t
|
Line 51 nom_segment(unsigned char *chemin, pid_t
|
unsigned char *fichier; |
unsigned char *fichier; |
|
|
# ifdef IPCS_SYSV |
# ifdef IPCS_SYSV |
|
|
|
# ifndef OS2 |
|
|
if ((fichier = malloc((strlen(chemin) + 1 + 256 + 1) * |
if ((fichier = malloc((strlen(chemin) + 1 + 256 + 1) * |
sizeof(unsigned char))) == NULL) |
sizeof(unsigned char))) == NULL) |
{ |
{ |
Line 51 nom_segment(unsigned char *chemin, pid_t
|
Line 61 nom_segment(unsigned char *chemin, pid_t
|
} |
} |
|
|
sprintf(fichier, "%s/RPL-SIGQUEUES-%d", chemin, (int) pid); |
sprintf(fichier, "%s/RPL-SIGQUEUES-%d", chemin, (int) pid); |
|
|
# else |
# else |
|
|
|
if ((fichier = malloc((10 + 256 + 1) * sizeof(unsigned char))) == NULL) |
|
{ |
|
return(NULL); |
|
} |
|
|
|
sprintf(fichier, "\\SHAREMEM\\RPL-SIGQUEUES-%d", (int) pid); |
|
|
|
# endif |
|
# else |
|
|
if ((fichier = malloc((1 + 256 + 1) * |
if ((fichier = malloc((1 + 256 + 1) * |
sizeof(unsigned char))) == NULL) |
sizeof(unsigned char))) == NULL) |
{ |
{ |
Line 59 nom_segment(unsigned char *chemin, pid_t
|
Line 81 nom_segment(unsigned char *chemin, pid_t
|
} |
} |
|
|
sprintf(fichier, "/RPL-SIGQUEUES-%d", (int) pid); |
sprintf(fichier, "/RPL-SIGQUEUES-%d", (int) pid); |
|
|
# endif |
# endif |
|
|
return(fichier); |
return(fichier); |
Line 74 nom_semaphore(pid_t pid, int queue)
|
Line 97 nom_semaphore(pid_t pid, int queue)
|
return(NULL); |
return(NULL); |
} |
} |
|
|
sprintf(fichier, "/RPL-SIGESMAPHORES-%d-%d", (int) pid, queue); |
sprintf(fichier, "/RPL-SIGSEMAPHORES-%d-%d", (int) pid, queue); |
|
|
return(fichier); |
return(fichier); |
} |
} |
Line 174 creation_fifos_signaux(struct_processus
|
Line 197 creation_fifos_signaux(struct_processus
|
free(nom); |
free(nom); |
|
|
# else // SystemV |
# else // SystemV |
|
# ifndef OS2 |
|
|
file *desc; |
file *desc; |
|
|
Line 228 creation_fifos_signaux(struct_processus
|
Line 252 creation_fifos_signaux(struct_processus
|
return; |
return; |
} |
} |
|
|
|
# else |
|
|
|
if ((nom = nom_segment(NULL, getpid())) == NULL) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
if (DosAllocSharedMem(&ptr_os2, nom, nombre_queues * |
|
((2 * longueur_queue) + 4) * sizeof(int), |
|
PAG_WRITE | PAG_READ | PAG_COMMIT) != 0) |
|
{ |
|
free(nom); |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
free(nom); |
|
fifos = ptr_os2; |
|
|
|
# endif |
# endif |
# endif |
|
|
/* |
/* |
Line 301 liberation_fifos_signaux(struct_processu
|
Line 346 liberation_fifos_signaux(struct_processu
|
int i; |
int i; |
|
|
# ifdef IPCS_SYSV // SystemV |
# ifdef IPCS_SYSV // SystemV |
|
# ifndef OS2 |
|
|
if (shmdt(fifos) == -1) |
if (shmdt(fifos) == -1) |
{ |
{ |
Line 308 liberation_fifos_signaux(struct_processu
|
Line 354 liberation_fifos_signaux(struct_processu
|
return; |
return; |
} |
} |
|
|
|
# else |
|
|
|
if (DosFreeMem(fifos) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
# endif |
# else // POSIX |
# else // POSIX |
|
|
if (munmap(fifos, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int)) |
if (munmap(fifos, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int)) |
Line 345 destruction_fifos_signaux(struct_process
|
Line 400 destruction_fifos_signaux(struct_process
|
unsigned char *nom; |
unsigned char *nom; |
|
|
# ifdef IPCS_SYSV // SystemV |
# ifdef IPCS_SYSV // SystemV |
|
# ifndef OS2 |
|
|
if (shmdt(fifos) == -1) |
if (shmdt(fifos) == -1) |
{ |
{ |
Line 368 destruction_fifos_signaux(struct_process
|
Line 424 destruction_fifos_signaux(struct_process
|
unlink(nom); |
unlink(nom); |
free(nom); |
free(nom); |
|
|
|
# else |
|
|
|
if (DosFreeMem(fifos) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_allocation_memoire; |
|
return; |
|
} |
|
|
|
# endif |
# else // POSIX |
# else // POSIX |
|
|
if (munmap(fifos, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int)) |
if (munmap(fifos, nombre_queues * ((2 * longueur_queue) + 4) * sizeof(int)) |
Line 441 horodatage()
|
Line 506 horodatage()
|
return(ts); |
return(ts); |
} |
} |
|
|
static int |
int |
queue_in(pid_t pid, int signal) |
queue_in(pid_t pid, int signal) |
{ |
{ |
int queue; |
int queue; |
int *base; |
int *base; |
int *buffer; |
int *buffer; |
int horodatage_initial; |
int horodatage_initial; |
|
# ifndef OS2 |
int identifiant; |
int identifiant; |
|
# endif |
int *projection_fifos; |
int *projection_fifos; |
|
|
sem_t *semaphore; |
sem_t *semaphore; |
Line 502 queue_in(pid_t pid, int signal)
|
Line 569 queue_in(pid_t pid, int signal)
|
|
|
# else // Traitement à l'aide d'IPCS SystemV |
# else // Traitement à l'aide d'IPCS SystemV |
|
|
|
# ifndef OS2 |
key_t clef; |
key_t clef; |
|
|
struct stat s_stat; |
struct stat s_stat; |
|
# endif |
|
|
|
// Dans le cas de SIGSTART, premier signal envoyé à un processus fils, |
|
// il convient d'attendre que le fichier support soit effectivement |
|
// accessible. Dans tous les autres cas, ce fichier doit exister. S'il |
|
// n'existe plus, le processus associé n'existe plus. |
|
|
|
# ifndef OS2 |
|
|
// Ouverture des projections |
// Ouverture des projections |
|
|
Line 513 queue_in(pid_t pid, int signal)
|
Line 589 queue_in(pid_t pid, int signal)
|
return(-1); |
return(-1); |
} |
} |
|
|
// Dans le cas de SIGSTART, premier signal envoyé à un processus fils, |
|
// il convient d'attendre que le fichier support soit effectivement |
|
// accessible. Dans tous les autres cas, ce fichier doit exister. S'il |
|
// n'existe plus, le processus associé n'existe plus. |
|
|
|
if (signal == SIGSTART) |
if (signal == SIGSTART) |
{ |
{ |
// On attend que le fichier sois présent |
// On attend que le fichier sois présent |
Line 563 queue_in(pid_t pid, int signal)
|
Line 634 queue_in(pid_t pid, int signal)
|
return(-1); |
return(-1); |
} |
} |
|
|
|
# else |
|
|
|
// Ouverture des projections |
|
|
|
if ((nom = nom_segment(NULL, pid)) == NULL) |
|
{ |
|
return(-1); |
|
} |
|
|
|
if (signal == SIGSTART) |
|
{ |
|
horodatage_initial = horodatage(); |
|
|
|
while(DosGetNamedSharedMem(&ptr_os2, nom, |
|
PAG_READ | PAG_WRITE | PAG_COMMIT) != 0) |
|
{ |
|
if (abs(horodatage_initial - horodatage()) > 500) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
} |
|
else |
|
{ |
|
if (DosGetNamedSharedMem(&ptr_os2, nom, |
|
PAG_READ | PAG_WRITE) != 0) |
|
{ |
|
return(-1); |
|
} |
|
} |
|
|
|
projection_fifos = ptr_os2; |
|
|
|
# endif |
# endif |
# endif |
|
|
if ((nom = nom_semaphore(pid, queue)) == NULL) |
if ((nom = nom_semaphore(pid, queue)) == NULL) |
{ |
{ |
# ifdef IPCS_SYSV |
# ifdef IPCS_SYSV |
|
# ifndef OS2 |
shmdt(projection_fifos); |
shmdt(projection_fifos); |
# else |
# else |
|
DosFreeMem(projection_fifos); |
|
# endif |
|
# else |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
* sizeof(int)); |
* sizeof(int)); |
# endif |
# endif |
Line 584 queue_in(pid_t pid, int signal)
|
Line 693 queue_in(pid_t pid, int signal)
|
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
# ifdef IPCS_SYSV |
# ifdef IPCS_SYSV |
|
# ifndef OS2 |
shmdt(projection_fifos); |
shmdt(projection_fifos); |
# else |
# else |
|
DosFreeMem(projection_fifos); |
|
# endif |
|
# else |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
* sizeof(int)); |
* sizeof(int)); |
# endif |
# endif |
Line 603 queue_in(pid_t pid, int signal)
|
Line 716 queue_in(pid_t pid, int signal)
|
sem_post(semaphore); |
sem_post(semaphore); |
sem_close(semaphore); |
sem_close(semaphore); |
# ifdef IPCS_SYSV |
# ifdef IPCS_SYSV |
|
# ifndef OS2 |
shmdt(projection_fifos); |
shmdt(projection_fifos); |
# else |
# else |
|
DosFreeMem(projection_fifos); |
|
# endif |
|
# else |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
* sizeof(int)); |
* sizeof(int)); |
# endif |
# endif |
Line 622 queue_in(pid_t pid, int signal)
|
Line 739 queue_in(pid_t pid, int signal)
|
if (sem_post(semaphore) != 0) |
if (sem_post(semaphore) != 0) |
{ |
{ |
# ifdef IPCS_SYSV |
# ifdef IPCS_SYSV |
|
# ifndef OS2 |
shmdt(projection_fifos); |
shmdt(projection_fifos); |
# else |
# else |
|
DosFreeMem(projection_fifos); |
|
# endif |
|
# else |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
* sizeof(int)); |
* sizeof(int)); |
# endif |
# endif |
Line 635 queue_in(pid_t pid, int signal)
|
Line 756 queue_in(pid_t pid, int signal)
|
|
|
// Fermeture des projections |
// Fermeture des projections |
# ifdef IPCS_SYSV |
# ifdef IPCS_SYSV |
|
# ifndef OS2 |
shmdt(projection_fifos); |
shmdt(projection_fifos); |
# else |
# else |
|
DosFreeMem(projection_fifos); |
|
# endif |
|
# else |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
munmap(projection_fifos, nombre_queues * ((2 * longueur_queue) + 4) |
* sizeof(int)); |
* sizeof(int)); |
# endif |
# endif |
Line 706 origine_signal(int signal)
|
Line 831 origine_signal(int signal)
|
// base[0] - 1 : dernière interruption lue |
// base[0] - 1 : dernière interruption lue |
pid = buffer[((((base[0] + base[2] - 1) % base[2]) |
pid = buffer[((((base[0] + base[2] - 1) % base[2]) |
- ((base[3] - base[2]) + 1)) + base[2]) % base[2]]; |
- ((base[3] - base[2]) + 1)) + base[2]) % base[2]]; |
|
|
|
if (kill(pid, 0) != 0) |
|
{ |
|
pid = getpid(); |
|
} |
} |
} |
else |
else |
{ |
{ |