From 04660e460797d8f4a159fed1849c47a9fa1bbf0a Mon Sep 17 00:00:00 2001 From: "Arnaud G. GIBERT" Date: Mon, 15 Apr 2024 16:54:18 +0200 Subject: [PATCH] - Fix SM_Name_Prefix() implementation, - Minor code cleanup. --- include/shmem.h | 233 +++++++++++++++++--------- lib/libshmem.c | 430 +++++++++++++++++++++++++----------------------- lib/libshmem.h | 10 +- 3 files changed, 389 insertions(+), 284 deletions(-) diff --git a/include/shmem.h b/include/shmem.h index 2ee8534..e337556 100644 --- a/include/shmem.h +++ b/include/shmem.h @@ -33,16 +33,19 @@ #define _LIBSM #ifdef __cplusplus -extern "C" { +//extern "C" { #endif #include #include #include + + + /* Code retour des fonctions constituant l'API */ - typedef long SMT_Status; +typedef long SMT_Status; #define SMS_OK NDS_OK /* La fonction s'est correctement exécutée et a produit un résultat */ #define SMS_KO NDS_KO /* La fonction s'est correctement exécutée mais n'a pas produit de résultat */ @@ -59,7 +62,14 @@ extern "C" { #define SM_ERROR(s) ((s) < 0) /* Tous les codes retour négatifs correspondent à des erreurs */ - typedef int SMT_Flags; + + +#define SMD_NAME_LEN (short) 256 +#define SMD_NAME_SIZE (SMD_NAME_LEN + 1) + + + +typedef int SMT_Flags; #define SMD_UNDEF 0 @@ -72,6 +82,8 @@ extern "C" { /* NB : pour l'ouverture de la librairie, les valeurs SMD_OPEN et SMD_CREATE sont mutuellement exclusives */ + + /* Flags de verrouillage */ #define SMD_READ 0x04 /* verrou partagé */ @@ -80,6 +92,8 @@ extern "C" { #define SMD_LOCK_MSK(a) ((a) & (SMD_READ|SMD_WRITE)) + + /* Mode de debug sur l'ouverture de la librairie */ #define SMD_DEBUG_NONE 0x00 /* pour n'afficher aucun message généré par les diverses librairies */ @@ -88,9 +102,11 @@ extern "C" { #define SMD_DEBUG_MSK(a) ((a) & (SMD_DEBUG|SMD_DEBUG_ALL)) + + /* Différentes types de configuration d'un heap */ - typedef int SMT_Config; +typedef int SMT_Config; #define SMD_SEGMENT_SIZE 1 /* Définir la taille des segments */ #define SMD_HEAP_LIMIT 2 /* Définir la taille maximale */ @@ -99,15 +115,21 @@ extern "C" { #define SMD_DEFAULT_COMPRESS 1000 /* si + de 1000 chunks libres, alors compression du heap */ + + /* Différentes valeurs de configuration */ #define SMD_UNLIMITED 0 #define SMD_NO_AUTO_COMPRESS 0 + + /* Nom du heap système */ #define HEAP_SYSTEM "system" + + #ifndef FALSE #define FALSE 0 #endif @@ -116,12 +138,103 @@ extern "C" { #define TRUE 1 #endif + + + + #ifdef _LIBSHMEM_C_ char SM_Error_Msg [512]; #else extern char SM_Error_Msg [512]; #endif + +/*------------------------------------------------------------------------------*/ +/* Structure de la base de heaps */ +/*------------------------------------------------------------------------------*/ + + typedef struct { + int SysMemId; /* Id de la 1ère zone de mémoire partagée de la base */ + int DataMemId; /* Id de la 2ème zone de mémoire partagée de la base */ + size_t Size; /* Taille de la zone de mémoire partagée */ + int SemId; /* Id du sémaphore pour la gestion des verrous */ + NDT_Root * MHR; /* Memory Heap Root : racine de la liste de heap */ + pid_t Creator; /* Id du processus créateur de la base */ + pid_t Writer; /* Id du dernier processus ayant accédé en écriture à la base */ + void * Free; /* Pointeur sur la première zone libre de la base */ + void * Attach; /* Adresse du dernier attachement */ + size_t Segment_Size; /* Taille par défaut des segments qui composeront les heaps */ + } SMT_Base; + +/* Référence sur la base de heaps */ + +#ifdef _LIBSHMEM_C_ + SMT_Base * SM_Base; +#else + extern SMT_Base * SM_Base; +#endif + + + +/*------------------------------------------------------------------------------*/ +/* Structure d'un MHH (Memory Heap Header) */ +/* Rappel : un MHH est une valeur attachée à un MHN (Memory Heap Node) */ +/*------------------------------------------------------------------------------*/ + +typedef struct { + char Name [SMD_NAME_SIZE]; /* Nom du heap */ + int SemId; /* Id du sémaphore pour la gestion des verrous */ + NDT_Root *DSR; /* Data Segment Root */ + NDT_Root *ACR; /* Allocated Chunks Root */ + NDT_Root *FCR; /* Free Chunks Root */ + pid_t Writer; /* Id du processus ayant accédé en dernier au MHH en écriture */ + int State; /* Etat d'un heap (valide, non validé ou corrompu) */ + size_t Segment_Size; /* Taille des segments de mémoire composant le heap */ + size_t Limit_Size; /* Taille limite du heap (par défaut : pas de limite) */ + int Auto_Compress; /* Nombre de chunks libres à partir duquel le heap est automatiquement compressé */ + long Compress_Nb; /* Nomber of time the heap has been compressed */ +} SMT_MHH; + +/* Heap ouvert */ + +typedef struct { + char * Name; + SMT_MHH * MHH; + SMT_Flags Lock_Mode; /* Mode dans lequel le heap est verrouillé */ + int Nb_Seg; /* Nombre de segments du heap lors de son ouverture */ +} SMT_Heap; + + + +/*------------------------------------------------------------------------------*/ +/* Structure d'un DSH (Data Segment Header) */ +/* Rappel : un DSH est une valeur attachée à un DSN (noeud de DSR) */ +/*------------------------------------------------------------------------------*/ + + typedef struct { + int MemId; /* Id de la zone de mémoire partagée */ + size_t Size; /* Taille de la zone de mémoire partagée */ + void * Start; /* Adresse de début de la zone de mémoire partagée */ + } SMT_DSH; + + + +/*------------------------------------------------------------------------------*/ +/* Structure d'un chunk */ +/* Rappel : un chunk est la valeur attachée à un noeud de ACR ou FCR */ +/*------------------------------------------------------------------------------*/ + + typedef struct { + size_t Size; /* Taille allouée au chunk */ + void * Data; /* Adresse de la zone de données du chunk */ + } SMT_Chunk; + + + + + +/* Alias API definition */ + #ifndef SM_MODE #define SM_MODE 0 #endif @@ -174,79 +287,7 @@ extern "C" { #endif -/*------------------------------------------------------------------------------*/ -/* Structure de la base de heaps */ -/*------------------------------------------------------------------------------*/ - typedef struct { - int SysMemId; /* Id de la 1ère zone de mémoire partagée de la base */ - int DataMemId; /* Id de la 2ème zone de mémoire partagée de la base */ - size_t Size; /* Taille de la zone de mémoire partagée */ - int SemId; /* Id du sémaphore pour la gestion des verrous */ - NDT_Root * MHR; /* Memory Heap Root : racine de la liste de heap */ - pid_t Creator; /* Id du processus créateur de la base */ - pid_t Writer; /* Id du dernier processus ayant accédé en écriture à la base */ - void * Free; /* Pointeur sur la première zone libre de la base */ - void * Attach; /* Adresse du dernier attachement */ - size_t Segment_Size; /* Taille par défaut des segments qui composeront les heaps */ - } SMT_Base; - -/* Référence sur la base de heaps */ - -#ifdef _LIBSHMEM_C_ - SMT_Base * SM_Base; -#else - extern SMT_Base * SM_Base; -#endif - -/*------------------------------------------------------------------------------*/ -/* Structure d'un MHH (Memory Heap Header) */ -/* Rappel : un MHH est une valeur attachée à un MHN (Memory Heap Node) */ -/*------------------------------------------------------------------------------*/ - - typedef struct { - char Name [256]; /* Nom du heap */ - int SemId; /* Id du sémaphore pour la gestion des verrous */ - NDT_Root * DSR; /* Data Segment Root */ - NDT_Root * ACR; /* Allocated Chunks Root */ - NDT_Root * FCR; /* Free Chunks Root */ - pid_t Writer; /* Id du processus ayant accédé en dernier au MHH en écriture */ - int State; /* Etat d'un heap (valide, non validé ou corrompu) */ - size_t Segment_Size; /* Taille des segments de mémoire composant le heap */ - size_t Limit_Size; /* Taille limite du heap (par défaut : pas de limite) */ - int Auto_Compress; /* Nombre de chunks libres à partir duquel le heap est automatiquement compressé */ - long Compress_Nb; /* Nomber of time the heap has been compressed */ - } SMT_MHH; - -/* Heap ouvert */ - - typedef struct { - char * Name; - SMT_MHH * MHH; - SMT_Flags Lock_Mode; /* Mode dans lequel le heap est verrouillé */ - int Nb_Seg; /* Nombre de segments du heap lors de son ouverture */ - } SMT_Heap; - -/*------------------------------------------------------------------------------*/ -/* Structure d'un DSH (Data Segment Header) */ -/* Rappel : un DSH est une valeur attachée à un DSN (noeud de DSR) */ -/*------------------------------------------------------------------------------*/ - - typedef struct { - int MemId; /* Id de la zone de mémoire partagée */ - size_t Size; /* Taille de la zone de mémoire partagée */ - void * Start; /* Adresse de début de la zone de mémoire partagée */ - } SMT_DSH; - -/*------------------------------------------------------------------------------*/ -/* Structure d'un chunk */ -/* Rappel : un chunk est la valeur attachée à un noeud de ACR ou FCR */ -/*------------------------------------------------------------------------------*/ - - typedef struct { - size_t Size; /* Taille allouée au chunk */ - void * Data; /* Adresse de la zone de données du chunk */ - } SMT_Chunk; /*------------------------------------------------------------------------------*/ /* Ouverture d'une instance de la librairie */ @@ -258,6 +299,8 @@ extern "C" { SMT_Status SM_Library_Open_I ( int Instance, const char * Context, SMT_Flags Flags ); SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_Flags Flags ); + + /*------------------------------------------------------------------------------*/ /* Récupération du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ @@ -266,6 +309,8 @@ extern "C" { SMT_Status SM_Library_Instance_Get_I ( int * Instance); SMT_Status SM_Library_Instance_Get_C ( int * Instance); + + /*------------------------------------------------------------------------------*/ /* Changement de contexte d'utilisation de la librairie */ /*------------------------------------------------------------------------------*/ @@ -274,6 +319,8 @@ extern "C" { SMT_Status SM_Library_Context_Set_I ( const char * Context ); SMT_Status SM_Library_Context_Set_C ( const char * Context ); + + /*------------------------------------------------------------------------------*/ /* Récupération du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ @@ -282,6 +329,8 @@ extern "C" { SMT_Status SM_Library_Context_Get_I ( char ** Context ); SMT_Status SM_Library_Context_Get_C ( char ** Context ); + + /*------------------------------------------------------------------------------*/ /* Fermeture de l'instance de la librairie */ /*------------------------------------------------------------------------------*/ @@ -290,6 +339,8 @@ extern "C" { SMT_Status SM_Library_Close_I ( SMT_Flags Flags ); SMT_Status SM_Library_Close_C ( SMT_Flags Flags ); + + /*------------------------------------------------------------------------------*/ /* Affichage des informations de la base de mémoires partagées */ /*------------------------------------------------------------------------------*/ @@ -298,18 +349,24 @@ extern "C" { SMT_Status SM_Library_Dump_I ( FILE * Out ); SMT_Status SM_Library_Dump_C ( FILE * Out ); + + /*------------------------------------------------------------------------------*/ /* Libération de tous les verrous (base, heap) */ /*------------------------------------------------------------------------------*/ SMT_Status SM_Library_Unlock_I ( void ); SMT_Status SM_Library_Unlock_C ( void ); + + /*------------------------------------------------------------------------------*/ /* Définition de la sortie standard des messages d'erreur de la librairie */ /*------------------------------------------------------------------------------*/ SMT_Status SM_Library_Stderr_Set_I ( FILE * Out ); SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ); + + /*------------------------------------------------------------------------------*/ /* Test d'existence d'un heap */ /*------------------------------------------------------------------------------*/ @@ -318,6 +375,8 @@ extern "C" { SMT_Status SM_Heap_Exist_I ( const char * Heap_Name ); SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ); + + /*------------------------------------------------------------------------------*/ /* Ouverture/création d'un heap */ /*------------------------------------------------------------------------------*/ @@ -330,6 +389,8 @@ extern "C" { SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Flags, int * Locked ); SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Flags, int * Locked ); + + /*------------------------------------------------------------------------------*/ /* Teste si un heap a déjà été ouvert par le processus courant */ /*------------------------------------------------------------------------------*/ @@ -339,6 +400,8 @@ extern "C" { SMT_Status SM_Heap_IsOpen_I ( const char * Heap_Name, SMT_Heap ** Heap ); SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ); + + /*------------------------------------------------------------------------------*/ /* Fermeture d'un heap */ /*------------------------------------------------------------------------------*/ @@ -347,6 +410,8 @@ extern "C" { SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap ); SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ); + + /*------------------------------------------------------------------------------*/ /* Destruction d'un heap */ /*------------------------------------------------------------------------------*/ @@ -355,6 +420,8 @@ extern "C" { SMT_Status SM_Heap_End_I ( const char * Heap_Name ); SMT_Status SM_Heap_End_C ( const char * Heap_Name ); + + /*------------------------------------------------------------------------------*/ /* Compression d'un heap */ /*------------------------------------------------------------------------------*/ @@ -364,6 +431,8 @@ extern "C" { SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress ); SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ); + + /*------------------------------------------------------------------------------*/ /* Configuration d'un heap */ /*------------------------------------------------------------------------------*/ @@ -373,6 +442,8 @@ extern "C" { SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ); SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ); + + /*------------------------------------------------------------------------------*/ /* Vérification/correction des structures d'un heap : */ /*------------------------------------------------------------------------------*/ @@ -384,6 +455,8 @@ extern "C" { SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out); SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out); + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ @@ -394,6 +467,8 @@ extern "C" { SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Flags, int * Locked ); SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Flags, int * Locked ); + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ @@ -402,6 +477,8 @@ extern "C" { SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap ); SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ); + + /*------------------------------------------------------------------------------*/ /* Allocation d'un chunk dans un heap */ /*------------------------------------------------------------------------------*/ @@ -412,6 +489,8 @@ extern "C" { SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ); SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ); + + /*------------------------------------------------------------------------------*/ /* Désallocation d'un chunk */ /*------------------------------------------------------------------------------*/ @@ -421,6 +500,8 @@ extern "C" { SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr ); SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr ); + + #ifdef __cplusplus } #endif diff --git a/lib/libshmem.c b/lib/libshmem.c index 690f7c8..724a67d 100644 --- a/lib/libshmem.c +++ b/lib/libshmem.c @@ -106,7 +106,7 @@ VER_INFO_EXPORT(libshmem,"$Revision: 2.4 $", "$Name: $",__FILE__,"$Author: agib /* Ouverture de la liste des heaps ouverts (locale) */ rc = ND_DataStruct_Open( &Opened_Heap_List, 1, &index_type, "SM_Opened_Heap_List_Manager", NULL, NULL, NULL, NULL, NULL, TRUE, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf( SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); SM_Error_Print(); @@ -458,10 +458,12 @@ SMT_Status SM_Heap_Exist_I ( const char *Heap_Name) { NDT_Node *Node; SMT_MHH *MHH; - char *Prefixed_Name = SM_Name_Prefix( Heap_Name); + char prefixed_name[ SMD_NAME_SIZE]; int Locked = FALSE; + SM_Name_Prefix( prefixed_name, Heap_Name); + if( strcmp( Heap_Name, HEAP_SYSTEM)) { /* Verrouillage du heap système en lecture */ @@ -477,7 +479,7 @@ SMT_Status SM_Heap_Exist_I ( const char *Heap_Name) { MHH = (SMT_MHH *)( Node->Value); - if (!strcmp( Prefixed_Name, MHH->Name)) + if( !strcmp( prefixed_name, MHH->Name)) { return( SMS_YES); } @@ -514,7 +516,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se SMT_MHH *MHH; NDT_Node *Node; SMT_DSH *New_DSH; - char *Prefixed_Name; + char prefixed_name[ SMD_NAME_SIZE]; union semun Sem_Ctl; int SemId; SMT_Status rc; @@ -532,7 +534,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* Verrouillage du heap dans le mode demandé */ rc = SM_Heap_Lock_I( *Heap, SMD_LOCK_MSK( Open_Mode), Locked); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", Heap_Name, Open_Mode & SMD_READ ? "reading" : "writing"); SM_Error_Print(); @@ -551,8 +553,10 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se } } - Prefixed_Name = SM_Name_Prefix( Heap_Name); + SM_Name_Prefix( prefixed_name, Heap_Name); + + /* On regarde si le heap existe déjà dans la base */ if( SM_Heap_Exist_I( Heap_Name) == SMS_YES) @@ -564,7 +568,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se /* Ouverture d'un heap existant */ - strcpy( To_Find.Name, Prefixed_Name); + strcpy( To_Find.Name, prefixed_name); ND_Index_Node_Find( &Node, SM_Base->MHR, NDD_INDEX_PRIMARY, &To_Find, NULL); MHH = (SMT_MHH *)( Node->Value); @@ -572,13 +576,13 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se *Heap = (SMT_Heap *) malloc( sizeof( SMT_Heap)); if( !*Heap) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the opened heap \"%s\"", Prefixed_Name); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the opened heap \"%s\"", prefixed_name); SM_Error_Print(); return( SMS_ERRMEM); } - ( *Heap)->Name = strdup( Prefixed_Name); + ( *Heap)->Name = strdup( prefixed_name); ( *Heap)->MHH = MHH; ( *Heap)->Lock_Mode = SMD_NO_LOCK; @@ -592,7 +596,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se if( rc != SMS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to open one of the data segments of heap \"%s\"", Prefixed_Name); + sprintf (SM_Error_Msg, "SM_Heap_Open : unable to open one of the data segments of heap \"%s\"", prefixed_name); SM_Error_Print (); goto Error1; @@ -609,7 +613,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se if( rc != SMS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", Prefixed_Name, Open_Mode & SMD_READ ? "reading" : "writing"); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", prefixed_name, Open_Mode & SMD_READ ? "reading" : "writing"); SM_Error_Print(); goto Error1; @@ -621,7 +625,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", Prefixed_Name); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", prefixed_name); SM_Error_Print(); goto Error2; @@ -638,16 +642,22 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se } } + fprintf( stderr, "Heap not Open!!!\n"); + + if( !( Open_Mode & SMD_CREATE)) { - sprintf( SM_Error_Msg, "SM_Heap_Open : the heap \"%s\" does no exist and (Open_Mode & SMD_CREATE) is false", Prefixed_Name); + sprintf( SM_Error_Msg, "SM_Heap_Open : the heap \"%s\" does no exist and (Open_Mode & SMD_CREATE) is false", prefixed_name); SM_Error_Print(); return( SMS_ERRAPI); } + fprintf( stderr, "Heap to be created!!!\n"); + + /*Alloc du MHH qui fait l'alloccation du premier segment de donnees*/ - rc = ND_Value_Alloc( (void **)&MHH, SM_Base->MHR, Prefixed_Name, Seg_Size); + rc = ND_Value_Alloc( (void **)&MHH, SM_Base->MHR, prefixed_name, Seg_Size); if( rc != NDS_OK) { sprintf( SM_Error_Msg, "SM_Heap_Open : unable to alloc a new MHH structure"); @@ -671,7 +681,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se if( rc != SMS_OK) { sprintf( SM_Error_Msg, "SM_Heap_Open : unable to lock heap \"%s\" for %s", - Prefixed_Name, Open_Mode & SMD_READ ? "reading" : "writing"); + prefixed_name, Open_Mode & SMD_READ ? "reading" : "writing"); SM_Error_Print(); goto Error10; } @@ -683,14 +693,14 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se *Heap = (SMT_Heap *)malloc( sizeof( SMT_Heap)); if( !*Heap) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for a new opened heap \"%s\"", Prefixed_Name); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for a new opened heap \"%s\"", prefixed_name); SM_Error_Print(); rc = SMS_ERRMEM; goto Error10; } - ( *Heap)->Name = strdup( Prefixed_Name); + ( *Heap)->Name = strdup( prefixed_name); ( *Heap)->MHH = MHH; ( *Heap)->Lock_Mode = SMD_LOCK_MSK( Open_Mode); ( *Heap)->Nb_Seg = 1; @@ -698,7 +708,7 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se rc = ND_DataStruct_Value_Add( Opened_Heap_List, *Heap); if( rc != NDS_OK) { - sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", Prefixed_Name); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", prefixed_name); SM_Error_Print(); goto Error11; @@ -770,13 +780,15 @@ SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Se SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap ) { SMT_Status rc; + char prefixed_name[ SMD_NAME_SIZE]; SMT_Heap To_Find; NDT_Node *Node_Ptr; *Heap = NULL; - To_Find.Name = SM_Name_Prefix( Heap_Name); + To_Find.Name = prefixed_name; + SM_Name_Prefix( prefixed_name, Heap_Name); rc = ND_Index_Node_Find( &Node_Ptr, Opened_Heap_List, NDD_INDEX_PRIMARY, &To_Find, NULL); @@ -788,6 +800,7 @@ SMT_Status SM_Heap_IsOpen_I( const char *Heap_Name, SMT_Heap **Heap ) { if( Node_Ptr == NULL) { + *Heap = NULL; return( SMS_NO); } else @@ -816,8 +829,8 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) rc = SM_Heap_Exist_I (Heap_Name); - if (SM_ERROR(rc)) return rc; - if (rc == SMS_NO) + if( SM_ERROR(rc)) return rc; + if( rc == SMS_NO) { sprintf (SM_Error_Msg, "SM_Heap_End: heap \"%s\" does not exist", Heap_Name); SM_Error_Print (); @@ -826,8 +839,8 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) } rc = SM_Heap_IsOpen_I (Heap_Name, &Heap); - if (SM_ERROR(rc)) return rc; - if (rc == SMS_YES) + if( SM_ERROR(rc)) return rc; + if( rc == SMS_YES) { /* Verrouillage en écriture */ @@ -838,7 +851,7 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) /* Ouverture du heap en écriture */ rc = SM_Heap_Open_I (Heap_Name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_End : unable to open the heap to remove for writing"); SM_Error_Print (); @@ -850,7 +863,7 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) /* Suppression du heap */ rc = ND_DataStruct_Value_Remove( SM_Base->MHR, Heap->MHH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Heap_End: unable to remove heap \"%s\" from the MHR structure", Heap_Name); SM_Error_Print (); @@ -859,7 +872,7 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) } rc = ND_Value_Free( SM_Base->MHR, Heap->MHH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Heap_End: unable to free heap \"%s\"", Heap_Name); SM_Error_Print (); @@ -894,7 +907,7 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) while (Node) { rc = SM_DataSegment_Close (Node->Value); - if (SM_ERROR(rc)) return rc; + if( SM_ERROR(rc)) return rc; ND_Index_Node_Previous_Get( &Node, Node); } @@ -906,7 +919,7 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) /* Suppression du heap de la liste des heaps ouverts */ rc = ND_DataStruct_Value_Remove( Opened_Heap_List, Heap); - if (SM_ERROR(rc)) return rc; + if( SM_ERROR(rc)) return rc; rc = ND_Value_Free( Opened_Heap_List, Heap); return rc; @@ -951,7 +964,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( Heap->MHH->State == SMD_STATE_CORRUPTED) { - sprintf (SM_Error_Msg, "SM_Heap_Lock : heap \"%s\" is flagged as being corrupted", Heap->Name); + sprintf( SM_Error_Msg, "SM_Heap_Lock : heap \"%s\" is flagged as being corrupted", Heap->Name); SM_Error_Print (); return SMS_KO; @@ -959,7 +972,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) /* Verrouillage du heap dans le mode demandé */ - rc = SM_Heap_Lock_Set (Heap->MHH, Lock_Mode); + rc = SM_Heap_Lock_Set( Heap->MHH, Lock_Mode); if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock : unable to lock heap \"%s\" for %s", Heap->Name, Lock_Mode & SMD_READ ? "reading" : "writing"); @@ -974,10 +987,10 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { /* Verrouillage du heap en écriture pour le vérifier */ - if (Lock_Mode == SMD_READ) + if( Lock_Mode == SMD_READ) { - rc = SM_Heap_Lock_Change (Heap->MHH, SMD_WRITE); - if (rc != SMS_OK) + rc = SM_Heap_Lock_Change( Heap->MHH, SMD_WRITE); + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock : unable to lock heap \"%s\" for writing before checking", Heap->Name); SM_Error_Print (); @@ -991,7 +1004,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) Nb_Detected = Nb_Corrected = 0; rc = SM_Heap_Check_I (Heap, &Nb_Detected, &Nb_Corrected, SM_stderr); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock : unable to check heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1005,7 +1018,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) if( Lock_Mode == SMD_READ) { rc = SM_Heap_Lock_Change (Heap->MHH, SMD_READ); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock : unable to lock heap \"%s\" for reading", Heap->Name); SM_Error_Print (); @@ -1064,7 +1077,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) /* On vérifie qu'aucun nouveau segment n'a été ajouté depuis la dernière ouverture */ - if (Heap->Nb_Seg != Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number) + if( Heap->Nb_Seg != Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number) { NDT_Node * Node; @@ -1074,7 +1087,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) while (Node) { rc = SM_DataSegment_Open (Node->Value); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock : unable to open one of the data segments of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1109,7 +1122,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) *Locked = TRUE; } - return SMS_OK; + return( SMS_OK); } @@ -1127,7 +1140,7 @@ SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) SMT_Status rc; rc = SM_Heap_Lock_Release (Heap->MHH, Heap->Lock_Mode); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Unlock : unable to unlock heap \"%s\" for %s", Heap->Name, Heap->Lock_Mode & SMD_READ ? "reading" : "writing"); @@ -1181,14 +1194,14 @@ SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) Size = va_arg (Arguments, size_t); Current_Size = 0; - if (Size != SMD_UNLIMITED) + if( Size != SMD_UNLIMITED) { /* On contrôle que la limite fixée est inférieure à la taille actuelle du heap */ rc = ND_DataStruct_Traverse (Heap->MHH->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); - if (rc != NDS_OK) return rc; + if( rc != NDS_OK) return rc; - if (Current_Size > Size) + if( Current_Size > Size) { sprintf (SM_Error_Msg, "SM_Heap_Config : the heap has already exceeded the limit size (%d bytes)", Current_Size); SM_Error_Print (); @@ -1275,16 +1288,16 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc SMT_Status rc; NDT_Node * Node; - if (Out) fprintf (Out, "Checking heap \"%s\" ...\n", Heap->Name); + if( Out) fprintf (Out, "Checking heap \"%s\" ...\n", Heap->Name); - if (Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) + if( Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number == 0) { sprintf (SM_Error_Msg, "SM_Heap_Check : unable to check heap \"%s\" which has no data segment", Heap->Name); SM_Error_Print (); (*Nb_Detected) ++; - if (Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; return SMS_ERRAPI; @@ -1293,15 +1306,15 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc { /* Vérification de la structure DSR du heap */ - if (Out) fprintf (Out, "Checking the DSR node structure ...\n"); + if( Out) fprintf (Out, "Checking the DSR node structure ...\n"); rc = ND_DataStruct_Check (Heap->MHH->DSR, Nb_Detected, Nb_Corrected, Out); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Check : unable to check the DSR structure"); SM_Error_Print (); - if (Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1317,14 +1330,14 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc while (Node) { rc = SM_DataSegment_Open (Node->Value); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Check : unable to open one of the data segments of heap \"%s\"", Heap->Name); SM_Error_Print (); (*Nb_Detected) ++; - if (Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1335,15 +1348,15 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* Vérification de la structure ACR du heap */ - if (Out) fprintf (Out, "Checking the ACR node structure ...\n"); + if( Out) fprintf (Out, "Checking the ACR node structure ...\n"); rc = ND_DataStruct_Check (Heap->MHH->ACR, Nb_Detected, Nb_Corrected, Out); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Check : unable to check the ACR node structure"); SM_Error_Print (); - if (Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1351,15 +1364,15 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* Vérification de la structure FCR du heap */ - if (Out) fprintf (Out, "Checking the FCR node structure ...\n"); + if( Out) fprintf (Out, "Checking the FCR node structure ...\n"); rc = ND_DataStruct_Check (Heap->MHH->FCR, Nb_Detected, Nb_Corrected, Out); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Check : unable to check the ACR node structure"); SM_Error_Print (); - if (Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; return rc; @@ -1367,11 +1380,11 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* Conclusion de la procédure de vérification */ - if (*Nb_Detected > *Nb_Corrected) + if( *Nb_Detected > *Nb_Corrected) { /* On déclare le heap corrompu afin que plus personne n'y accède */ - if (Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "%d error(s) could not be corrected in heap \"%s\" which will be declared as corrupted.\n Please contact an administrator about it.\n", *Nb_Detected - *Nb_Corrected, Heap->Name); Heap->MHH->State = SMD_STATE_CORRUPTED; @@ -1380,13 +1393,13 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* On rend le heap valide */ - if (*Nb_Detected == 0) + if( *Nb_Detected == 0) { - if (Out) fprintf (Out, "No error detected on heap \"%s\" which will be declared as a valid heap\n", Heap->Name); + if( Out) fprintf (Out, "No error detected on heap \"%s\" which will be declared as a valid heap\n", Heap->Name); } else { - if (Out) fprintf (Out, "Every %d error(s) have beeen corrected on heap \"%s\" which will be declared as a valid heap\n", *Nb_Corrected, Heap->Name); + if( Out) fprintf (Out, "Every %d error(s) have beeen corrected on heap \"%s\" which will be declared as a valid heap\n", *Nb_Corrected, Heap->Name); } Heap->MHH->State = SMD_STATE_VALID; @@ -1434,7 +1447,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) */ - if (Heap == System_Heap) Alloc_Size = DEFAULT_CHUNK_SIZE; + if( Heap == System_Heap) Alloc_Size = DEFAULT_CHUNK_SIZE; /* Attention : pour les autres heaps, la taille allouée doit être arrondie à un multiple @@ -1443,7 +1456,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) Round_Size = Alloc_Size % sizeof (void *); - if (Round_Size) Alloc_Size += sizeof (void *) - Round_Size; + if( Round_Size) Alloc_Size += sizeof (void *) - Round_Size; /* Recherche d'un chunk suffisamment grand dans la liste des chunks libres */ @@ -1454,11 +1467,11 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) { Chunk = (SMT_Chunk *)(Node->Value); - if (Chunk->Size >= Alloc_Size) Found = TRUE; + if( Chunk->Size >= Alloc_Size) Found = TRUE; else ND_Index_Node_Next_Get( &Node, Node); } - if (Found == FALSE) + if( Found == FALSE) { /* Si aucun chunk libre suffisamment grand n'a été trouvé, @@ -1467,14 +1480,14 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) size_t Seg_Size; - if (Alloc_Size + sizeof (NDT_Node) + sizeof (SMT_Chunk) > Heap->MHH->Segment_Size) + if( Alloc_Size + sizeof (NDT_Node) + sizeof (SMT_Chunk) > Heap->MHH->Segment_Size) Seg_Size = Alloc_Size + sizeof (NDT_Node) + sizeof (SMT_Chunk); else Seg_Size = Heap->MHH->Segment_Size; rc = ND_Value_Alloc( (void**)&DSH, Heap->MHH->DSR, Heap->MHH, Seg_Size); - if (rc != NDS_OK ) + if( rc != NDS_OK ) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to create a new data segment for heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1483,7 +1496,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) } rc = ND_DataStruct_Value_Add (Heap->MHH->DSR, DSH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to add a data segment to the DSR structure of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1506,7 +1519,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* Suppression du chunk de la liste des chunks libres */ rc = ND_Index_Node_Remove (Node); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to remove a chunk from the FCR structure of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1517,7 +1530,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* Ajout du chunk à la liste des chunks alloués */ rc = ND_Index_Node_Add( Heap->MHH->ACR, NDD_INDEX_PRIMARY, Node); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to add a chunk to the ACR structure of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1534,7 +1547,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) on peut créer un nouveau chunk libre avec le reliquat de mémoire. */ - if (Chunk->Size - Alloc_Size > 0) + if( Chunk->Size - Alloc_Size > 0) { size_t Remaining_Size = Chunk->Size - Alloc_Size; @@ -1544,7 +1557,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) chunk libre que si le reliquat est suffisamment important. */ - if (Remaining_Size > sizeof (SMT_Chunk) + sizeof (NDT_Node)) + if( Remaining_Size > sizeof (SMT_Chunk) + sizeof (NDT_Node)) { NDT_Node * New_Node; SMT_Chunk * New_Chunk; @@ -1569,7 +1582,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) New_Node->Value = New_Chunk; rc = ND_Index_Node_Add( Heap->MHH->FCR, NDD_INDEX_PRIMARY, New_Node); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to add a chunk to the FCR structure of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1591,7 +1604,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) pas déjà en train d'étendre le heap système (Adding_Segment=TRUE). */ - if (Heap == System_Heap && Adding_Segment == FALSE) + if( Heap == System_Heap && Adding_Segment == FALSE) { SMT_Chunk * Free_Chunk; unsigned int Free_Usable_Chunk = 0; @@ -1605,7 +1618,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) { Free_Chunk = Node->Value; - if (Free_Chunk->Size >= DEFAULT_CHUNK_SIZE) + if( Free_Chunk->Size >= DEFAULT_CHUNK_SIZE) { Free_Usable_Chunk++; Free_Usable_Size += Free_Chunk->Size; @@ -1622,16 +1635,16 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) Dans le cas contraire, il est urgent d'étendre le heap système. */ - if (Free_Usable_Chunk < FREE_CHUNK_LIMIT) + if( Free_Usable_Chunk < FREE_CHUNK_LIMIT) { size_t Needed_Size; Needed_Size = (size_t)(FREE_CHUNK_LIMIT * DEFAULT_CHUNK_SIZE) + (size_t)(FREE_CHUNK_LIMIT - Free_Usable_Chunk) * (sizeof (NDT_Node) + sizeof (SMT_Chunk)); - if (Free_Usable_Size < Needed_Size) New_Seg_Needed = TRUE; + if( Free_Usable_Size < Needed_Size) New_Seg_Needed = TRUE; } - if (New_Seg_Needed == TRUE) + if( New_Seg_Needed == TRUE) { NDT_Node * New_Node; @@ -1655,7 +1668,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* On crée le nouveau segment */ rc = ND_Value_Alloc( (void**)&DSH, Heap->MHH->DSR, Heap->MHH, Heap->MHH->Segment_Size); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to create un new data segment for the system heap (anticipation)"); SM_Error_Print (); @@ -1668,7 +1681,7 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) /* On ajoute le nouveau segment au heap système */ rc = ND_Index_Node_Add( Heap->MHH->DSR, NDD_INDEX_PRIMARY, New_Node); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : unable to add a data segment to the DSR structure of the system heap (anticipation)"); SM_Error_Print (); @@ -1731,7 +1744,7 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) /* Suppression du chunk de la liste des chunks alloués */ rc = ND_Index_Node_Remove (Node); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Free : unable to remove the allocated chunk from the ACR structure of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1742,7 +1755,7 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) /* Ajout du chunk à la liste des chunks libres */ rc = ND_Index_Node_Add( Heap->MHH->FCR, NDD_INDEX_PRIMARY, Node); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Free : unable to add the free chunk to the FCR structure of heap \"%s\"", Heap->Name); SM_Error_Print (); @@ -1763,13 +1776,13 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) /* Activation de la compression automatique */ - if (Heap->MHH->Auto_Compress != SMD_NO_AUTO_COMPRESS && + if( Heap->MHH->Auto_Compress != SMD_NO_AUTO_COMPRESS && Heap->MHH->FCR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number > Heap->MHH->Auto_Compress) { size_t Compress_Size; rc = SM_Heap_Compress (Heap, &Compress_Size); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Chunk_Free : unable to compress FCR structure of heap \"%s\" which contains %ld free chunks", Heap->Name, Heap->MHH->FCR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number); SM_Error_Print (); @@ -1858,7 +1871,7 @@ SMT_Status SM_Library_Context_Set_C ( const char * Context ) SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Library_Close : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -1879,7 +1892,7 @@ SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode ) SMT_Status SM_Library_Dump_C (FILE * Out) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Library_Dump : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -1899,7 +1912,7 @@ SMT_Status SM_Library_Dump_C (FILE * Out) SMT_Status SM_Library_Unlock_C ( void ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Library_Unlock : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -1934,14 +1947,14 @@ SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ) SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Exist : the LIBSHMEM library is not open"); SM_Error_Print (); return SMS_ERRAPI; } - if (!Heap_Name) + if( !Heap_Name) { sprintf (SM_Error_Msg, "SM_Heap_Exist : the heap name is undefined"); SM_Error_Print (); @@ -1967,7 +1980,7 @@ SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Open_Mode, int * Locked ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Open : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -1975,7 +1988,7 @@ SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg return SMS_ERRAPI; } - if (!Heap_Name) + if( !Heap_Name) { sprintf (SM_Error_Msg, "SM_Heap_Open : the heap name is undefined"); SM_Error_Print (); @@ -1998,7 +2011,7 @@ SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_IsOpen : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2006,7 +2019,7 @@ SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) return SMS_ERRAPI; } - if (!Heap_Name) + if( !Heap_Name) { sprintf (SM_Error_Msg, "SM_Heap_IsOpen : the heap name is undefined"); SM_Error_Print (); @@ -2028,7 +2041,7 @@ SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) SMT_Status SM_Heap_End_C ( const char * Heap_Name ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_End : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2036,7 +2049,7 @@ SMT_Status SM_Heap_End_C ( const char * Heap_Name ) return SMS_ERRAPI; } - if (!Heap_Name) + if( !Heap_Name) { sprintf (SM_Error_Msg, "SM_Heap_End : the heap name is undefined"); SM_Error_Print (); @@ -2058,7 +2071,7 @@ SMT_Status SM_Heap_End_C ( const char * Heap_Name ) SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Close : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2066,7 +2079,7 @@ SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Heap_Close : the heap is undefined"); SM_Error_Print (); @@ -2090,7 +2103,7 @@ SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Lock : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2098,7 +2111,7 @@ SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Heap_Lock : the heap is undefined"); SM_Error_Print (); @@ -2120,7 +2133,7 @@ SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Unlock : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2128,7 +2141,7 @@ SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Heap_Unlock : the heap is undefined"); SM_Error_Print (); @@ -2156,7 +2169,7 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) SMT_Status rc; - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Config : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2164,7 +2177,7 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Heap_Config : the heap is undefined"); SM_Error_Print (); @@ -2187,14 +2200,14 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) Limit_Size = va_arg (Arguments, size_t); Current_Size = 0; - if (Limit_Size != SMD_UNLIMITED) + if( Limit_Size != SMD_UNLIMITED) { /* On contrôle que la limite fixée est inférieure à la taille actuelle du heap */ rc = ND_DataStruct_Traverse (Heap->MHH->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); - if (rc != NDS_OK) return rc; + if( rc != NDS_OK) return rc; - if (Current_Size > Limit_Size) + if( Current_Size > Limit_Size) { sprintf (SM_Error_Msg, "SM_Heap_Config : the heap has already exceeded the limit size (%d bytes)", Current_Size); SM_Error_Print (); @@ -2234,7 +2247,7 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Compress : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2242,14 +2255,14 @@ SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Heap_Compress : the heap is undefined"); SM_Error_Print (); return SMS_ERRAPI; } - if (!Compress) + if( !Compress) { sprintf (SM_Error_Msg, "SM_Heap_Compress : the compress size pointer is null"); SM_Error_Print (); @@ -2274,7 +2287,7 @@ SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out ) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Check : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2282,21 +2295,21 @@ SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Heap_Check : the heap is undefined"); SM_Error_Print (); return SMS_ERRAPI; } - if (!Nb_Detected || !Nb_Corrected) + if( !Nb_Detected || !Nb_Corrected) { sprintf (SM_Error_Msg, "SM_Heap_Check : the error number pointer is null"); SM_Error_Print (); return SMS_ERRAPI; } - if (!Out) + if( !Out) { sprintf (SM_Error_Msg, "SM_Heap_Check : the out stream is null"); SM_Error_Print (); @@ -2320,7 +2333,7 @@ SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2328,14 +2341,14 @@ SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : the heap is undefined"); SM_Error_Print (); return SMS_ERRAPI; } - if (!Ptr) + if( !Ptr) { sprintf (SM_Error_Msg, "SM_Chunk_Alloc : the chunk address is null"); SM_Error_Print (); @@ -2358,7 +2371,7 @@ SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr) { - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Chunk_Free : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -2366,14 +2379,14 @@ SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr) return SMS_ERRAPI; } - if (!Heap) + if( !Heap) { sprintf (SM_Error_Msg, "SM_Chunk_Free : the heap is undefined"); SM_Error_Print (); return SMS_ERRAPI; } - if (!Ptr) + if( !Ptr) { sprintf (SM_Error_Msg, "SM_Chunk_Free : the chunk pointer is null"); SM_Error_Print (); @@ -2471,7 +2484,7 @@ SMT_Status SM_Base_Init ( void ) /* Création du sémaphore pour la gestion des verrous sur la base */ SemId = semget (IPC_PRIVATE, 1, 0777|IPC_CREAT|IPC_EXCL); - if (SemId == -1) + if( SemId == -1) { switch (errno) { @@ -2497,7 +2510,7 @@ SMT_Status SM_Base_Init ( void ) Sem_Ctl.val = 1; - if (semctl (SemId, 0, SETVAL, Sem_Ctl )) + if( semctl (SemId, 0, SETVAL, Sem_Ctl )) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to initialize the value of semaphore %d", SemId); SM_Error_Print (); @@ -2512,7 +2525,7 @@ SMT_Status SM_Base_Init ( void ) */ SysMemId = shmget (SM_Instance, (int) sizeof (SMT_Base), 0777|IPC_CREAT|IPC_EXCL); - if (SysMemId == -1) + if( SysMemId == -1) { switch (errno) { @@ -2547,7 +2560,7 @@ SMT_Status SM_Base_Init ( void ) errno = 0; SM_Base = shmat( SysMemId, 0, 0); - if (errno) + if( errno) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to attach the first shared memory segment to the current process (error %d)", errno); SM_Error_Print (); @@ -2580,7 +2593,7 @@ SMT_Status SM_Base_Init ( void ) Size = sizeof (NDT_Root) + sizeof (NDT_Node) + sizeof (SMT_MHH) + 3 * sizeof (NDT_Root) + sizeof (NDT_Node) + sizeof (SMT_DSH); DataMemId = shmget (IPC_PRIVATE, Size, 0777|IPC_CREAT|IPC_EXCL); - if (DataMemId == -1) + if( DataMemId == -1) { switch (errno) { @@ -2632,7 +2645,7 @@ SMT_Status SM_Base_Init ( void ) SM_Base->Free = shmat( DataMemId, 0, 0); #endif - if (errno) + if( errno) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to attach the second shared memory segment to the current process (error %d)", errno); SM_Error_Print (); @@ -2646,7 +2659,7 @@ SMT_Status SM_Base_Init ( void ) /* Création du MHR dans la base */ rc = ND_DataStruct_Open( &( SM_Base->MHR), 1, &index_type, "MHR_Manager", NULL, "SM_Base_Alloc", NULL, "SM_Base_Free", NULL, TRUE, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to create the MHR structure"); SM_Error_Print (); @@ -2662,7 +2675,7 @@ SMT_Status SM_Base_Init ( void ) */ rc = SM_Heap_Open_I (HEAP_SYSTEM, &System_Heap, 0, SMD_CREATE, &Locked); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to create the system heap"); SM_Error_Print (); @@ -2695,7 +2708,7 @@ SMT_Status SM_Base_Init ( void ) /* Verrouillage de la base en lecture */ rc = SM_Base_Lock (SMD_READ); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to lock the shared memory base for reading"); SM_Error_Print (); @@ -2742,7 +2755,7 @@ SMT_Status SM_Base_End ( void ) /* Retrait du verrou en lecture sur la base */ rc = SM_Base_Unlock (SMD_READ); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_End : unable to unlock the shared memory base"); SM_Error_Print (); @@ -2753,7 +2766,7 @@ SMT_Status SM_Base_End ( void ) /* Verrouillage de la base en écriture */ rc = SM_Base_Lock (SMD_WRITE); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_End : unable to lock the shared memory base for writing"); SM_Error_Print (); @@ -2791,7 +2804,7 @@ SMT_Status SM_Base_End ( void ) /* Retrait du heap de la structure du MHR */ rc = ND_DataStruct_Value_Remove( SM_Base->MHR, MHH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Base_End : unable to remove heap \"%s\" from the MHR", MHH->Name); SM_Error_Print (); @@ -2805,7 +2818,7 @@ SMT_Status SM_Base_End ( void ) /* Suppression du heap */ rc = ND_Value_Free (SM_Base->MHR, MHH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_Base_End : unable to free heap \"%s\"", MHH->Name); SM_Error_Print (); @@ -2825,7 +2838,7 @@ SMT_Status SM_Base_End ( void ) /* Destruction des segments de mémoire partagée de la base */ - if (shmctl (DataMemId, IPC_RMID, 0) == -1 || shmctl (SysMemId, IPC_RMID, 0) == -1) + if( shmctl (DataMemId, IPC_RMID, 0) == -1 || shmctl (SysMemId, IPC_RMID, 0) == -1) { switch (errno) { @@ -2854,7 +2867,7 @@ SMT_Status SM_Base_End ( void ) /* Destruction du sémaphore de gestion des verrous sur la base */ - if (semctl (SemId, 0, IPC_RMID, Sem_Ctl) == -1) + if( semctl (SemId, 0, IPC_RMID, Sem_Ctl) == -1) { switch (errno) { @@ -2895,12 +2908,12 @@ SMT_Status SM_Base_Open ( void ) int Locked; - if (SM_Base) return SMS_OK; + if( SM_Base) return SMS_OK; /* Récupération de l'identifiant du segment de mémoire partagée de la base */ MemId = shmget (SM_Instance, 0, 0); - if (MemId == -1) + if( MemId == -1) { switch (errno) { @@ -2930,7 +2943,7 @@ SMT_Status SM_Base_Open ( void ) errno = 0; SM_Base = shmat( MemId, 0, 0); - if (errno) + if( errno) { sprintf (SM_Error_Msg, "SM_Base_Open : unable to attach the shared memory segment to the current process (error %d)", errno); SM_Error_Print (); @@ -2942,7 +2955,7 @@ SMT_Status SM_Base_Open ( void ) errno = 0; Ptr = shmat (SM_Base->DataMemId, SM_Base->MHR, 0); - if (errno) + if( errno) { sprintf (SM_Error_Msg, "SM_Base_Open : unable to attach the shared memory segment to the current process at the specified address %p (error %d)", SM_Base->MHR, errno); SM_Error_Print (); @@ -2956,7 +2969,7 @@ SMT_Status SM_Base_Open ( void ) /* Verrouillage de la base en lecture */ rc = SM_Base_Lock (SMD_READ); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Open : unable to lock the shared memory base for reading"); SM_Error_Print (); @@ -2970,7 +2983,7 @@ SMT_Status SM_Base_Open ( void ) /* Ouverture du heap système (sans le verrouiller) */ rc = SM_Heap_Open_I (HEAP_SYSTEM, &System_Heap, 0, SMD_OPEN, &Locked); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Open : unable to open the system heap"); SM_Error_Print (); @@ -2997,7 +3010,7 @@ SMT_Status SM_Base_Close ( void ) NDT_Node * Node; - if (!SM_Base) + if( !SM_Base) { sprintf (SM_Error_Msg, "SM_Base_Close : the LIBSHMEM library is not open"); SM_Error_Print (); @@ -3047,10 +3060,10 @@ SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) { SMT_Status rc; - if (Lock_Mode & SMD_READ) + if( Lock_Mode & SMD_READ) { rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_SSL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Lock : unable to lock the library base for reading"); SM_Error_Print (); @@ -3059,10 +3072,10 @@ SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) } } - if (Lock_Mode & SMD_WRITE) + if( Lock_Mode & SMD_WRITE) { rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_SEL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Lock : unable to lock the library base for writing"); SM_Error_Print (); @@ -3086,10 +3099,10 @@ SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode ) { SMT_Status rc; - if (Lock_Mode & SMD_READ) + if( Lock_Mode & SMD_READ) { rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_RSL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Unlock : unable to unlock the library base which had been locked for reading"); SM_Error_Print (); @@ -3098,10 +3111,10 @@ SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode ) } } - if (Lock_Mode & SMD_WRITE) + if( Lock_Mode & SMD_WRITE) { rc = SM_Semaphore_Operate (SM_Base->SemId, SM_SemOp_REL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Base_Unlock : unable to unlock the library base which had been locked for writing"); SM_Error_Print (); @@ -3551,7 +3564,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node */ rc = ND_DataStruct_Open( &( (*MHH_Ptr_Ptr)->DSR), 1, &index_type, "SM_DSR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the DSR structure"); SM_Error_Print(); @@ -3566,7 +3579,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node */ rc = ND_DataStruct_Open( &( (*MHH_Ptr_Ptr)->ACR), 1, &index_type, "SM_ACR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Deallocator_Name, NULL, TRUE, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the ACR structure"); SM_Error_Print(); @@ -3666,7 +3679,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Destruction de la structure DSR (et de toutes ses valeurs) */ - if (!strcmp (MHH_Ptr->Name, HEAP_SYSTEM)) + if( !strcmp (MHH_Ptr->Name, HEAP_SYSTEM)) { NDT_Node * Node, * Previous_Node; SMT_DSH * DSH; @@ -3699,23 +3712,23 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Retrait du segment du DSR */ rc = ND_DataStruct_Value_Remove( MHH_Ptr->DSR, DSH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to remove the shared memory segment (address=%p) from the DSR structure", DSH->Start); SM_Error_Print (); - if (SM_ERROR(rc)) return rc; + if( SM_ERROR(rc)) return rc; } /* Destruction du segment */ rc = ND_Value_Free( MHH_Ptr->DSR, DSH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, " MHR_Manager NDD_CMD_VALUE_FREE: unable to free the shared memory segment (address=%p)", DSH->Start); SM_Error_Print (); - if (SM_ERROR(rc)) return rc; + if( SM_ERROR(rc)) return rc; } Node = Previous_Node; @@ -3724,7 +3737,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node else { rc = ND_DataStruct_Close (MHH_Ptr->DSR); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to destroy the DSR structure of heap \"%s\"", MHH_Ptr->Name); SM_Error_Print (); @@ -3740,14 +3753,14 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node */ rc = ND_Deallocator_Exec( MHH_Ptr->ACR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to free the ACR root of heap \"%s\"", MHH_Ptr->Name); SM_Error_Print (); } rc = ND_Deallocator_Exec( MHH_Ptr->FCR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to free the FCR root of heap \"%s\"", MHH_Ptr->Name); SM_Error_Print (); @@ -3762,7 +3775,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node { rc = ND_DataStruct_Value_Remove( Opened_Heap_List, Opened_Heap); - if (rc != NDS_OK) + if( rc != NDS_OK) { return( rc); } @@ -3784,7 +3797,7 @@ NDT_Status MHR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Désallocation de la structure du MHH */ rc = ND_Deallocator_Exec( MHH_Ptr, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "MHR_Manager NDD_CMD_VALUE_FREE : unable to free the header of heap \"%s\"", MHH_Ptr->Name); SM_Error_Print (); @@ -4041,7 +4054,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) /* Destruction de la structure DSR (et de toutes ses valeurs) */ - if (!strcmp (MHH->Name, HEAP_SYSTEM)) + if( !strcmp (MHH->Name, HEAP_SYSTEM)) { NDT_Node * Node, * Previous_Node; SMT_DSH * DSH; @@ -4074,23 +4087,23 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) /* Retrait du segment du DSR */ rc = ND_DataStruct_Value_Remove( MHH->DSR, DSH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to remove the shared memory segment (address=%p) from the DSR structure", DSH->Start); SM_Error_Print (); - if (SM_ERROR(rc)) return rc; + if( SM_ERROR(rc)) return rc; } /* Destruction du segment */ rc = ND_Value_Free( MHH->DSR, DSH); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to free the shared memory segment (address=%p)", DSH->Start); SM_Error_Print (); - if (SM_ERROR(rc)) return rc; + if( SM_ERROR(rc)) return rc; } Node = Previous_Node; @@ -4099,7 +4112,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) else { rc = ND_DataStruct_Close (MHH->DSR); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to destroy the DSR structure of heap \"%s\"", MHH->Name); SM_Error_Print (); @@ -4115,14 +4128,14 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) */ rc = ND_Deallocator_Exec( MHH->ACR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to free the ACR root of heap \"%s\"", MHH->Name); SM_Error_Print (); } rc = ND_Deallocator_Exec( MHH->FCR, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to free the FCR root of heap \"%s\"", MHH->Name); SM_Error_Print (); @@ -4137,7 +4150,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) { rc = ND_DataStruct_Value_Remove( Opened_Heap_List, Opened_Heap); - if (rc != NDS_OK) + if( rc != NDS_OK) { return( rc); } @@ -4159,7 +4172,7 @@ SMT_Status SM_MHH_End( SMT_MHH *MHH) /* Désallocation de la structure du MHH */ rc = ND_Deallocator_Exec( MHH, SM_Base->MHR->Deallocator_Name, SM_Base->MHR->Deallocator_Ptr, NULL); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to free the header of heap \"%s\"", MHH->Name); SM_Error_Print (); @@ -4272,13 +4285,13 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node Command_Name = "NDD_CMD_VALUE_ALLOC"; /* On vérifie que le heap n'atteint pas sa limite */ - if (MHH_Ptr->Limit_Size != SMD_UNLIMITED) + if( MHH_Ptr->Limit_Size != SMD_UNLIMITED) { size_t Current_Size; ND_DataStruct_Traverse (MHH_Ptr->DSR, NDD_CMD_VALUE_SUM, (void *)&Current_Size); - if (Current_Size + Segment_Size > MHH_Ptr->Limit_Size) + if( Current_Size + Segment_Size > MHH_Ptr->Limit_Size) { sprintf (SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : the heap limit size would be exceeded"); SM_Error_Print (); @@ -4300,7 +4313,7 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node } /* Création d'un segment de mémoire partagée */ - if (((*DSH_Ptr_Ptr)->MemId = shmget (IPC_PRIVATE, Segment_Size, 0777|IPC_CREAT|IPC_EXCL)) == -1) + if( ((*DSH_Ptr_Ptr)->MemId = shmget (IPC_PRIVATE, Segment_Size, 0777|IPC_CREAT|IPC_EXCL)) == -1) { switch (errno) { @@ -4336,7 +4349,7 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node #else (*DSH_Ptr_Ptr)->Start = shmat( (*DSH_Ptr_Ptr)->MemId, 0, 0); #endif - if (errno) + if( errno) { sprintf (SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : unable to attach the shared memory segment to the current process (error %d)", errno); SM_Error_Print (); @@ -4368,7 +4381,7 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Ajout du chunk libre à la liste des chunks libres du heap */ - if (ND_Index_Node_Add( MHH_Ptr->FCR, NDD_INDEX_PRIMARY, Chunk_Node) != NDS_OK) + if( ND_Index_Node_Add( MHH_Ptr->FCR, NDD_INDEX_PRIMARY, Chunk_Node) != NDS_OK) { sprintf (SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_ALLOC : unable to add a first chunk to the FCR structure of heap \"%s\"", MHH_Ptr->Name); SM_Error_Print (); @@ -4405,7 +4418,7 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Destruction du segment de mémoire partagée du segment de données */ - if (shmctl (DSH_Ptr->MemId, IPC_RMID, 0) == -1) + if( shmctl (DSH_Ptr->MemId, IPC_RMID, 0) == -1) { switch (errno) { @@ -4430,7 +4443,7 @@ NDT_Status SM_DSR_Manager( NDT_Root *Root_Ptr, NDT_Index_Id Index_Id, NDT_Node /* Désallocation de l'entête */ rc = ND_Deallocator_Exec( DSH_Ptr, Root_Ptr->Deallocator_Name, Root_Ptr->Deallocator_Ptr, NULL); - if (rc != NDS_OK) + if( rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_DSR_Manager NDD_CMD_VALUE_FREE : the data segment header is nul"); SM_Error_Print (); @@ -4658,7 +4671,7 @@ SMT_Status SM_DataSegment_Open ( SMT_DSH *DSH) errno = 0; Ptr = shmat( DSH->MemId, DSH->Start, 0); - if (errno) + if( errno) { sprintf (SM_Error_Msg, "SM_DataSegment_Open : unable to attach the shared memory segment at the specified address %p (error %d)", DSH->Start, errno); SM_Error_Print (); @@ -4712,15 +4725,15 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) while (Found == FALSE && Node) { - if (Node > (NDT_Node *)DSH_End) Node = NULL; + if( Node > (NDT_Node *)DSH_End) Node = NULL; else { - if (Node >= (NDT_Node *)(DSH->Start)) Found = TRUE; + if( Node >= (NDT_Node *)(DSH->Start)) Found = TRUE; else ND_Index_Node_Next_Get( &Node, Node); } } - if (!Node) return 0; + if( !Node) return 0; /* Parcours de tous les chunks libres du segment courant */ @@ -4734,7 +4747,7 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) /* Si le chunk suivant est "collé" au chunk courant, alors on les fusionne */ - if (Next_Node == (NDT_Node *)((size_t)(Chunk->Data) + Chunk->Size)) + if( Next_Node == (NDT_Node *)((size_t)(Chunk->Data) + Chunk->Size)) { ND_Index_Node_Remove (Next_Node); @@ -5370,10 +5383,10 @@ SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; - if (Lock_Mode & SMD_READ) + if( Lock_Mode & SMD_READ) { rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SSL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Set : unable to lock the heap for reading"); SM_Error_Print (); @@ -5382,10 +5395,10 @@ SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) } } - if (Lock_Mode & SMD_WRITE) + if( Lock_Mode & SMD_WRITE) { rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SEL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Set : unable to lock the heap for writing"); SM_Error_Print (); @@ -5409,7 +5422,7 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; - if (Lock_Mode & SMD_WRITE) + if( Lock_Mode & SMD_WRITE) { /* Attention : il ne faut pas tenter de transformer directement un verrou en lecture en @@ -5419,7 +5432,7 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) => On passe donc par un déverrouillage intermédiaire. */ - if ((rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_RSL, 2)) != SMS_OK) + if( (rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_RSL, 2)) != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Change : unable to transform the heap lock for writing"); SM_Error_Print (); @@ -5427,7 +5440,7 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) return rc; } - if ((rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SEL, 2)) != SMS_OK) + if( (rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_SEL, 2)) != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Change : unable to transform the heap lock for writing"); SM_Error_Print (); @@ -5439,10 +5452,10 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) return rc; } } - else if (Lock_Mode & SMD_READ) + else if( Lock_Mode & SMD_READ) { rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_TSL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Change : unable to transform the heap lock for reading"); SM_Error_Print (); @@ -5466,10 +5479,10 @@ SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; - if (Lock_Mode & SMD_READ) + if( Lock_Mode & SMD_READ) { rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_RSL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Release : unable to unlock the heap which had been locked for reading"); SM_Error_Print (); @@ -5478,10 +5491,10 @@ SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) } } - if (Lock_Mode & SMD_WRITE) + if( Lock_Mode & SMD_WRITE) { rc = SM_Semaphore_Operate (MHH->SemId, SM_SemOp_REL, 2); - if (rc != SMS_OK) + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Lock_Release : unable to unlock the heap which had been locked for writing"); SM_Error_Print (); @@ -5503,7 +5516,7 @@ SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) SMT_Status SM_Semaphore_Operate (int SemId, struct sembuf * Operations, unsigned int Nb_Oper) { - if (semop (SemId, Operations, Nb_Oper) == -1) + if( semop (SemId, Operations, Nb_Oper) == -1) { switch (errno) { @@ -5630,7 +5643,7 @@ char *SM_Lock_Status_Get( const char *Type_Name, void *Struct_Ptr) void SM_Error_Print ( void ) { - if (SM_stderr) fprintf (SM_stderr, "Error %s\n", SM_Error_Msg); + if( SM_stderr) fprintf (SM_stderr, "Error %s\n", SM_Error_Msg); } @@ -5638,17 +5651,22 @@ void SM_Error_Print ( void ) /*------------------------------------------------------------------------------*/ -/* Pour préfixer un nom de heap avec le nom du contexte d'utilisation */ +/* Add context prefix to heap name */ +/*------------------------------------------------------------------------------*/ +/* (O) Prefixed: Prefixed heap name */ +/* (I) Unprefixed: Unprefixed heap name */ /*------------------------------------------------------------------------------*/ -static char * SM_Name_Prefix ( const char * Name) +SMT_Status SM_Name_Prefix( char *Prefixed, const char *Unprefixed) { - static char Prefixed [256]; - - if (!SM_Context || !strlen (SM_Context) || !strcmp (Name, HEAP_SYSTEM)) - strcpy (Prefixed, Name); + if( !SM_Context || !strlen( SM_Context) || !strcmp( Unprefixed, HEAP_SYSTEM)) + { + strcpy( Prefixed, Unprefixed); + } else - sprintf (Prefixed, "%s/%s", SM_Context, Name); + { + snprintf( Prefixed, SMD_NAME_LEN, "%s/%s", SM_Context, Unprefixed); + } - return Prefixed; + return( SMS_OK); } diff --git a/lib/libshmem.h b/lib/libshmem.h index 2a373cb..cccb067 100644 --- a/lib/libshmem.h +++ b/lib/libshmem.h @@ -289,7 +289,13 @@ char * SM_Lock_Status_Get (const char *, void *); /*------------------------------------------------------------------------------*/ void SM_Error_Print (void); + + /*------------------------------------------------------------------------------*/ -/* Pour préfixer un nom de heap avec le nom de l'instance utilisée */ +/* Add context prefix to heap name */ /*------------------------------------------------------------------------------*/ -static char * SM_Name_Prefix (const char *); +/* (O) Prefixed: Prefixed heap name */ +/* (I) Unprefixed: Unprefixed heap name */ +/*------------------------------------------------------------------------------*/ + +SMT_Status SM_Name_Prefix( char *, const char *);