version 1.43, 2011/09/14 14:34:28
|
version 1.52, 2011/12/16 13:46:56
|
Line 1
|
Line 1
|
/* |
/* |
================================================================================ |
================================================================================ |
RPL/2 (R) version 4.1.3 |
RPL/2 (R) version 4.1.5 |
Copyright (C) 1989-2011 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 45 instruction_spawn(struct_processus *s_et
|
Line 45 instruction_spawn(struct_processus *s_et
|
|
|
pthread_mutexattr_t attributs_mutex; |
pthread_mutexattr_t attributs_mutex; |
|
|
pthread_t thread_id; |
|
pthread_t thread_surveillance; |
pthread_t thread_surveillance; |
|
|
struct_descripteur_thread *s_argument_thread; |
struct_descripteur_thread *s_argument_thread; |
Line 353 instruction_spawn(struct_processus *s_et
|
Line 352 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
# ifndef OS2 |
# ifdef SCHED_OTHER |
# ifndef Cygwin |
|
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_EXPLICIT_SCHED |
if (pthread_attr_setinheritsched(&attributs, PTHREAD_EXPLICIT_SCHED) != 0) |
if (pthread_attr_setinheritsched(&attributs, PTHREAD_EXPLICIT_SCHED) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_SCOPE_SYSTEM |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
# endif |
# endif |
# endif |
|
|
|
/* |
/* |
* Création de l'objet à retourner |
* Création de l'objet à retourner |
Line 397 instruction_spawn(struct_processus *s_et
|
Line 398 instruction_spawn(struct_processus *s_et
|
|
|
// Lancement du thread fils |
// Lancement du thread fils |
|
|
if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
(*s_argument_thread).s_nouvel_etat_processus = s_nouvel_etat_processus; |
(*s_argument_thread).s_nouvel_etat_processus = s_nouvel_etat_processus; |
(*s_argument_thread).s_etat_processus = s_etat_processus; |
(*s_argument_thread).s_etat_processus = s_etat_processus; |
|
|
Line 419 instruction_spawn(struct_processus *s_et
|
Line 414 instruction_spawn(struct_processus *s_et
|
|
|
(*s_argument_thread).thread_actif = d_faux; |
(*s_argument_thread).thread_actif = d_faux; |
|
|
if (pthread_create(&thread_id, &attributs, lancement_thread, |
if (pthread_create(&(*s_nouvel_etat_processus).tid, |
s_argument_thread) != 0) |
&attributs, lancement_thread, s_argument_thread) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
Line 431 instruction_spawn(struct_processus *s_et
|
Line 426 instruction_spawn(struct_processus *s_et
|
|
|
while((*s_argument_thread).thread_actif == d_faux) |
while((*s_argument_thread).thread_actif == d_faux) |
{ |
{ |
|
scrutation_interruptions(s_etat_processus); |
nanosleep(&attente, NULL); |
nanosleep(&attente, NULL); |
INCR_GRANULARITE(attente.tv_nsec); |
INCR_GRANULARITE(attente.tv_nsec); |
} |
} |
Line 454 instruction_spawn(struct_processus *s_et
|
Line 450 instruction_spawn(struct_processus *s_et
|
return; |
return; |
} |
} |
|
|
# ifndef OS2 |
# ifdef SCHED_OTHER |
# ifndef Cygwin |
|
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
if (pthread_attr_setschedpolicy(&attributs, SCHED_OTHER) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_EXPLICIT_SCHED |
if (pthread_attr_setinheritsched(&attributs, |
if (pthread_attr_setinheritsched(&attributs, |
PTHREAD_EXPLICIT_SCHED) != 0) |
PTHREAD_EXPLICIT_SCHED) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
|
# endif |
|
|
|
# ifdef PTHREAD_SCOPE_SYSTEM |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
if (pthread_attr_setscope(&attributs, PTHREAD_SCOPE_SYSTEM) != 0) |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
# endif |
# endif |
# endif |
|
|
|
// Attente de l'affectation de la grandeur processus.tid par le thread fils. |
|
|
|
if (pthread_mutex_lock(&((*s_nouvel_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
/* |
/* |
* On copie l'objet plutôt que le pointeur car cet objet peut être |
* On copie l'objet plutôt que le pointeur car cet objet peut être |
Line 500 instruction_spawn(struct_processus *s_et
|
Line 490 instruction_spawn(struct_processus *s_et
|
|
|
if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) |
if (pthread_mutex_lock(&((*s_etat_processus).mutex)) != 0) |
{ |
{ |
|
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 561 instruction_spawn(struct_processus *s_et
|
Line 552 instruction_spawn(struct_processus *s_et
|
} |
} |
} |
} |
|
|
|
scrutation_interruptions(s_etat_processus); |
l_element_courant = (*l_element_courant).suivant; |
l_element_courant = (*l_element_courant).suivant; |
} |
} |
} while(drapeau == d_vrai); |
} while(drapeau == d_vrai); |
Line 570 instruction_spawn(struct_processus *s_et
|
Line 562 instruction_spawn(struct_processus *s_et
|
.l_base_pile_processus), s_objet_systeme) == d_erreur) |
.l_base_pile_processus), s_objet_systeme) == d_erreur) |
{ |
{ |
pthread_mutex_unlock(&((*s_etat_processus).mutex)); |
pthread_mutex_unlock(&((*s_etat_processus).mutex)); |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
return; |
return; |
} |
} |
|
|
Line 583 instruction_spawn(struct_processus *s_et
|
Line 574 instruction_spawn(struct_processus *s_et
|
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
if (empilement(s_etat_processus, &((*s_etat_processus).l_base_pile), |
s_objet_resultat) == d_erreur) |
s_objet_resultat) == d_erreur) |
{ |
{ |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
return; |
return; |
} |
} |
|
|
if (pthread_mutex_lock(&(*s_argument_thread).mutex) != 0) |
if (pthread_mutex_lock(&(*s_argument_thread).mutex) != 0) |
{ |
{ |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 599 instruction_spawn(struct_processus *s_et
|
Line 588 instruction_spawn(struct_processus *s_et
|
// Le thread n'existe plus. |
// Le thread n'existe plus. |
|
|
pthread_join((*s_argument_thread).tid, NULL); |
pthread_join((*s_argument_thread).tid, NULL); |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
pthread_mutex_unlock(&(*s_argument_thread).mutex); |
pthread_mutex_unlock(&(*s_argument_thread).mutex); |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
Line 607 instruction_spawn(struct_processus *s_et
|
Line 595 instruction_spawn(struct_processus *s_et
|
|
|
if (pthread_mutex_unlock(&(*s_argument_thread).mutex) != 0) |
if (pthread_mutex_unlock(&(*s_argument_thread).mutex) != 0) |
{ |
{ |
pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)); |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
|
|
if (pthread_mutex_unlock(&((*s_nouvel_etat_processus).mutex)) != 0) |
|
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
Line 1128 instruction_smphrdecr(struct_processus *
|
Line 1109 instruction_smphrdecr(struct_processus *
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
# else |
# else |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
|
# endif |
{ |
{ |
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
# endif |
|
|
|
while(sem_wait((*((struct_semaphore *) (*s_objet_argument).objet)) |
while(sem_wait((*((struct_semaphore *) (*s_objet_argument).objet)) |
.semaphore) == -1) |
.semaphore) == -1) |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
{ |
{ |
|
# ifndef SEMAPHORES_NOMMES |
|
sem_post(&((*s_etat_processus).semaphore_fork)); |
|
# else |
|
sem_post((*s_etat_processus).semaphore_fork); |
|
# endif |
|
|
(*s_etat_processus).erreur_execution = d_ex_semaphore; |
(*s_etat_processus).erreur_execution = d_ex_semaphore; |
|
|
if ((*s_etat_processus).profilage == d_vrai) |
if ((*s_etat_processus).profilage == d_vrai) |
Line 1159 instruction_smphrdecr(struct_processus *
|
Line 1142 instruction_smphrdecr(struct_processus *
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
# else |
# else |
while(sem_wait((*s_etat_processus).semaphore_fork) == -1) |
while(sem_wait((*s_etat_processus).semaphore_fork) != 0) |
# endif |
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |
Line 1282 instruction_smphrtrydecr(struct_processu
|
Line 1265 instruction_smphrtrydecr(struct_processu
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
if (sem_post(&((*s_etat_processus).semaphore_fork)) != 0) |
{ |
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
|
return; |
|
} |
|
# else |
# else |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
if (sem_post((*s_etat_processus).semaphore_fork) != 0) |
|
# endif |
{ |
{ |
|
if ((*s_etat_processus).profilage == d_vrai) |
|
{ |
|
profilage(s_etat_processus, NULL); |
|
} |
|
|
(*s_etat_processus).erreur_systeme = d_es_processus; |
(*s_etat_processus).erreur_systeme = d_es_processus; |
return; |
return; |
} |
} |
# endif |
|
|
|
(*((integer8 *) (*s_objet_resultat).objet)) = 0; |
(*((integer8 *) (*s_objet_resultat).objet)) = 0; |
|
|
Line 1334 instruction_smphrtrydecr(struct_processu
|
Line 1318 instruction_smphrtrydecr(struct_processu
|
} |
} |
|
|
# ifndef SEMAPHORES_NOMMES |
# ifndef SEMAPHORES_NOMMES |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) == -1) |
while(sem_wait(&((*s_etat_processus).semaphore_fork)) != 0) |
# else |
# else |
while(sem_wait((*s_etat_processus).semaphore_fork) == -1) |
while(sem_wait((*s_etat_processus).semaphore_fork) != 0) |
# endif |
# endif |
{ |
{ |
if (errno != EINTR) |
if (errno != EINTR) |