From bb73fb28cce6bd803554ab25d3c3099b16cf4d78 Mon Sep 17 00:00:00 2001 From: agibert Date: Mon, 24 Jan 2005 22:57:06 +0000 Subject: [PATCH] Initial support for LibNode 2.1.x. Not working version... Update revision number to 2.0 ! --- include/shmem.h | 201 ++++--- lib/libshmem.c | 1418 ++++++++++++++++++++++++++++++----------------- lib/libshmem.h | 78 ++- 3 files changed, 1099 insertions(+), 598 deletions(-) diff --git a/include/shmem.h b/include/shmem.h index 131d1f9..d6037a1 100644 --- a/include/shmem.h +++ b/include/shmem.h @@ -1,3 +1,34 @@ +/*---------------------------------------------------------------------------------*/ +/* $RCSfile: shmem.h,v $ */ +/*---------------------------------------------------------------------------------*/ +/* $Revision: 2.0 $ */ +/* $Name: $ */ +/* $Date: 2005/01/24 22:57:06 $ */ +/* $Author: agibert $ */ +/*---------------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------------*/ +/* This file is part of LibShMem */ +/* */ +/* LibShMem is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU Lesser General Public Licence as published by */ +/* the Free Software Foundation; either version 2.1 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* LibShMem is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License */ +/* along with LibShMem; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/*---------------------------------------------------------------------------------*/ + + + + + #ifndef _LIBSM #define _LIBSM @@ -11,7 +42,7 @@ extern "C" { /* 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 */ @@ -28,7 +59,7 @@ typedef long SMT_Status; #define SM_ERROR(s) ((s) < 0) /* Tous les codes retour négatifs correspondent à des erreurs */ -typedef int SMT_Flags; + typedef int SMT_Flags; #define SMD_UNDEF 0 @@ -59,12 +90,12 @@ typedef int SMT_Flags; /* 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 */ #define SMD_AUTO_COMPRESS 3 /* Définir la taille d'un FCR à partir de laquelle - la compression du heap est autmatiquement activée */ + la compression du heap est autmatiquement activée */ #define SMD_DEFAULT_COMPRESS 1000 /* si + de 1000 chunks libres, alors compression du heap */ @@ -85,7 +116,7 @@ typedef int SMT_Config; #define TRUE 1 #endif -char SM_Error_Msg [512]; + char SM_Error_Msg [512]; #ifndef SM_MODE #define SM_MODE 0 @@ -143,70 +174,70 @@ char SM_Error_Msg [512]; /* 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; + 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 */ -SMT_Base * SM_Base; + SMT_Base * SM_Base; /*------------------------------------------------------------------------------*/ /* 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é */ -} SMT_MHH; + 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é */ + } 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; + 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; + 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; + 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 */ @@ -215,68 +246,68 @@ typedef struct { /* (I) Context : nom du nouveau contexte */ /* (I) Flags : indicateur création/ouverture + mode d'affichage des erreurs */ /*------------------------------------------------------------------------------*/ -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 ); + 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 */ /*------------------------------------------------------------------------------*/ /* (O) Instance : adresse du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Instance_Get_I ( int * Instance); -SMT_Status SM_Library_Instance_Get_C ( int * Instance); + 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 */ /*------------------------------------------------------------------------------*/ /* (I) Context : nom du nouveau contexte */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Context_Set_I ( const char * Context ); -SMT_Status SM_Library_Context_Set_C ( const char * Context ); + 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é */ /*------------------------------------------------------------------------------*/ /* (O) Context : adresse du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Context_Get_I ( char ** Context ); -SMT_Status SM_Library_Context_Get_C ( char ** Context ); + 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 */ /*------------------------------------------------------------------------------*/ /* (I) Flags : mode de fermeture (destruction ou fermeture simple) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Close_I ( SMT_Flags Flags ); -SMT_Status SM_Library_Close_C ( SMT_Flags Flags ); + 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 */ /*------------------------------------------------------------------------------*/ /* (I) Out : pointeur sur le flux de sortie */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Dump_I ( FILE * Out ); -SMT_Status SM_Library_Dump_C ( FILE * Out ); + 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 ); + 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 ); + SMT_Status SM_Library_Stderr_Set_I ( FILE * Out ); + SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ); /*------------------------------------------------------------------------------*/ /* Test d'existence d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : nom du heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Exist_I ( const char * Heap_Name ); -SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ); + 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 */ @@ -287,8 +318,8 @@ SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ); /* (I) Flags : mode d'ouverture du heap */ /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -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 ); + 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 */ @@ -296,24 +327,24 @@ SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* (I) Heap_Name : nom du heap */ /* (O) Heap : adresse du pointeur sur le heap ouvert */ /*------------------------------------------------------------------------------*/ -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 ); + 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 */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap ); -SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ); + SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap ); + SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ); /*------------------------------------------------------------------------------*/ /* Destruction d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : nom du heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_End_I ( const char * Heap_Name ); -SMT_Status SM_Heap_End_C ( const char * Heap_Name ); + SMT_Status SM_Heap_End_I ( const char * Heap_Name ); + SMT_Status SM_Heap_End_C ( const char * Heap_Name ); /*------------------------------------------------------------------------------*/ /* Compression d'un heap */ @@ -321,8 +352,8 @@ SMT_Status SM_Heap_End_C ( const char * Heap_Name ); /* (I) Heap : pointeur sur un heap ouvert */ /* (O) Compress : pointeur sur la taille mémoire gagnée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress ); -SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ); + 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 */ @@ -330,8 +361,8 @@ SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ); /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Tag : type de configuration */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ); -SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ); + 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 : */ @@ -341,8 +372,8 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ); /* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */ /* (I) Out : pointeur sur le flux de sortie du rapport */ /*------------------------------------------------------------------------------*/ -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); + 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 */ @@ -351,16 +382,16 @@ SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* (I) Flags : mode de verrouillage (SMD_READ ou SMD_WRITE) */ /* (O) Locked : verrouillage effectué (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -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 ); + 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 */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap ); -SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ); + 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 */ @@ -369,8 +400,8 @@ SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ); /* (I) Size : taille du chunk */ /* (O) Ptr : pointeur sur la zone de données allouée */ /*------------------------------------------------------------------------------*/ -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 ); + 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 */ @@ -378,8 +409,8 @@ SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ); /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Ptr : adresse de la zone de données du chunk à désallouer */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr ); -SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr ); + SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr ); + SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr ); #ifdef __cplusplus } diff --git a/lib/libshmem.c b/lib/libshmem.c index 5250e2d..aae67e5 100644 --- a/lib/libshmem.c +++ b/lib/libshmem.c @@ -1,10 +1,43 @@ -/* Utilisation des API de la LIBNODE sans vérification des arguments */ +/*---------------------------------------------------------------------------------*/ +/* $RCSfile: libshmem.c,v $ */ +/*---------------------------------------------------------------------------------*/ +/* $Revision: 2.0 $ */ +/* $Name: $ */ +/* $Date: 2005/01/24 22:57:06 $ */ +/* $Author: agibert $ */ +/*---------------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------------*/ +/* This file is part of LibShMem */ +/* */ +/* LibShMem is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU Lesser General Public Licence as published by */ +/* the Free Software Foundation; either version 2.1 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* LibShMem is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License */ +/* along with LibShMem; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/*---------------------------------------------------------------------------------*/ + + + + + +#define _LIBSHMEM_C_ + -#define ND_MODE 1 #include -VER_INFO_EXPORT(libshmem,"$Revision: 1.1 $", "$Name: $",__FILE__,"$Author: smas $") +#ifdef _LIBVER_SUPPORT +VER_INFO_EXPORT(libshmem,"$Revision: 2.0 $", "$Name: $",__FILE__,"$Author: agibert $") +#endif /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ @@ -23,115 +56,119 @@ VER_INFO_EXPORT(libshmem,"$Revision: 1.1 $", "$Name: $",__FILE__,"$Author: smas /* (I) Context : nom du nouveau contexte */ /* (I) Open_Mode : indicateur création/ouverture + mode d'affichage des erreurs */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Open_I ( int Instance, const char * Context, SMT_Flags Open_Mode ) + + SMT_Status SM_Library_Open_I( int Instance, const char *Context, SMT_Flags Open_Mode) { - SMT_Status rc; - int ND_Debug = FALSE; - int To_Open_Instance; + SMT_Status rc; + int ND_Debug = FALSE; + int To_Open_Instance; + NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_TREE | NDD_INDEX_SUBTYPE_BALANCED); + /* Définition du mode d'affichage des messages d'erreur */ - if (SMD_DEBUG_MSK(Open_Mode)) SM_stderr = stderr; - if (Open_Mode & SMD_DEBUG_ALL) ND_Debug = TRUE; + if( SMD_DEBUG_MSK( Open_Mode)) SM_stderr = stderr; + if( Open_Mode & SMD_DEBUG_ALL) ND_Debug = TRUE; + /* Définition de l'instance à ouvrir */ - if (Instance) To_Open_Instance = Instance; + if( Instance) To_Open_Instance = Instance; else { - if (!getenv (INSTANCE_ENV_VAR) || (To_Open_Instance = atoi (getenv (INSTANCE_ENV_VAR))) <= 0) + if( !getenv( INSTANCE_ENV_VAR) || ( To_Open_Instance = atoi ( getenv( INSTANCE_ENV_VAR))) <= 0) + { To_Open_Instance = DEFAULT_INSTANCE; + } } - if (Open_Mode & SMD_CREATE) /* Création d'une nouvelle instance */ + if( Open_Mode & SMD_CREATE) /* Création d'une nouvelle instance */ { /* On vérifie que le processus courant n'accède pas déjà à une instance */ - if (SM_Open_Counter > 0) + if( SM_Open_Counter > 0) { - sprintf (SM_Error_Msg, "SM_Library_Open : the current process has already opened an instance (%d) of the LIBSHMEM base", SM_Instance); - SM_Error_Print (); - return SMS_ERRAPI; + sprintf( SM_Error_Msg, "SM_Library_Open : the current process has already opened an instance (%d) of the LIBSHMEM base", SM_Instance); + SM_Error_Print(); + return( SMS_ERRAPI); } /* Ouverture de la librairie LIBNODE */ - rc = ND_Library_Open (ND_Debug); - if (rc != SMS_OK) + rc = ND_Library_Open( ND_Debug); + if( rc != SMS_OK) { - sprintf (SM_Error_Msg, "SM_Library_Open : unable to open the LIBNODE library"); - SM_Error_Print (); - return rc; + sprintf( SM_Error_Msg, "SM_Library_Open : unable to open the LIBNODE library"); + SM_Error_Print(); + return( rc); } /* Ouverture de la liste des heaps ouverts (locale) */ - rc = ND_DataStruct_Open (&Opened_Heap_List, NDD_DS_TREE | NDD_MN_AUTO_EQU, NULL, NULL, NULL, TRUE); + 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) { - sprintf (SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); + SM_Error_Print(); goto Error1; } - else strcpy (Opened_Heap_List->Manager, "SM_Opened_Heap_List_Manager"); /* Création de la base de mémoire partagée */ SM_Instance = To_Open_Instance; - rc = SM_Base_Init (); - if (rc != SMS_OK ) + rc = SM_Base_Init(); + if( rc != SMS_OK ) { - sprintf (SM_Error_Msg, "SM_Library_Open : unable to initialize the shared memory base"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Library_Open : unable to initialize the shared memory base"); + SM_Error_Print(); goto Error2; } } - else if (Open_Mode & SMD_OPEN) /* Ouverture d'une instance existante */ + else if( Open_Mode & SMD_OPEN) /* Ouverture d'une instance existante */ { /* On vérifie que le processus courant n'a pas déjà ouvert une autre instance */ - if (SM_Open_Counter > 0 && To_Open_Instance != SM_Instance) + if( SM_Open_Counter > 0 && To_Open_Instance != SM_Instance) { - sprintf (SM_Error_Msg, "SM_Library_Open : the current process cannot open instance %d because it is already accessing instance %d", To_Open_Instance, SM_Instance); + sprintf( SM_Error_Msg, "SM_Library_Open : the current process cannot open instance %d because it is already accessing instance %d", To_Open_Instance, SM_Instance); SM_Error_Print (); - return SMS_ERRAPI; + return( SMS_ERRAPI); } SM_Instance = To_Open_Instance; /* Ouverture effective si c'est la première fois */ - if (SM_Open_Counter == 0) + if( SM_Open_Counter == 0) { /* Ouverture de la librairie LIBNODE */ - rc = ND_Library_Open (ND_Debug); - if (rc != SMS_OK) + rc = ND_Library_Open( ND_Debug); + if( rc != SMS_OK) { - sprintf (SM_Error_Msg, "SM_Library_Open : unable to open the LIBNODE library"); - SM_Error_Print (); - return rc; + sprintf( SM_Error_Msg, "SM_Library_Open : unable to open the LIBNODE library"); + SM_Error_Print(); + return( rc); } /* Ouverture de la liste des heaps ouverts (locale) */ - rc = ND_DataStruct_Open (&Opened_Heap_List, NDD_DS_TREE | NDD_MN_AUTO_EQU, NULL, NULL, NULL, TRUE); - if (rc != NDS_OK) + 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) { - sprintf (SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Library_Open : unable to create the local opened heap cache"); + SM_Error_Print(); goto Error1; } - else strcpy (Opened_Heap_List->Manager, "SM_Opened_Heap_List_Manager"); /* Ouverture de la base de mémoire partagée */ - rc = SM_Base_Open (); - if (rc != SMS_OK ) + rc = SM_Base_Open(); + if( rc != SMS_OK ) { - sprintf (SM_Error_Msg, "SM_Library_Open : unable to open the shared memory base"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Library_Open : unable to open the shared memory base"); + SM_Error_Print(); goto Error2; } } @@ -139,140 +176,167 @@ SMT_Status SM_Library_Open_I ( int Instance, const char * Context, SMT_Flags Ope /* Définition du contexte */ - SM_Library_Context_Set_I (Context); + SM_Library_Context_Set_I( Context); /* On incrémente le compteur d'ouverture de la librairie */ SM_Open_Counter++; - return SMS_OK; + return( SMS_OK); /* Gestion d'erreur */ - Error2: - ND_DataStruct_Close (Opened_Heap_List); - Error1: - ND_Library_Close (); + Error2: + ND_DataStruct_Close( Opened_Heap_List); - return rc; + Error1: + ND_Library_Close(); + + return( rc); } + + + + /*------------------------------------------------------------------------------*/ /* Récupération du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ /* (O) Instance : adresse du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Instance_Get_I ( int * Instance ) + +SMT_Status SM_Library_Instance_Get_I( int *Instance) { *Instance = SM_Instance; - return SMS_OK; + return( SMS_OK); } + + /*------------------------------------------------------------------------------*/ /* Récupération du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ /* (O) Context : adresse du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Context_Get_I ( char ** Context ) + +SMT_Status SM_Library_Context_Get_I ( char **Context) { *Context = SM_Context; - return SMS_OK; + return( SMS_OK); } + + + + /*------------------------------------------------------------------------------*/ /* Changement de contexte d'utilisation de la librairie */ /*------------------------------------------------------------------------------*/ /* (I) Context : nom du nouveau contexte */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Context_Set_I ( const char * Context ) -{ - if (SM_Context) free (SM_Context); - if (Context && strlen (Context)) SM_Context = strdup (Context); +SMT_Status SM_Library_Context_Set_I( const char *Context ) +{ + if( SM_Context) free( SM_Context); + + if( Context && strlen( Context)) + { + SM_Context = strdup( Context); + } else { - if (getenv (CONTEXT_ENV_VAR) && strlen (getenv (CONTEXT_ENV_VAR))) + if( getenv( CONTEXT_ENV_VAR) && strlen ( getenv( CONTEXT_ENV_VAR))) + { SM_Context = strdup (getenv (CONTEXT_ENV_VAR)); + } else + { SM_Context = strdup (DEFAULT_CONTEXT); + } } - return SMS_OK; + return( SMS_OK); } + + + + /*------------------------------------------------------------------------------*/ /* Fermeture de l'instance de la librairie */ /*------------------------------------------------------------------------------*/ /* (I) Close_Mode : mode de fermeture (destruction ou fermeture simple) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Close_I ( SMT_Flags Close_Mode ) -{ - SMT_Status rc; - if (Close_Mode & SMD_DESTROY) /* Destruction de l'instance */ +SMT_Status SM_Library_Close_I( SMT_Flags Close_Mode) +{ + SMT_Status rc; + + + if( Close_Mode & SMD_DESTROY) /* Destruction de l'instance */ { /* Destruction de la base de mémoire partagée */ - rc = SM_Base_End (); - if (rc != SMS_OK) + rc = SM_Base_End(); + if( rc != SMS_OK) { - sprintf (SM_Error_Msg, "SM_Library_Close: unable to destroy the shared memory base"); - SM_Error_Print (); - return rc; + sprintf( SM_Error_Msg, "SM_Library_Close: unable to destroy the shared memory base"); + SM_Error_Print(); + return( rc); } - if (SM_Context) + if( SM_Context) { - free (SM_Context); + free( SM_Context); SM_Context = NULL; } /* Fermeture de la liste des heaps ouverts */ - ND_DataStruct_Close (Opened_Heap_List); + ND_DataStruct_Close( Opened_Heap_List); /* Fermeture de la librairie LIBNODE */ - ND_Library_Close (); + ND_Library_Close(); /* Réinitialisation du compteur d'ouverture */ SM_Open_Counter = 0; } - else if (Close_Mode & SMD_CLOSE) /* Fermeture de l'instance */ + else if( Close_Mode & SMD_CLOSE) /* Fermeture de l'instance */ { /* - La fermeture n'est effective que si la librairie - n'a été ouverte qu'une seule fois. + La fermeture n'est effective que si la librairie + n'a été ouverte qu'une seule fois. */ - if (SM_Open_Counter == 1) + if( SM_Open_Counter == 1) { /* Fermeture de la base de mémoire partagée */ - rc = SM_Base_Close (); - if (rc != SMS_OK) + rc = SM_Base_Close(); + if( rc != SMS_OK) { - sprintf (SM_Error_Msg, "SM_Library_Close : unable to close the shared memory base"); - SM_Error_Print (); - return rc; + sprintf( SM_Error_Msg, "SM_Library_Close : unable to close the shared memory base"); + SM_Error_Print(); + return( rc); } - if (SM_Context) + if( SM_Context) { - free (SM_Context); + free( SM_Context); SM_Context = NULL; } /* Fermeture de la liste des heaps ouverts */ - ND_DataStruct_Close (Opened_Heap_List); + ND_DataStruct_Close( Opened_Heap_List); /* Fermeture de la librairie LIBNODE */ - ND_Library_Close (); + ND_Library_Close(); } /* On met à jour le compteur d'ouverture de la librairie */ @@ -280,125 +344,161 @@ SMT_Status SM_Library_Close_I ( SMT_Flags Close_Mode ) SM_Open_Counter--; } - return SMS_OK; + return( SMS_OK); } + + + + /*------------------------------------------------------------------------------*/ /* Affichage des informations de la base de mémoires partagées */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Dump_I (FILE * Out) + +SMT_Status SM_Library_Dump_I( FILE *Out) { /* Affichage des informations sur la base */ - fprintf (Out, "Base [%d/%s] :\n\t- Size = %d bytes\n\t- Creator pid = %ld\n\t- Last write access pid = %ld\n\t- ID Mem = %d (+%d)\n\t- ID Sem = %d\n\t- Status = %s\n\n", - SM_Instance, SM_Context, SM_Base->Size, SM_Base->Creator, SM_Base->Writer, SM_Base->SysMemID, SM_Base->DataMemID, SM_Base->SemID, SM_Lock_Status_Get ("base", SM_Base)); + fprintf( Out, "Base [%d/%s] :\n\t- Size = %d bytes\n\t- Creator pid = %ld\n\t- Last write access pid = %ld\n\t- ID Mem = %d (+%d)\n\t- ID Sem = %d\n\t- Status = %s\n\n", + SM_Instance, SM_Context, SM_Base->Size, SM_Base->Creator, SM_Base->Writer, SM_Base->SysMemID, SM_Base->DataMemID, SM_Base->SemID, SM_Lock_Status_Get( "base", SM_Base)); /* Affichage des informations du MHR */ - ND_DataStruct_Info_Print (SM_Base->MHR, Out); - fprintf (Out, "\n"); + ND_DataStruct_Info_Print( Out, SM_Base->MHR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0); + fprintf( Out, "\n"); /* Affichage des informations de chaque heap */ - return ND_DataStruct_Print (SM_Base->MHR, Out); + return( ND_DataStruct_Print( Out, SM_Base->MHR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0)); } + + + + /*------------------------------------------------------------------------------*/ /* Libération de tous les verrous (base, heap) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Library_Unlock_I ( void ) + +SMT_Status SM_Library_Unlock_I( void) { - NDT_Node * Node; - union semun Sem_Ctl; + NDT_Node *Node; + union semun Sem_Ctl; + /* Libération des verrous sur la base */ Sem_Ctl.val = 1; - if (semctl (SM_Base->SemID, 0, SETVAL, Sem_Ctl)) + if( semctl( SM_Base->SemID, 0, SETVAL, Sem_Ctl)) { - sprintf (SM_Error_Msg, "SM_Library_Free : unable to unlock the shared memory base"); - SM_Error_Print (); - return SMS_ERRSEM; + sprintf( SM_Error_Msg, "SM_Library_Free : unable to unlock the shared memory base"); + SM_Error_Print(); + + return( SMS_ERRSEM); } /* Libération des verrous sur les heaps */ - ND_Node_First_Get (SM_Base->MHR, &Node); + ND_Node_First_Get( SM_Base->MHR, &Node); - while (Node) + while( Node) { - SMT_MHH * MHH; + SMT_MHH *MHH; - MHH = (SMT_MHH *)(Node->Value); + MHH = (SMT_MHH *)( Node->Value); - if (semctl (MHH->SemID, 0, SETVAL, Sem_Ctl)) + if( semctl( MHH->SemID, 0, SETVAL, Sem_Ctl)) { - sprintf (SM_Error_Msg, "SM_Library_Free : unable to unlock heap \"%s\"", MHH->Name); - SM_Error_Print (); - return SMS_ERRSEM; + sprintf( SM_Error_Msg, "SM_Library_Free : unable to unlock heap \"%s\"", MHH->Name); + SM_Error_Print(); + return( SMS_ERRSEM); } - ND_Node_Next_Get (Node, &Node); + ND_Node_Next_Get( Node, &Node); } - ND_Node_First_Get (Opened_Heap_List, &Node); + ND_Node_First_Get( Opened_Heap_List, &Node); - while (Node) + while( Node) { - ((SMT_Heap *)(Node->Value))->Lock_Mode = SMD_NO_LOCK; - ND_Node_Next_Get (Node, &Node); + ( (SMT_Heap *)(Node->Value))->Lock_Mode = SMD_NO_LOCK; + ND_Node_Next_Get( Node, &Node); } - return SMS_OK; + return( SMS_OK); } + + + + /*------------------------------------------------------------------------------*/ /* 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_I ( FILE *Out) { SM_stderr = Out; - return SMS_OK; + return( SMS_OK); } + + + + /*------------------------------------------------------------------------------*/ /* Test d'existence d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : Nom du heap */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Exist_I ( const char * Heap_Name ) -{ - NDT_Node * Node; - SMT_MHH * MHH; - char * Prefixed_Name = SM_Name_Prefix (Heap_Name); - int Locked = FALSE; - if (strcmp (Heap_Name, HEAP_SYSTEM)) +SMT_Status SM_Heap_Exist_I ( const char *Heap_Name) +{ + NDT_Node *Node; + SMT_MHH *MHH; + char *Prefixed_Name = SM_Name_Prefix( Heap_Name); + int Locked = FALSE; + + + if( strcmp( Heap_Name, HEAP_SYSTEM)) { /* Verrouillage du heap système en lecture */ - SM_Heap_Lock_I (System_Heap, SMD_READ, &Locked); + SM_Heap_Lock_I( System_Heap, SMD_READ, &Locked); } /* Recherche dans le MHR */ - ND_Node_First_Get (SM_Base->MHR, &Node); - while (Node) + ND_Node_First_Get( SM_Base->MHR, &Node); + + while( Node) { - MHH = (SMT_MHH *)(Node->Value); - if (!strcmp (Prefixed_Name, MHH->Name)) return SMS_YES; - ND_Node_Next_Get (Node, &Node); + MHH = (SMT_MHH *)( Node->Value); + + if (!strcmp( Prefixed_Name, MHH->Name)) + { + return( SMS_YES); + } + + ND_Node_Next_Get( Node, &Node); } /* Déverrouillage éventuel du heap système */ - if (Locked == TRUE) SM_Heap_Unlock_I (System_Heap); + if( Locked == TRUE) + { + SM_Heap_Unlock_I( System_Heap); + } - return SMS_NO; + return( SMS_NO); } + + + + /*------------------------------------------------------------------------------*/ /* Ouverture/création d'un heap */ /*------------------------------------------------------------------------------*/ @@ -408,83 +508,89 @@ SMT_Status SM_Heap_Exist_I ( const char * Heap_Name ) /* (I) Open_Mode : mode d'ouverture du heap */ /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ -SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg_Size, SMT_Flags Open_Mode, int * Locked ) + +SMT_Status SM_Heap_Open_I( const char *Heap_Name, SMT_Heap **Heap, size_t Seg_Size, SMT_Flags Open_Mode, int *Locked) { - SMT_MHH * MHH; - NDT_Node * Node; - SMT_DSH * New_DSH; - char * Prefixed_Name; - union semun Sem_Ctl; - int SemID; - SMT_Status rc; + SMT_MHH *MHH; + NDT_Node *Node; + SMT_DSH *New_DSH; + char *Prefixed_Name; + union semun Sem_Ctl; + int SemID; + SMT_Status rc; + NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO); + *Locked = FALSE; /* On regarde si le heap est déjà ouvert par le processus courant */ - if (SM_Heap_IsOpen_I (Heap_Name, Heap) == SMS_YES) + if( SM_Heap_IsOpen_I( Heap_Name, Heap) == SMS_YES) { - if (Open_Mode & SMD_OPEN) + if( Open_Mode & SMD_OPEN) { /* Verrouillage du heap dans le mode demandé */ - rc = SM_Heap_Lock_I (*Heap, SMD_LOCK_MSK(Open_Mode), Locked); + rc = SM_Heap_Lock_I( *Heap, SMD_LOCK_MSK( Open_Mode), Locked); 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 (); + 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(); - return rc; + return( rc); } - return SMS_OK; + return( SMS_OK); } else { - sprintf (SM_Error_Msg, "SM_Heap_Open : the heap already exists but (Flags & SMD_OPEN) is false"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : the heap already exists but (Flags & SMD_OPEN) is false"); + SM_Error_Print(); - return SMS_ERRAPI; + return( SMS_ERRAPI); } } - Prefixed_Name = SM_Name_Prefix (Heap_Name); + Prefixed_Name = SM_Name_Prefix( Heap_Name); /* On regarde si le heap existe déjà dans la base */ - if (SM_Heap_Exist_I (Heap_Name) == SMS_YES) + if( SM_Heap_Exist_I( Heap_Name) == SMS_YES) { - if (Open_Mode & SMD_OPEN) + if( Open_Mode & SMD_OPEN) { + SMT_MHH To_Find; + + /* Ouverture d'un heap existant */ - SMT_MHH To_Find; + strcpy( To_Find.Name, Prefixed_Name); + ND_Node_Find( SM_Base->MHR, &Node, &To_Find, NULL); - strcpy (To_Find.Name, Prefixed_Name); - ND_Node_Find (SM_Base->MHR, &Node, &To_Find, NULL); + MHH = (SMT_MHH *)( Node->Value); - MHH = (SMT_MHH *)(Node->Value); - - *Heap = (SMT_Heap *) malloc (sizeof (SMT_Heap)); - if (!*Heap) + *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); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the opened heap \"%s\"", Prefixed_Name); + SM_Error_Print(); - return SMS_ERRMEM; + return( SMS_ERRMEM); } - (*Heap)->Name = strdup (Prefixed_Name); - (*Heap)->MHH = MHH; - (*Heap)->Lock_Mode = SMD_NO_LOCK; + ( *Heap)->Name = strdup( Prefixed_Name); + ( *Heap)->MHH = MHH; + ( *Heap)->Lock_Mode = SMD_NO_LOCK; /* On ouvre tous les segments du heap */ - ND_Node_First_Get ((*Heap)->MHH->DSR, &Node); - while (Node) + ND_Node_First_Get( ( *Heap)->MHH->DSR, &Node); + + while( Node) { - rc = SM_DataSegment_Open (Node->Value); - if (rc != SMS_OK) + rc = SM_DataSegment_Open( Node->Value); + + if( rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_Heap_Open : unable to open one of the data segments of heap \"%s\"", Prefixed_Name); SM_Error_Print (); @@ -492,18 +598,19 @@ SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg goto Error1; } - ND_Node_Next_Get (Node, &Node); + ND_Node_Next_Get( Node, &Node); } - (*Heap)->Nb_Seg = (*Heap)->MHH->DSR->Node_Number; + (*Heap)->Nb_Seg = (*Heap)->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; /* Verrouillage du heap dans le mode demandé */ - rc = SM_Heap_Lock_I (*Heap, SMD_LOCK_MSK(Open_Mode), Locked); - if (rc != SMS_OK) + rc = SM_Heap_Lock_I( *Heap, SMD_LOCK_MSK( Open_Mode), Locked); + + 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"); - SM_Error_Print (); + 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; } @@ -511,66 +618,73 @@ SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* Ajout au cache des heaps ouverts */ rc = ND_Value_Add (Opened_Heap_List, *Heap); - if (rc != NDS_OK) + + if( rc != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", Prefixed_Name); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", Prefixed_Name); + SM_Error_Print(); goto Error2; } - return SMS_OK; + return( SMS_OK); } else { - sprintf (SM_Error_Msg, "SM_Heap_Open : the heap already exists but (Open_Mode & SMD_OPEN) is false"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : the heap already exists but (Open_Mode & SMD_OPEN) is false"); + SM_Error_Print(); - return SMS_ERRAPI; + return( SMS_ERRAPI); } } - if (!(Open_Mode & SMD_CREATE)) + 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); - SM_Error_Print (); + 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; + return( SMS_ERRAPI); } /* Création du sémaphore pour gérer les verrous sur le nouveau MHH */ - SemID = semget (IPC_PRIVATE, 1, 0777|IPC_CREAT|IPC_EXCL); - if (SemID == -1) + SemID = semget( IPC_PRIVATE, 1, 0777 | IPC_CREAT | IPC_EXCL); + if( SemID == -1) { - switch (errno) + switch( errno) { case ENOMEM: - sprintf (SM_Error_Msg, "SM_Heap_Open : the amount of memory is not sufficient to create a new semaphore"); + { + sprintf( SM_Error_Msg, "SM_Heap_Open : the amount of memory is not sufficient to create a new semaphore"); break; + } case ENOSPC: - sprintf (SM_Error_Msg, "SM_Heap_Open : the number of semaphores exceeds the system-imposed limit"); + { + sprintf( SM_Error_Msg, "SM_Heap_Open : the number of semaphores exceeds the system-imposed limit"); break; + } default : - sprintf (SM_Error_Msg, "SM_Heap_Open : unknown error (%d) while creating a semaphore", errno); + { + sprintf( SM_Error_Msg, "SM_Heap_Open : unknown error (%d) while creating a semaphore", errno); break; + } } - SM_Error_Print (); + SM_Error_Print(); - return SMS_ERRSEM; + return( SMS_ERRSEM); } /* Initialisation du sémaphore à 1 (équivaut à aucun verrou posé) */ Sem_Ctl.val = 1; - if (semctl (SemID, 0, SETVAL, Sem_Ctl)) + if( semctl( SemID, 0, SETVAL, Sem_Ctl)) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to initialize the value of the semaphore %d", SemID); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to initialize the value of the semaphore %d", SemID); + SM_Error_Print(); rc = SMS_ERRSEM; goto Error3; @@ -578,10 +692,10 @@ SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* Réservation du MHH (dans la base pour le heap système, dans le heap système pour les autres heaps) */ - if (ND_Allocator_Exec (SM_Base->MHR->Allocator, (void **)(&MHH), sizeof (SMT_MHH), NULL) != NDS_OK) + if( ND_Allocator_Exec( SM_Base->MHR->Allocator_Ptr, (void **)(&MHH), sizeof( SMT_MHH), NULL) != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the heap header"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to allocate memory for the heap header"); + SM_Error_Print(); rc = SMS_ERRSHM; goto Error3; @@ -589,82 +703,81 @@ SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* Initialisation de la structure du nouveau MHH */ - strcpy (MHH->Name, Prefixed_Name); - MHH->Writer = getpid (); - MHH->SemID = SemID; - MHH->State = SMD_STATE_UNVALIDATED; - MHH->Segment_Size = (Seg_Size > 0 ? Seg_Size : SEGMENT_DEFAULT_SIZE); - MHH->Limit_Size = SMD_UNLIMITED; + strcpy( MHH->Name, Prefixed_Name); + MHH->Writer = getpid(); + MHH->SemID = SemID; + MHH->State = SMD_STATE_UNVALIDATED; + MHH->Segment_Size = ( ( Seg_Size > 0) ? Seg_Size : SEGMENT_DEFAULT_SIZE); + MHH->Limit_Size = SMD_UNLIMITED; MHH->Auto_Compress = SMD_DEFAULT_COMPRESS; + /* - Création de la structure DSR : - - dans la base pour le heap système - - dans le heap système pour les autres heaps + Création de la structure DSR : + - dans la base pour le heap système + - dans le heap système pour les autres heaps */ - rc = ND_DataStruct_Open (&(MHH->DSR), NDD_DS_LIST | NDD_MN_FIFO, SM_Base->MHR->Allocator, SM_Base->MHR->Desallocator, NULL, TRUE); + rc = ND_DataStruct_Open( &( MHH->DSR), 1, &index_type, "SM_DSR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Desallocator_Name, NULL, TRUE, NULL); if (rc != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to create the DSR structure"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the DSR structure"); + SM_Error_Print(); goto Error4; } - strcpy (MHH->DSR->Manager, "SM_DSR_Manager"); /* - Création de la structure ACR : - - dans la base pour le heap système - - dans le heap système pour les autres heaps + Création de la structure ACR : + - dans la base pour le heap système + - dans le heap système pour les autres heaps */ - rc = ND_DataStruct_Open (&(MHH->ACR), NDD_DS_LIST | NDD_MN_FIFO, SM_Base->MHR->Allocator, SM_Base->MHR->Desallocator, NULL, TRUE); + rc = ND_DataStruct_Open( &( MHH->ACR), 1, &index_type, "SM_ACR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Desallocator_Name, NULL, TRUE, NULL); if (rc != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to create the ACR structure"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the ACR structure"); + SM_Error_Print(); goto Error5; } - strcpy (MHH->ACR->Manager, "SM_ACR_Manager"); /* - Création de la structure FCR : - - dans la base pour le heap système - - dans le heap système pour les autres heaps + Création de la structure FCR : + - dans la base pour le heap système + - dans le heap système pour les autres heaps */ - rc = ND_DataStruct_Open (&(MHH->FCR), NDD_DS_LIST | NDD_MN_FIFO, SM_Base->MHR->Allocator, SM_Base->MHR->Desallocator, NULL, TRUE); - if (rc != NDS_OK) + rc = ND_DataStruct_Open( &( MHH->FCR), 1, &index_type, "SM_FCR_Manager", NULL, SM_Base->MHR->Allocator_Name, NULL, SM_Base->MHR->Desallocator_Name, NULL, TRUE, NULL); + if( rc != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to create the FCR structure"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create the FCR structure"); + SM_Error_Print(); goto Error6; } - strcpy (MHH->FCR->Manager, "SM_FCR_Manager"); /* Création d'un premier segment de données */ - New_DSH = SM_DataSegment_Init (MHH, MHH->Segment_Size); - if (!New_DSH) + New_DSH = SM_DataSegment_Init( MHH, MHH->Segment_Size); + if( !New_DSH) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to create a data segment for the new heap"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to create a data segment for the new heap"); + SM_Error_Print(); rc = SMS_ERRSHM; + goto Error7; } - rc = ND_Value_Add (MHH->DSR, New_DSH); - if (rc != NDS_OK) + rc = ND_Value_Add( MHH->DSR, New_DSH); + if( rc != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to add a data segment to the DSR structure"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add a data segment to the DSR structure"); + SM_Error_Print(); goto Error8; } @@ -673,23 +786,23 @@ SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* Ajout du nouveau heap à la structure MHR */ - rc = ND_Value_Add (SM_Base->MHR, MHH); - if (rc != NDS_OK) + rc = ND_Value_Add( SM_Base->MHR, MHH); + if( rc != NDS_OK) { - sprintf (SM_Error_Msg, "SM_Heap_Open : unable to add the new heap to the MHR structure"); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add the new heap to the MHR structure"); + SM_Error_Print(); goto Error9; } /* Verrouillage du nouveau MHH dans le mode demandé */ - rc = SM_Heap_Lock_Set (MHH, SMD_LOCK_MSK(Open_Mode)); - if (rc != SMS_OK) + rc = SM_Heap_Lock_Set( MHH, SMD_LOCK_MSK( Open_Mode)); + 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"); - SM_Error_Print (); + 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 Error10; } @@ -698,73 +811,93 @@ SMT_Status SM_Heap_Open_I ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg /* Ajout du nouveau heap au cache des heaps ouverts */ - *Heap = (SMT_Heap *) malloc (sizeof (SMT_Heap)); - if (!*Heap) + *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); - SM_Error_Print (); + 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)->MHH = MHH; - (*Heap)->Lock_Mode = SMD_LOCK_MSK(Open_Mode); - (*Heap)->Nb_Seg = 1; + ( *Heap)->Name = strdup( Prefixed_Name); + ( *Heap)->MHH = MHH; + ( *Heap)->Lock_Mode = SMD_LOCK_MSK( Open_Mode); + ( *Heap)->Nb_Seg = 1; - rc = ND_Value_Add (Opened_Heap_List, *Heap); - if (rc != NDS_OK) + rc = ND_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); - SM_Error_Print (); + sprintf( SM_Error_Msg, "SM_Heap_Open : unable to add heap \"%s\" to the opened heap cache", Prefixed_Name); + SM_Error_Print(); + goto Error11; } - return SMS_OK; + return( SMS_OK); + + /* Gestion d'erreur sur création */ - Error11: - free ((*Heap)->Name); - free (*Heap); - *Heap = NULL; - Error10: - ND_Value_Remove (SM_Base->MHR, MHH, (void **)&MHH); - Error9: - ND_Value_Remove (MHH->DSR, New_DSH, (void **)&New_DSH); - Error8: - SM_DataSegment_End (MHH->DSR, New_DSH); - Error7: - ND_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH->FCR, NULL); - Error6: - ND_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH->ACR, NULL); - Error5: - ND_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH->DSR, NULL); - Error4: - ND_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH, NULL); - Error3: - semctl (SemID, 0, IPC_RMID, Sem_Ctl); + Error11: + free( ( *Heap)->Name); + free( *Heap); - return rc; + *Heap = NULL; + + Error10: + ND_Value_Remove( SM_Base->MHR, MHH, (void **)&MHH); + + Error9: + ND_Value_Remove( MHH->DSR, New_DSH, (void **)&New_DSH); + + Error8: + SM_DataSegment_End( MHH->DSR, New_DSH); + + Error7: + ND_Desallocator_Exec( SM_Base->MHR->Desallocator_Ptr, MHH->FCR, NULL); + + Error6: + ND_Desallocator_Exec( SM_Base->MHR->Desallocator_Ptr, MHH->ACR, NULL); + + Error5: + ND_Desallocator_Exec( SM_Base->MHR->Desallocator_Ptr, MHH->DSR, NULL); + + Error4: + ND_Desallocator_Exec( SM_Base->MHR->Desallocator_Ptr, MHH, NULL); + + Error3: + semctl( SemID, 0, IPC_RMID, Sem_Ctl); + + return( rc); /* Gestion d'erreur sur ouverture */ - Error2: - SM_Heap_Unlock_I (*Heap); - Error1: - free ((*Heap)->Name); - free (*Heap); - *Heap = NULL; + Error2: + SM_Heap_Unlock_I( *Heap); - return rc; + Error1: + free( (*Heap)->Name); + free( *Heap); + + *Heap = NULL; + + return( rc); } + + + + /*------------------------------------------------------------------------------*/ /* Teste si un heap a déjà été ouvert par le processus courant */ /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : Nom du heap */ /* (O) Heap : pointeur sur le heap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_IsOpen_I ( const char * Heap_Name, SMT_Heap ** Heap ) { SMT_Status rc; @@ -786,17 +919,23 @@ SMT_Status SM_Heap_IsOpen_I ( const char * Heap_Name, SMT_Heap ** Heap ) return SMS_YES; } + + + + /*------------------------------------------------------------------------------*/ /* Destruction d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_End_I ( const char * Heap_Name ) { SMT_Status rc; SMT_Heap * Heap; int Locked; + rc = SM_Heap_Exist_I (Heap_Name); if (SM_ERROR(rc)) return rc; if (rc == SMS_NO) @@ -852,19 +991,24 @@ SMT_Status SM_Heap_End_I ( const char * Heap_Name ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Fermeture d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) { SMT_Status rc; NDT_Node * Node; /* - Fermeture des segments de données composant le heap - en commencant par le dernier (important pour le heap système) + Fermeture des segments de données composant le heap + en commencant par le dernier (important pour le heap système) */ ND_Node_Last_Get (Heap->MHH->DSR, &Node); @@ -889,6 +1033,10 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) return rc; } + + + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ @@ -896,11 +1044,13 @@ SMT_Status SM_Heap_Close_I ( SMT_Heap * Heap) /* (I) Lock_Mode : mode de verrouillage (SMD_READ ou SMD_WRITE) */ /* (O) Locked : verrouillage effectué (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { SMT_Status rc; int Nb_Detected, Nb_Corrected; + if (Lock_Mode == Heap->Lock_Mode) { /* Rien à faire : le heap est déjà verrouillé dans ce mode */ @@ -910,9 +1060,9 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) else if (Heap->Lock_Mode == SMD_NO_LOCK) { /* - Verrouillage d'un heap qui ne l'était pas : le heap ayant pu être modifié - depuis la dernière fois qu'on y a accédé, il faut procéder à un certain - nombre de vérifications. + Verrouillage d'un heap qui ne l'était pas : le heap ayant pu être modifié + depuis la dernière fois qu'on y a accédé, il faut procéder à un certain + nombre de vérifications. */ /* Vérification de l'état du heap */ @@ -986,7 +1136,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->Node_Number) + if (Heap->Nb_Seg != Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number) { NDT_Node * Node; @@ -997,7 +1147,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { rc = SM_DataSegment_Open (Node->Value); 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 (); @@ -1008,7 +1158,7 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) ND_Node_Next_Get (Node, &Node); } - Heap->Nb_Seg = Heap->MHH->DSR->Node_Number; + Heap->Nb_Seg = Heap->MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; } Heap->Lock_Mode = Lock_Mode; @@ -1034,11 +1184,16 @@ SMT_Status SM_Heap_Lock_I ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur unheap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) { SMT_Status rc; @@ -1047,7 +1202,7 @@ SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) 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"); + Heap->Name, Heap->Lock_Mode & SMD_READ ? "reading" : "writing"); SM_Error_Print (); return rc; @@ -1058,12 +1213,17 @@ SMT_Status SM_Heap_Unlock_I ( SMT_Heap * Heap) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Configuration d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Tag : type de configuration */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) { va_list Arguments; @@ -1097,7 +1257,7 @@ SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) { /* 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_SUM_VALUES, (void *)&Current_Size); + rc = ND_DataStruct_Traverse (Heap->MHH->DSR, SMD_CMD_VALUE_SUM, (void *)&Current_Size); if (rc != NDS_OK) return rc; if (Current_Size > Size) @@ -1127,22 +1287,28 @@ SMT_Status SM_Heap_Config_I ( SMT_Heap * Heap, SMT_Config Tag, ... ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Compression d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /* (O) Compress : pointeur sur la taille mémoire gagnée */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress) { SMT_Status rc; NDT_Node * Node; + *Compress = 0; /* - Pour permettre la compression, il faut que les - chunks libres soient triés par adresse. + Pour permettre la compression, il faut que les + chunks libres soient triés par adresse. */ rc = ND_DataStruct_Reorg (Heap->MHH->FCR); @@ -1160,6 +1326,10 @@ SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Vérification/correction des structures d'un heap */ /*------------------------------------------------------------------------------*/ @@ -1168,6 +1338,7 @@ SMT_Status SM_Heap_Compress_I ( SMT_Heap * Heap, size_t * Compress) /* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */ /* (I) Out : pointeur sur le flux de sortie du rapport */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out) { SMT_Status rc; @@ -1175,7 +1346,7 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc if (Out) fprintf (Out, "Checking heap \"%s\" ...\n", Heap->Name); - if (Heap->MHH->DSR->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 (); @@ -1292,6 +1463,10 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Allocation d'un chunk dans un heap */ /*------------------------------------------------------------------------------*/ @@ -1299,6 +1474,7 @@ SMT_Status SM_Heap_Check_I ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* (I) Size : taille du chunk */ /* (O) Ptr : adresse d'un pointeur sur la zone de données allouée */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) { NDT_Node * Node; @@ -1308,29 +1484,30 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) size_t Round_Size; SMT_Status rc; + *Ptr = NULL; /* - On invalide le heap jusqu'à ce que la procédure d'allocation soit entièrement terminée. - Ainsi, si celle-ci est interrompue, le heap restera invalide jusqu'à ce qu'il soit - "réparé" (appel de la fonction SM_Heap_Check par la fonction SM_Heap_Open). + On invalide le heap jusqu'à ce que la procédure d'allocation soit entièrement terminée. + Ainsi, si celle-ci est interrompue, le heap restera invalide jusqu'à ce qu'il soit + "réparé" (appel de la fonction SM_Heap_Check par la fonction SM_Heap_Open). */ Heap->MHH->State = SMD_STATE_UNVALIDATED; /* - Pour le heap système, tous les chunks alloués ont la même taille (DEFAULT_CHUNK_SIZE). - Ceci facilite notamment la récupération des errors (Recovery) dans le heap système. - Ceci a aussi pour but de simplifier (et donc d'optimiser) l'allocation de nouveaux chunks - dans ce heap système dont la mémoire n'a pas besoin d'être optimisée. + Pour le heap système, tous les chunks alloués ont la même taille (DEFAULT_CHUNK_SIZE). + Ceci facilite notamment la récupération des errors (Recovery) dans le heap système. + Ceci a aussi pour but de simplifier (et donc d'optimiser) l'allocation de nouveaux chunks + dans ce heap système dont la mémoire n'a pas besoin d'être optimisée. */ if (Heap == System_Heap) Alloc_Size = DEFAULT_CHUNK_SIZE; /* - Attention : pour les autres heaps, la taille allouée doit être arrondie à un multiple - de 4 octets (en 32 bits) afin que les adresses des chunks soient alignées (sinon SIGBUS !). + Attention : pour les autres heaps, la taille allouée doit être arrondie à un multiple + de 4 octets (en 32 bits) afin que les adresses des chunks soient alignées (sinon SIGBUS !). */ Round_Size = Alloc_Size % sizeof (void *); @@ -1353,8 +1530,8 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) if (Found == FALSE) { /* - Si aucun chunk libre suffisamment grand n'a été trouvé, - alors on crée un nouveau segment de données. + Si aucun chunk libre suffisamment grand n'a été trouvé, + alors on crée un nouveau segment de données. */ size_t Seg_Size; @@ -1385,8 +1562,8 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) } /* - Maintenant que l'on a ajouté un segment de données, il existe - un chunk libre suffisamment grand au début de ce segment. + Maintenant que l'on a ajouté un segment de données, il existe + un chunk libre suffisamment grand au début de ce segment. */ Node = (NDT_Node *)DSH->Start; @@ -1420,8 +1597,8 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) } /* - Si le chunk trouvé est plus grand que ce dont on a besoin, alors - on peut créer un nouveau chunk libre avec le reliquat de mémoire. + Si le chunk trouvé est plus grand que ce dont on a besoin, alors + on peut créer un nouveau chunk libre avec le reliquat de mémoire. */ if (Chunk->Size - Alloc_Size > 0) @@ -1429,9 +1606,9 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) size_t Remaining_Size = Chunk->Size - Alloc_Size; /* - La création d'un nouveau chunk libre requiert de la place pour les - données système (SMT_Chunk + NDT_Node) : on ne crée donc un nouveau - chunk libre que si le reliquat est suffisamment important. + La création d'un nouveau chunk libre requiert de la place pour les + données système (SMT_Chunk + NDT_Node) : on ne crée donc un nouveau + chunk libre que si le reliquat est suffisamment important. */ if (Remaining_Size > sizeof (SMT_Chunk) + sizeof (NDT_Node)) @@ -1474,11 +1651,11 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) } /* - Pour une allocation dans le heap système, on anticipe l'ajout - d'un nouveau segment pour éviter de se retrouver bloqué. + Pour une allocation dans le heap système, on anticipe l'ajout + d'un nouveau segment pour éviter de se retrouver bloqué. - Bien entendu, cette opération n'est faite que si l'on n'est - pas déjà en train d'étendre le heap système (Adding_Segment=TRUE). + Bien entendu, cette opération n'est faite que si l'on n'est + pas déjà en train d'étendre le heap système (Adding_Segment=TRUE). */ if (Heap == System_Heap && Adding_Segment == FALSE) @@ -1505,11 +1682,11 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) } /* - S'il reste au moins FREE_CHUNK_LIMIT chunks libres "utilisables" - ou bien si ces chunks libres "utilisables" représentent suffisament de - place pour allouer FREE_CHUNK_LIMIT nouveaux chunks, alors tout est OK. + S'il reste au moins FREE_CHUNK_LIMIT chunks libres "utilisables" + ou bien si ces chunks libres "utilisables" représentent suffisament de + place pour allouer FREE_CHUNK_LIMIT nouveaux chunks, alors tout est OK. - Dans le cas contraire, il est urgent d'étendre le heap système. + Dans le cas contraire, il est urgent d'étendre le heap système. */ if (Free_Usable_Chunk < FREE_CHUNK_LIMIT) @@ -1526,15 +1703,15 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) NDT_Node * New_Node; /* - Puisque l'ajout d'un nouveau segment va appeler cette même fonction, - on positionne une variable globale pour ne pas recommencer cette opération. + Puisque l'ajout d'un nouveau segment va appeler cette même fonction, + on positionne une variable globale pour ne pas recommencer cette opération. */ Adding_Segment = TRUE; /* - On alloue le noeud du nouveau segment avant de faire appel à la fonction - SM_DataSegment_Init pour éviter que ce noeud soit alloué dans le nouveau segment. + On alloue le noeud du nouveau segment avant de faire appel à la fonction + SM_DataSegment_Init pour éviter que ce noeud soit alloué dans le nouveau segment. */ SM_System_Alloc (sizeof (NDT_Node), (void **)(&New_Node), NULL); @@ -1574,8 +1751,8 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) } /* - Puisque la procédure d'allocation d'un chunk s'est correctement - terminée, on peut rendre le heap à nouveau valide. + Puisque la procédure d'allocation d'un chunk s'est correctement + terminée, on peut rendre le heap à nouveau valide. */ Heap->MHH->State = SMD_STATE_VALID; @@ -1585,12 +1762,17 @@ SMT_Status SM_Chunk_Alloc_I ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Désallocation d'un chunk */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Ptr : pointeur sur la zone de données du chunk à désallouer */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) { NDT_Node * Node; @@ -1598,17 +1780,17 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) SMT_Status rc; /* - On invalide le heap jusqu'à ce que la procédure de désallocation soit entièrement terminée. - Ainsi, si celle-ci est interrompue, le heap restera invalide jusqu'à ce qu'il soit - "réparé" (appel de la fonction SM_Heap_Check par la fonction SM_Heap_Open). + On invalide le heap jusqu'à ce que la procédure de désallocation soit entièrement terminée. + Ainsi, si celle-ci est interrompue, le heap restera invalide jusqu'à ce qu'il soit + "réparé" (appel de la fonction SM_Heap_Check par la fonction SM_Heap_Open). */ Heap->MHH->State = SMD_STATE_UNVALIDATED; /* - Le noeud du chunk étant adjoint à celui-ci, on n'a pas besoin - de le rechercher dans la liste des chunks alloués. - */ + Le noeud du chunk étant adjoint à celui-ci, on n'a pas besoin + de le rechercher dans la liste des chunks alloués. + */ Node = (NDT_Node *)((size_t)Ptr - sizeof (SMT_Chunk) - sizeof (NDT_Node)); @@ -1641,8 +1823,8 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) } /* - Puisque la procédure de désallocation d'un chunk s'est correctement - terminé, on peut rendre le heap à nouveau valide. + Puisque la procédure de désallocation d'un chunk s'est correctement + terminé, on peut rendre le heap à nouveau valide. */ Heap->MHH->State = SMD_STATE_VALID; @@ -1650,14 +1832,14 @@ 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 && - Heap->MHH->FCR->Node_Number > Heap->MHH->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) { - 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->Node_Number); + 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 (); return rc; } @@ -1666,6 +1848,10 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* FONCTIONS SECURISEES (SM_MODE = 0) */ /*------------------------------------------------------------------------------*/ @@ -1677,46 +1863,67 @@ SMT_Status SM_Chunk_Free_I ( SMT_Heap * Heap, void * Ptr) /* (I) Context : nom du nouveau contexte */ /* (I) Open_Mode : indicateur création/ouverture + mode d'affichage des erreurs */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Open_C ( int Instance, const char * Context, SMT_Flags Open_Mode ) { return SM_Library_Open_I (Instance, Context, Open_Mode); } + + + + /*------------------------------------------------------------------------------*/ /* Récupération du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ /* (O) Instance : adresse du numéro de l'instance utilisée */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Instance_Get_C ( int * Instance ) { return SM_Library_Instance_Get_I (Instance); } + + + + /*------------------------------------------------------------------------------*/ /* Récupération du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ /* (O) Context : adresse du nom du contexte utilisé */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Context_Get_C ( char ** Context ) { return SM_Library_Context_Get_I (Context); } + + + + /*------------------------------------------------------------------------------*/ /* Changement de contexte d'utilisation de la librairie */ /*------------------------------------------------------------------------------*/ /* (I) Context : nom du nouveau contexte */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Context_Set_C ( const char * Context ) { return SM_Library_Context_Set_I (Context); } + + + + /*------------------------------------------------------------------------------*/ /* Fermeture de l'instance de la librairie */ /*------------------------------------------------------------------------------*/ /* (I) Close_Mode : mode de fermeture (destruction ou fermeture simple) */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode ) { if (!SM_Base) @@ -1730,9 +1937,14 @@ SMT_Status SM_Library_Close_C ( SMT_Flags Close_Mode ) return SM_Library_Close_I (Close_Mode); } + + + + /*------------------------------------------------------------------------------*/ /* Affichage des informations de la base de mémoires partagées */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Dump_C (FILE * Out) { if (!SM_Base) @@ -1745,9 +1957,14 @@ SMT_Status SM_Library_Dump_C (FILE * Out) return SM_Library_Dump_I (Out); } + + + + /*------------------------------------------------------------------------------*/ /* Libération de tous les verrous (base, heap) */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Unlock_C ( void ) { if (!SM_Base) @@ -1760,19 +1977,29 @@ SMT_Status SM_Library_Unlock_C ( void ) return SM_Library_Unlock_I (); } + + + + /*------------------------------------------------------------------------------*/ /* Définition de la sortie standard des messages d'erreur de la librairie */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Library_Stderr_Set_C ( FILE * Out ) { return SM_Library_Stderr_Set_I (Out); } + + + + /*------------------------------------------------------------------------------*/ /* Test d'existence d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : Nom du heap */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) { if (!SM_Base) @@ -1792,6 +2019,10 @@ SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) return SM_Heap_Exist_I (Heap_Name); } + + + + /*------------------------------------------------------------------------------*/ /* Ouverture/création d'un heap */ /*------------------------------------------------------------------------------*/ @@ -1801,6 +2032,7 @@ SMT_Status SM_Heap_Exist_C ( const char * Heap_Name ) /* (I) Open_Mode : mode d'ouverture du heap */ /* (O) Locked : verrou effectif (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ + 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) @@ -1821,12 +2053,17 @@ SMT_Status SM_Heap_Open_C ( const char * Heap_Name, SMT_Heap ** Heap, size_t Seg return SM_Heap_Open_I (Heap_Name, Heap, Seg_Size, Open_Mode, Locked); } + + + + /*------------------------------------------------------------------------------*/ /* Teste si un heap a déjà été ouvert par le processus courant */ /*------------------------------------------------------------------------------*/ /* (I) Heap_Name : Nom du heap */ /* (O) Heap : pointeur sur le heap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) { if (!SM_Base) @@ -1847,11 +2084,16 @@ SMT_Status SM_Heap_IsOpen_C ( const char * Heap_Name, SMT_Heap ** Heap ) return SM_Heap_IsOpen_I (Heap_Name, Heap); } + + + + /*------------------------------------------------------------------------------*/ /* Destruction d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_End_C ( const char * Heap_Name ) { if (!SM_Base) @@ -1872,11 +2114,16 @@ SMT_Status SM_Heap_End_C ( const char * Heap_Name ) return SM_Heap_End_I (Heap_Name); } + + + + /*------------------------------------------------------------------------------*/ /* Fermeture d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) { if (!SM_Base) @@ -1897,6 +2144,10 @@ SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) return SM_Heap_Close_I (Heap); } + + + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ @@ -1904,6 +2155,7 @@ SMT_Status SM_Heap_Close_C ( SMT_Heap * Heap ) /* (I) Lock_Mode : mode de verrouillage (SMD_READ ou SMD_WRITE) */ /* (O) Locked : verrouillage effectué (TRUE ou FALSE) */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) { if (!SM_Base) @@ -1924,11 +2176,16 @@ SMT_Status SM_Heap_Lock_C ( SMT_Heap * Heap, SMT_Flags Lock_Mode, int * Locked ) return SM_Heap_Lock_I (Heap, Lock_Mode, Locked); } + + + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur unheap ouvert */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ) { if (!SM_Base) @@ -1949,18 +2206,24 @@ SMT_Status SM_Heap_Unlock_C ( SMT_Heap * Heap ) return SM_Heap_Unlock_I (Heap); } + + + + /*------------------------------------------------------------------------------*/ /* Configuration d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Tag : type de configuration */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) { va_list Arguments; size_t Segment_Size, Limit_Size, Current_Size; SMT_Status rc; + if (!SM_Base) { sprintf (SM_Error_Msg, "SM_Heap_Config : the LIBSHMEM library is not open"); @@ -1996,7 +2259,7 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) { /* 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_SUM_VALUES, (void *)&Current_Size); + rc = ND_DataStruct_Traverse (Heap->MHH->DSR, SMD_CMD_VALUE_SUM, (void *)&Current_Size); if (rc != NDS_OK) return rc; if (Current_Size > Limit_Size) @@ -2026,12 +2289,17 @@ SMT_Status SM_Heap_Config_C ( SMT_Heap * Heap, SMT_Config Tag, ... ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Compression d'un heap */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /* (O) Compress : pointeur sur la taille mémoire gagnée */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) { if (!SM_Base) @@ -2059,6 +2327,10 @@ SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) return SM_Heap_Compress_I (Heap, Compress); } + + + + /*------------------------------------------------------------------------------*/ /* Vérification/correction des structures d'un heap */ /*------------------------------------------------------------------------------*/ @@ -2067,6 +2339,7 @@ SMT_Status SM_Heap_Compress_C ( SMT_Heap * Heap, size_t * Compress ) /* (O) Nb_Corrected : pointeur sur le nombre d'erreurs corrigées */ /* (I) Out : pointeur sur le flux de sortie du rapport */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Corrected, FILE * Out ) { if (!SM_Base) @@ -2101,6 +2374,10 @@ SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc return SM_Heap_Check_I (Heap, Nb_Detected, Nb_Corrected, Out); } + + + + /*------------------------------------------------------------------------------*/ /* Allocation d'un chunk dans un heap */ /*------------------------------------------------------------------------------*/ @@ -2108,6 +2385,7 @@ SMT_Status SM_Heap_Check_C ( SMT_Heap * Heap, int * Nb_Detected, int * Nb_Correc /* (I) Size : taille du chunk */ /* (O) Ptr : adresse d'un pointeur sur la zone de données allouée */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) { if (!SM_Base) @@ -2135,12 +2413,17 @@ SMT_Status SM_Chunk_Alloc_C ( SMT_Heap * Heap, size_t Alloc_Size, void ** Ptr) return SM_Chunk_Alloc_I (Heap, Alloc_Size, Ptr); } + + + + /*------------------------------------------------------------------------------*/ /* Désallocation d'un chunk */ /*------------------------------------------------------------------------------*/ /* (I) Heap : pointeur sur un heap ouvert */ /* (I) Ptr : pointeur sur la zone de données du chunk à désallouer */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr) { if (!SM_Base) @@ -2168,15 +2451,22 @@ SMT_Status SM_Chunk_Free_C ( SMT_Heap * Heap, void * Ptr) return SM_Chunk_Free_I (Heap, Ptr); } + + + + /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ /* FONCTIONS PRIVEES */ /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ + + /*------------------------------------------------------------------------------*/ /* Allocation de mémoire dans la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Alloc (size_t Size, void ** Ptr, void * Data) { *Ptr = NULL; @@ -2187,9 +2477,14 @@ SMT_Status SM_Base_Alloc (size_t Size, void ** Ptr, void * Data) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Désallocation de mémoire dans la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Free (void * Ptr, void * Data) { if (!Ptr) return SMS_ERRAPI; @@ -2197,34 +2492,51 @@ SMT_Status SM_Base_Free (void * Ptr, void * Data) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Allocation de mémoire dans le heap système */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_System_Alloc (size_t Size, void ** Ptr, void * Data) { return SM_Chunk_Alloc_I (System_Heap, Size, Ptr); } + + + + /*------------------------------------------------------------------------------*/ /* Désallocation de mémoire dans le heap système */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_System_Free (void * Ptr, void * Data) { return SM_Chunk_Free_I (System_Heap, Ptr); } + + + + /*------------------------------------------------------------------------------*/ /* Initialisation de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Init ( void ) { - SMT_Status rc; - int SemID; - int SysMemID; - int DataMemID; - union semun Sem_Ctl; - size_t Size; - int Locked; + SMT_Status rc; + int SemID; + int SysMemID; + int DataMemID; + union semun Sem_Ctl; + size_t Size; + int Locked; + NDT_Index_Type index_type = ( NDD_INDEX_STATUS_OPENED | NDD_INDEX_TYPE_LIST | NDD_INDEX_SUBTYPE_FIFO); + /* Création du sémaphore pour la gestion des verrous sur la base */ @@ -2265,8 +2577,8 @@ SMT_Status SM_Base_Init ( void ) } /* - Création d'un segment de mémoire partagée qui contiendra la structure SMT_Base. - Ce segment peut être attaché à n'importe quelle adresse. + Création d'un segment de mémoire partagée qui contiendra la structure SMT_Base. + Ce segment peut être attaché à n'importe quelle adresse. */ SysMemID = shmget (SM_Instance, (int) sizeof (SMT_Base), 0777|IPC_CREAT|IPC_EXCL); @@ -2315,24 +2627,24 @@ SMT_Status SM_Base_Init ( void ) } /* - Attention : tant que le heap système n'est pas créé, on est obligé d'allouer de - la mémoire dans le segment de mémoire partagée de la base (fonction SM_Base_Alloc). + Attention : tant que le heap système n'est pas créé, on est obligé d'allouer de + la mémoire dans le segment de mémoire partagée de la base (fonction SM_Base_Alloc). - Les ressources à allouer (structure MHR + ressources du heap système) sont référencées - par des pointeurs et doivent par conséquent être contenues dans un segment attaché à - une adresse commune à tous les processus. - On crée donc ce segment de mémoire partagé spécifique dont l'adresse d'attachement - sera mémorisée dans la structure SMT_Base. + Les ressources à allouer (structure MHR + ressources du heap système) sont référencées + par des pointeurs et doivent par conséquent être contenues dans un segment attaché à + une adresse commune à tous les processus. + On crée donc ce segment de mémoire partagé spécifique dont l'adresse d'attachement + sera mémorisée dans la structure SMT_Base. - Pour ce segment de mémoire partagé, on réserve de la place pour : - - la structure du MHR (NDT_Root) - - les ressources du heap système, i.e : - - son noeud (NDT_Node) - - sa structure d'entête ( SMT_MHH) - - sa structure DSR (NDT_Root) - - sa structure ACR (NDT_Root) - - sa structure FCR (NDT_Root) - - son premier segment de données (noeud + entête) + Pour ce segment de mémoire partagé, on réserve de la place pour : + - la structure du MHR (NDT_Root) + - les ressources du heap système, i.e : + - son noeud (NDT_Node) + - sa structure d'entête ( SMT_MHH) + - sa structure DSR (NDT_Root) + - sa structure ACR (NDT_Root) + - sa structure FCR (NDT_Root) + - son premier segment de données (noeud + entête) */ Size = sizeof (NDT_Root) + sizeof (NDT_Node) + sizeof (SMT_MHH) + 3 * sizeof (NDT_Root) + sizeof (NDT_Node) + sizeof (SMT_DSH); @@ -2377,9 +2689,9 @@ SMT_Status SM_Base_Init ( void ) SM_Base->MHR = NULL; /* - On attache le segment de mémoire partagée au processus courant - à une adresse la plus haute possible (MEM_LIMIT) afin d'éviter - de déborder sur la plage d'adressage des symboles. + On attache le segment de mémoire partagée au processus courant + à une adresse la plus haute possible (MEM_LIMIT) afin d'éviter + de déborder sur la plage d'adressage des symboles. */ errno = 0; @@ -2397,7 +2709,7 @@ SMT_Status SM_Base_Init ( void ) /* Création du MHR dans la base */ - rc = ND_DataStruct_Open (&(SM_Base->MHR), NDD_DS_LIST | NDD_MN_FIFO, "SM_Base_Alloc", "SM_Base_Free", NULL, TRUE); + 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) { sprintf (SM_Error_Msg, "SM_Base_Init : unable to create the MHR structure"); @@ -2406,12 +2718,11 @@ SMT_Status SM_Base_Init ( void ) goto Error4; } - strcpy (SM_Base->MHR->Manager, "MHR_Manager"); /* - Création d'un premier heap qui constituera le heap système - (l'allocation du MHN, du MHH et des structures DSR, ACR et FCR - sont effectuées dans la base) + Création d'un premier heap qui constituera le heap système + (l'allocation du MHN, du MHH et des structures DSR, ACR et FCR + sont effectuées dans la base) */ rc = SM_Heap_Open_I (HEAP_SYSTEM, &System_Heap, 0, SMD_CREATE, &Locked); @@ -2424,26 +2735,26 @@ SMT_Status SM_Base_Init ( void ) } /* - On change les fonctions d'allocation et de désallocation du MHR afin que désormais, - les allocations des nouveaux heaps soient faites dans le heap système. + On change les fonctions d'allocation et de désallocation du MHR afin que désormais, + les allocations des nouveaux heaps soient faites dans le heap système. */ - strcpy (SM_Base->MHR->Allocator, "SM_System_Alloc"); - strcpy (SM_Base->MHR->Desallocator, "SM_System_Free"); + strcpy( SM_Base->MHR->Allocator_Name, "SM_System_Alloc"); + strcpy( SM_Base->MHR->Desallocator_Name, "SM_System_Free"); /* - On change les fonctions Allocator et Desallocator du DSR, ACR - et FCR du heap système afin que désormais, les allocations des - nouveaux segments et chunks soient faites dans le segment de - données du heap système. + On change les fonctions Allocator et Desallocator du DSR, ACR + et FCR du heap système afin que désormais, les allocations des + nouveaux segments et chunks soient faites dans le segment de + données du heap système. */ - strcpy (System_Heap->MHH->DSR->Allocator, "SM_System_Alloc"); - strcpy (System_Heap->MHH->DSR->Desallocator, "SM_System_Free"); - strcpy (System_Heap->MHH->ACR->Allocator, "SM_System_Alloc"); - strcpy (System_Heap->MHH->ACR->Desallocator, "SM_System_Free"); - strcpy (System_Heap->MHH->FCR->Allocator, "SM_System_Alloc"); - strcpy (System_Heap->MHH->FCR->Desallocator, "SM_System_Free"); + strcpy( System_Heap->MHH->DSR->Allocator_Name, "SM_System_Alloc"); + strcpy( System_Heap->MHH->DSR->Desallocator_Name, "SM_System_Free"); + strcpy( System_Heap->MHH->ACR->Allocator_Name, "SM_System_Alloc"); + strcpy( System_Heap->MHH->ACR->Desallocator_Name, "SM_System_Free"); + strcpy( System_Heap->MHH->FCR->Allocator_Name, "SM_System_Alloc"); + strcpy( System_Heap->MHH->FCR->Desallocator_Name, "SM_System_Free"); /* Verrouillage de la base en lecture */ @@ -2460,25 +2771,30 @@ SMT_Status SM_Base_Init ( void ) /* Gestion d'erreur */ - Error5: - ND_DataStruct_Close (SM_Base->MHR); - Error4: - shmdt ((void *)(SM_Base->Free)); - Error3: - shmctl (DataMemID, IPC_RMID, 0); - Error2: - shmdt ((void *)SM_Base); - shmctl (SysMemID, IPC_RMID, 0); - SM_Base = NULL; - Error1: - semctl (SemID, 0, IPC_RMID, Sem_Ctl); + Error5: + ND_DataStruct_Close (SM_Base->MHR); + Error4: + shmdt ((void *)(SM_Base->Free)); + Error3: + shmctl (DataMemID, IPC_RMID, 0); + Error2: + shmdt ((void *)SM_Base); + shmctl (SysMemID, IPC_RMID, 0); + SM_Base = NULL; + Error1: + semctl (SemID, 0, IPC_RMID, Sem_Ctl); return rc; } + + + + /*------------------------------------------------------------------------------*/ /* Destruction de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_End ( void ) { int SemID; @@ -2512,10 +2828,10 @@ SMT_Status SM_Base_End ( void ) } /* - Destruction de tous les heaps (parcours du MHR en - sens inverse pour détruire le heap système en dernier). + Destruction de tous les heaps (parcours du MHR en + sens inverse pour détruire le heap système en dernier). - NB : à chaque destruction de heap, la base est verrouillée en écriture + NB : à chaque destruction de heap, la base est verrouillée en écriture */ ND_Node_Last_Get (SM_Base->MHR, &Node); @@ -2527,11 +2843,14 @@ SMT_Status SM_Base_End ( void ) ND_Node_Previous_Get (Node, &Previous_Node); /* - Pour la suppression du heap système, il faut redéfinir la fonction de - désallocation du MHR, car il a été alloué dans la base (voir SM_Base_Init) + Pour la suppression du heap système, il faut redéfinir la fonction de + désallocation du MHR, car il a été alloué dans la base (voir SM_Base_Init) */ - if (!Previous_Node) strcpy (SM_Base->MHR->Desallocator, "SM_Base_Free"); + if( !Previous_Node) + { + strcpy( SM_Base->MHR->Desallocator_Name, "SM_Base_Free"); + } /* Retrait du heap de la structure du MHR */ @@ -2624,9 +2943,14 @@ SMT_Status SM_Base_End ( void ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Ouverture de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Open ( void ) { SMT_Status rc; @@ -2634,6 +2958,7 @@ SMT_Status SM_Base_Open ( void ) int MemID; int Locked; + if (SM_Base) return SMS_OK; /* Récupération de l'identifiant du segment de mémoire partagée de la base */ @@ -2723,13 +3048,19 @@ SMT_Status SM_Base_Open ( void ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Fermeture de la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Close ( void ) { NDT_Node * Node; + if (!SM_Base) { sprintf (SM_Error_Msg, "SM_Base_Close : the LIBSHMEM library is not open"); @@ -2739,9 +3070,9 @@ SMT_Status SM_Base_Close ( void ) } /* - Fermeture de tous les heaps (sans déverrouillage) ouverts. + Fermeture de tous les heaps (sans déverrouillage) ouverts. - Attention : il faut fermer le heap système en dernier. + Attention : il faut fermer le heap système en dernier. */ ND_Node_First_Get (Opened_Heap_List, &Node); @@ -2768,9 +3099,14 @@ SMT_Status SM_Base_Close ( void ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) { SMT_Status rc; @@ -2802,9 +3138,14 @@ SMT_Status SM_Base_Lock ( SMT_Flags Lock_Mode ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur la base */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode ) { SMT_Status rc; @@ -2836,14 +3177,20 @@ SMT_Status SM_Base_Unlock ( SMT_Flags Lock_Mode ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Fonction manager de la liste des heaps ouverts */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_Opened_Heap_List_Manager (va_list Args) { NDT_Command Command = (NDT_Command)va_arg (Args, NDT_Command); - if (Command == NDD_CMD_COMP_VALUE) + + if (Command == NDD_CMD_VALUE_COMP) { SMT_Heap * Heap1, * Heap2; long comp; @@ -2862,7 +3209,7 @@ NDT_Status SM_Opened_Heap_List_Manager (va_list Args) return NDS_EQUAL; } - if (Command == NDD_CMD_DELETE_VALUE) + if (Command == NDD_CMD_VALUE_FREE) { NDT_Root * Root = va_arg (Args, NDT_Root *); SMT_Heap * Heap = (SMT_Heap *) va_arg (Args, void *); @@ -2874,15 +3221,20 @@ NDT_Status SM_Opened_Heap_List_Manager (va_list Args) return NDS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Fonction manager du MHR (Memory Heap Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status MHR_Manager (va_list Args) { SMT_Status rc; NDT_Command Command = (NDT_Command)va_arg (Args, NDT_Command); - if (Command == NDD_CMD_PRINT_VALUE) + if (Command == NDD_CMD_VALUE_PRINT) { SMT_MHH * MHH = (SMT_MHH *)va_arg (Args, void *); FILE * Out = va_arg (Args, FILE *); @@ -2919,24 +3271,24 @@ NDT_Status MHR_Manager (va_list Args) return rc; } - Nb_Segment = MHH->DSR->Node_Number; - ND_DataStruct_Traverse (MHH->DSR, NDD_CMD_SUM_VALUES, (void *)&Segment_Size); + Nb_Segment = MHH->DSR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; + ND_DataStruct_Traverse (MHH->DSR, SMD_CMD_VALUE_SUM, (void *)&Segment_Size); - Nb_Alloc_Chunk = MHH->ACR->Node_Number; - ND_DataStruct_Traverse (MHH->ACR, NDD_CMD_SUM_VALUES, (void *)&Alloc_Size); + Nb_Alloc_Chunk = MHH->ACR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; + ND_DataStruct_Traverse (MHH->ACR, SMD_CMD_VALUE_SUM, (void *)&Alloc_Size); - Nb_Free_Chunk = MHH->FCR->Node_Number; - ND_DataStruct_Traverse (MHH->FCR, NDD_CMD_SUM_VALUES, (void *)&Free_Size); + Nb_Free_Chunk = MHH->FCR->Index_Tab[NDD_INDEX_PRIMARY].Node_Number; + ND_DataStruct_Traverse (MHH->FCR, SMD_CMD_VALUE_SUM, (void *)&Free_Size); fprintf (Out, "Heap \"%s\" :\n\t- Last write access pid = %ld\n\t- ID Sem = %d\n\t- Status = %s\n\t- Data = %d segment(s) - %d bytes\n\t- Allocated = %d chunk(s) - %d bytes\n\t- Free = %d chunk(s) - %d bytes", - ptr, MHH->Writer, MHH->SemID, SM_Lock_Status_Get ("heap", MHH), Nb_Segment, Segment_Size, Nb_Alloc_Chunk, Alloc_Size, Nb_Free_Chunk, Free_Size); + ptr, MHH->Writer, MHH->SemID, SM_Lock_Status_Get ("heap", MHH), Nb_Segment, Segment_Size, Nb_Alloc_Chunk, Alloc_Size, Nb_Free_Chunk, Free_Size); if (Locked == TRUE) SM_Heap_Unlock_I (Heap); return NDS_OK; } - if (Command == NDD_CMD_PRINT_INFO) + if (Command == NDD_CMD_INFO_PRINT) { NDT_Root * Root = va_arg (Args, NDT_Root *); FILE * Out = va_arg (Args, FILE *); @@ -2946,7 +3298,7 @@ NDT_Status MHR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_COMP_VALUE) + if (Command == NDD_CMD_VALUE_COMP) { SMT_MHH * MHH1, * MHH2; long comp; @@ -2965,7 +3317,7 @@ NDT_Status MHR_Manager (va_list Args) return NDS_EQUAL; } - if (Command == NDD_CMD_DELETE_VALUE) + if (Command == NDD_CMD_VALUE_FREE) { NDT_Root * Root = va_arg (Args, NDT_Root *); SMT_MHH * MHH = (SMT_MHH *)va_arg (Args, void *); @@ -2976,9 +3328,14 @@ NDT_Status MHR_Manager (va_list Args) return NDS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Destruction d'un MHH (Memory Heap Header) */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_MHH_End ( SMT_MHH * MHH) { SMT_Status rc; @@ -2994,13 +3351,13 @@ SMT_Status SM_MHH_End ( SMT_MHH * MHH) SMT_DSH * DSH; /* - Pour le heap système, on doit procéder de manière spécifique - car le premier segment contient des références sur les autres - segments. Il faut donc supprimer celui-ci en dernier. + Pour le heap système, on doit procéder de manière spécifique + car le premier segment contient des références sur les autres + segments. Il faut donc supprimer celui-ci en dernier. - Par ailleurs, ce premier segment a été alloué dans la base. - Il faudra donc aussi redéfinir la fonction de désallocation - du DSR pour celui-ci. + Par ailleurs, ce premier segment a été alloué dans la base. + Il faudra donc aussi redéfinir la fonction de désallocation + du DSR pour celui-ci. */ ND_Node_Last_Get (MHH->DSR, &Node); @@ -3013,7 +3370,10 @@ SMT_Status SM_MHH_End ( SMT_MHH * MHH) /* S'agit-il du heap système ? */ - if (!Previous_Node) strcpy (MHH->DSR->Desallocator, "SM_Base_Free"); + if( !Previous_Node) + { + strcpy( MHH->DSR->Desallocator_Name, "SM_Base_Free"); + } /* Retrait du segment du DSR */ @@ -3051,21 +3411,21 @@ SMT_Status SM_MHH_End ( SMT_MHH * MHH) } /* - Destruction des structures ACR et FCR. + Destruction des structures ACR et FCR. - NB : puisque tous les chunks réfénrencés par les ACR et FCR étaient alloués - dans les segments qui viennent d'être supprimés, on se contente de détuire - leur racine. + NB : puisque tous les chunks réfénrencés par les ACR et FCR étaient alloués + dans les segments qui viennent d'être supprimés, on se contente de détuire + leur racine. */ - rc = ND_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH->ACR, NULL); + rc = ND_Desallocator_Exec( SM_Base->MHR->Desallocator_Ptr, MHH->ACR, NULL); 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_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH->FCR, NULL); + rc = ND_Desallocator_Exec (SM_Base->MHR->Desallocator_Ptr, MHH->FCR, NULL); if (rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to free the FCR root of heap \"%s\"", MHH->Name); @@ -3088,7 +3448,7 @@ SMT_Status SM_MHH_End ( SMT_MHH * MHH) /* Désallocation de la structure du MHH */ - rc = ND_Desallocator_Exec (SM_Base->MHR->Desallocator, MHH, NULL); + rc = ND_Desallocator_Exec( SM_Base->MHR->Desallocator_Ptr, MHH, NULL); if (rc != SMS_OK) { sprintf (SM_Error_Msg, "SM_MHH_End : unable to free the header of heap \"%s\"", MHH->Name); @@ -3098,20 +3458,27 @@ SMT_Status SM_MHH_End ( SMT_MHH * MHH) return rc; } + + + + /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ /* Gestion des segments de données */ /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ + + /*------------------------------------------------------------------------------*/ /* Fonction manager pour un DSR (Data Segment Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_DSR_Manager (va_list Args) { NDT_Command Command = (NDT_Command)va_arg (Args, NDT_Command); - if (Command == NDD_CMD_SUM_VALUES) + if (Command == SMD_CMD_VALUE_SUM) { SMT_DSH * DSH = (SMT_DSH *)va_arg (Args, void *); int * Total_Size = (int *)va_arg (Args, int *); @@ -3121,7 +3488,7 @@ NDT_Status SM_DSR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_PRINT_VALUE) + if (Command == NDD_CMD_VALUE_PRINT) { SMT_DSH * DSH = (SMT_DSH *)va_arg (Args, void *); FILE * Out = va_arg (Args, FILE *); @@ -3132,7 +3499,7 @@ NDT_Status SM_DSR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_PRINT_INFO) + if (Command == NDD_CMD_INFO_PRINT) { NDT_Root * Root = Root = va_arg (Args, NDT_Root *); FILE * Out = va_arg (Args, FILE *); @@ -3143,7 +3510,7 @@ NDT_Status SM_DSR_Manager (va_list Args) } - if (Command == NDD_CMD_COMP_VALUE) + if (Command == NDD_CMD_VALUE_COMP) { int comp; @@ -3160,7 +3527,7 @@ NDT_Status SM_DSR_Manager (va_list Args) } - if (Command == NDD_CMD_DELETE_VALUE) + if (Command == NDD_CMD_VALUE_FREE) { NDT_Root * Root = va_arg (Args, NDT_Root *); SMT_DSH * DSH = (SMT_DSH *)va_arg (Args, void *); @@ -3171,9 +3538,14 @@ NDT_Status SM_DSR_Manager (va_list Args) return NDS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Création d'un nouveau segment de données */ /*------------------------------------------------------------------------------*/ + SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) { SMT_DSH * New_DSH; @@ -3186,7 +3558,7 @@ SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) { size_t Current_Size; - ND_DataStruct_Traverse (MHH->DSR, NDD_CMD_SUM_VALUES, (void *)&Current_Size); + ND_DataStruct_Traverse (MHH->DSR, SMD_CMD_VALUE_SUM, (void *)&Current_Size); if (Current_Size + Segment_Size > MHH->Limit_Size) { @@ -3199,7 +3571,7 @@ SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) /* Création de l'entête */ - if (ND_Allocator_Exec (MHH->DSR->Allocator, (void **)(&New_DSH), sizeof (SMT_DSH), NULL) != NDS_OK) + if( ND_Allocator_Exec( MHH->DSR->Allocator_Ptr, (void **)(&New_DSH), sizeof (SMT_DSH), NULL) != NDS_OK) { sprintf (SM_Error_Msg, "SM_DataSegment_Init : unable to allocate memory for the new data segment header"); SM_Error_Print (); @@ -3232,7 +3604,7 @@ SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) SM_Error_Print (); - ND_Desallocator_Exec (MHH->DSR->Desallocator, New_DSH, NULL); + ND_Desallocator_Exec( MHH->DSR->Desallocator_Ptr, New_DSH, NULL); return NULL; } @@ -3248,7 +3620,7 @@ SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) shmctl (New_DSH->MemID, IPC_RMID, 0); - ND_Desallocator_Exec (MHH->DSR->Desallocator, New_DSH, NULL); + ND_Desallocator_Exec( MHH->DSR->Desallocator_Ptr, New_DSH, NULL); return NULL; } @@ -3280,7 +3652,7 @@ SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) shmctl (New_DSH->MemID, IPC_RMID, 0); - ND_Desallocator_Exec (MHH->DSR->Desallocator, New_DSH, NULL); + ND_Desallocator_Exec( MHH->DSR->Desallocator_Ptr, New_DSH, NULL); return NULL; } @@ -3288,9 +3660,14 @@ SMT_DSH * SM_DataSegment_Init ( SMT_MHH * MHH, size_t Segment_Size) return New_DSH; } + + + + /*------------------------------------------------------------------------------*/ /* Terminaison d'un segment de données */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_DataSegment_End (NDT_Root * Root, SMT_DSH *DSH) { SMT_Status rc; @@ -3321,7 +3698,7 @@ SMT_Status SM_DataSegment_End (NDT_Root * Root, SMT_DSH *DSH) /* Désallocation de l'entête */ - rc = ND_Desallocator_Exec (Root->Desallocator, DSH, NULL); + rc = ND_Desallocator_Exec( Root->Desallocator_Ptr, DSH, NULL); if (rc != NDS_OK) { sprintf (SM_Error_Msg, "SM_DataSegment_End : the data segment header is nul"); @@ -3333,19 +3710,24 @@ SMT_Status SM_DataSegment_End (NDT_Root * Root, SMT_DSH *DSH) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Ouverture d'un segment de données */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_DataSegment_Open ( SMT_DSH *DSH) { void *Ptr; /* - On attache le segment de mémoire partagée au processus courant. + On attache le segment de mémoire partagée au processus courant. - Attention : il faut que ce segment soit attaché à la même adresse - que lorsqu'il a été créé afin que les pointeurs qui pointent dans - ce segment soient valides. + Attention : il faut que ce segment soit attaché à la même adresse + que lorsqu'il a été créé afin que les pointeurs qui pointent dans + ce segment soient valides. */ shmdt ((void *)DSH->Start); @@ -3363,9 +3745,14 @@ SMT_Status SM_DataSegment_Open ( SMT_DSH *DSH) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Fermeture d'un segment de données */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_DataSegment_Close ( SMT_DSH *DSH) { /* On détache le segment de mémoire partagée du processus courant */ @@ -3375,9 +3762,14 @@ SMT_Status SM_DataSegment_Close ( SMT_DSH *DSH) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Compression d'un segment de données */ /*------------------------------------------------------------------------------*/ + size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) { size_t Total_Compress = 0; @@ -3387,6 +3779,7 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) void *DSH_End; int Found = FALSE; + DSH_End = (void *)((size_t)(DSH->Start) + DSH->Size); /* Recherche du premier chunk libre contenu dans le segment courant */ @@ -3439,20 +3832,27 @@ size_t SM_DataSegment_Compress ( SMT_DSH *DSH, NDT_Root *FCR) return Total_Compress; } + + + + /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ /* Fonction de gestion de chunks */ /*------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------*/ + + /*------------------------------------------------------------------------------*/ /* Fonction manager pour un ACR (Allocated Chunk Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_ACR_Manager (va_list Args) { NDT_Command Command = (NDT_Command)va_arg (Args, NDT_Command); - if (Command == NDD_CMD_SUM_VALUES) + if (Command == SMD_CMD_VALUE_SUM) { SMT_Chunk * Chunk = (SMT_Chunk *)va_arg (Args, void *); int * Total_Size = (int *)va_arg (Args, int *); @@ -3462,7 +3862,7 @@ NDT_Status SM_ACR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_PRINT_VALUE) + if (Command == NDD_CMD_VALUE_PRINT) { SMT_Chunk *Chunk = (SMT_Chunk *)va_arg (Args, void *); FILE * Out = va_arg (Args, FILE *); @@ -3472,7 +3872,7 @@ NDT_Status SM_ACR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_PRINT_INFO) + if (Command == NDD_CMD_INFO_PRINT) { NDT_Root * Root = va_arg (Args, NDT_Root *); FILE * Out = va_arg (Args, FILE *); @@ -3482,7 +3882,7 @@ NDT_Status SM_ACR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_COMP_VALUE) + if (Command == NDD_CMD_VALUE_COMP) { int comp; SMT_Chunk *Chunk1 = (SMT_Chunk *)va_arg (Args, void *); @@ -3502,14 +3902,19 @@ NDT_Status SM_ACR_Manager (va_list Args) return NDS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Fonction manager pour un FCR (Free Chunk Root) */ /*------------------------------------------------------------------------------*/ + NDT_Status SM_FCR_Manager (va_list Args) { NDT_Command Command = (NDT_Command)va_arg (Args, NDT_Command); - if (Command == NDD_CMD_SUM_VALUES) + if (Command == SMD_CMD_VALUE_SUM) { SMT_Chunk * Chunk = (SMT_Chunk *)va_arg (Args, void *); int * Total_Size = (int *)va_arg (Args, int *); @@ -3519,7 +3924,7 @@ NDT_Status SM_FCR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_PRINT_VALUE) + if (Command == NDD_CMD_VALUE_PRINT) { SMT_Chunk * Chunk = (SMT_Chunk *)va_arg (Args, void *); FILE * Out = va_arg (Args, FILE *); @@ -3529,7 +3934,7 @@ NDT_Status SM_FCR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_PRINT_INFO) + if (Command == NDD_CMD_INFO_PRINT) { NDT_Root * Root = va_arg (Args, NDT_Root *); FILE * Out = va_arg (Args, FILE *); @@ -3539,7 +3944,7 @@ NDT_Status SM_FCR_Manager (va_list Args) return NDS_OK; } - if (Command == NDD_CMD_COMP_VALUE) + if (Command == NDD_CMD_VALUE_COMP) { int comp; SMT_Chunk *Chunk1 = (SMT_Chunk *)va_arg (Args, void *); @@ -3548,8 +3953,8 @@ NDT_Status SM_FCR_Manager (va_list Args) va_end (Args); /* - La comparaison des chunks libres porte sur le champ - pour faciliter la compression des heaps. + La comparaison des chunks libres porte sur le champ + pour faciliter la compression des heaps. */ comp = (unsigned int)(Chunk1->Data) - (unsigned int)(Chunk2->Data); @@ -3562,9 +3967,14 @@ NDT_Status SM_FCR_Manager (va_list Args) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Pose d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; @@ -3596,9 +4006,14 @@ SMT_Status SM_Heap_Lock_Set ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Changement d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; @@ -3606,11 +4021,11 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) if (Lock_Mode & SMD_WRITE) { /* - Attention : il ne faut pas tenter de transformer directement un verrou en lecture en - un verrou en écriture car cela pourrait aboutir à un deadlock entre deux processus - qui voudraient réaliser cette opération en même temps. + Attention : il ne faut pas tenter de transformer directement un verrou en lecture en + un verrou en écriture car cela pourrait aboutir à un deadlock entre deux processus + qui voudraient réaliser cette opération en même temps. - => On passe donc par un déverrouillage intermédiaire. + => On passe donc par un déverrouillage intermédiaire. */ if ((rc = SM_Semaphore_Operate (MHH->SemID, SM_SemOp_RSL, 2)) != SMS_OK) @@ -3648,9 +4063,14 @@ SMT_Status SM_Heap_Lock_Change ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Libération d'un verrou sur un heap */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) { SMT_Status rc; @@ -3682,9 +4102,14 @@ SMT_Status SM_Heap_Lock_Release ( SMT_MHH * MHH, SMT_Flags Lock_Mode ) return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Opération sur un sémaphore */ /*------------------------------------------------------------------------------*/ + SMT_Status SM_Semaphore_Operate (int SemID, struct sembuf * Operations, unsigned int Nb_Oper) { if (semop (SemID, Operations, Nb_Oper) == -1) @@ -3734,9 +4159,14 @@ SMT_Status SM_Semaphore_Operate (int SemID, struct sembuf * Operations, unsigned return SMS_OK; } + + + + /*------------------------------------------------------------------------------*/ /* Récupère sous forme explicite l'état d'un verrou */ /*------------------------------------------------------------------------------*/ + char * SM_Lock_Status_Get ( const char * Type, void * Struct) { static char Status [50]; @@ -3785,55 +4215,49 @@ char * SM_Lock_Status_Get ( const char * Type, void * Struct) return Status; } + + + + /*------------------------------------------------------------------------------*/ /* Récupère sous forme explicite la description d'une racine de structure */ /*------------------------------------------------------------------------------*/ + char * SM_Root_Description_Get ( const char * Root_Label, NDT_Root * Root ) { - char * Root_Type; static char Root_Info [256]; - switch ((int)(Root->Type & NDD_DS_MSK)) - { - case NDD_DS_LIST : - switch ((int)(Root->Type & NDD_MN_MSK)) - { - case NDD_MN_ORDERED : Root_Type = "ordered list"; break; - case NDD_MN_FILO : Root_Type = "FILO list"; break; - case NDD_MN_FIFO : Root_Type = "FIFO list"; break; - default : Root_Type = "unknown"; break; - } - break; + sprintf (Root_Info, "%s :\n\t- Structure type = %s:%s\n\t- Node number = %ld\n", + Root_Label, + ND_INDEX_TYPE_ASCII_GET( Root, NDD_INDEX_PRIMARY), + ND_INDEX_SUBTYPE_ASCII_GET( Root, NDD_INDEX_PRIMARY), + Root->Index_Tab[NDD_INDEX_PRIMARY].Node_Number); - case NDD_DS_TREE : - - switch ((int)(Root->Type & NDD_MN_MSK)) - { - case NDD_MN_AUTO_EQU : Root_Type = "auto-equalized tree"; break; - default : Root_Type = "non-auto-equalized tree"; break; - } - break; - - default : Root_Type = "unknown"; break; - } - - sprintf (Root_Info, "%s :\n\t- Structure type = %s\n\t- Node number = %ld\n", Root_Label, Root_Type, Root->Node_Number); - - return Root_Info; + return( Root_Info); } + + + + /*------------------------------------------------------------------------------*/ /* Routine d'affichage d'un message d'erreur */ /*------------------------------------------------------------------------------*/ + void SM_Error_Print ( void ) { if (SM_stderr) fprintf (SM_stderr, "Error %s\n", SM_Error_Msg); } + + + + /*------------------------------------------------------------------------------*/ /* Pour préfixer un nom de heap avec le nom du contexte d'utilisation */ /*------------------------------------------------------------------------------*/ + static char * SM_Name_Prefix ( const char * Name) { static char Prefixed [256]; diff --git a/lib/libshmem.h b/lib/libshmem.h index 8f55482..df7ebca 100644 --- a/lib/libshmem.h +++ b/lib/libshmem.h @@ -1,19 +1,59 @@ +/*---------------------------------------------------------------------------------*/ +/* $RCSfile: libshmem.h,v $ */ +/*---------------------------------------------------------------------------------*/ +/* $Revision: 2.0 $ */ +/* $Name: $ */ +/* $Date: 2005/01/24 22:57:06 $ */ +/* $Author: agibert $ */ +/*---------------------------------------------------------------------------------*/ + +/*---------------------------------------------------------------------------------*/ +/* This file is part of LibShMem */ +/* */ +/* LibShMem is free software; you can redistribute it and/or modify */ +/* it under the terms of the GNU Lesser General Public Licence as published by */ +/* the Free Software Foundation; either version 2.1 of the License, or */ +/* (at your option) any later version. */ +/* */ +/* LibShMem is distributed in the hope that it will be useful, */ +/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ +/* GNU Lesser General Public License for more details. */ +/* */ +/* You should have received a copy of the GNU Lesser General Public License */ +/* along with LibShMem; if not, write to the Free Software */ +/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +/*---------------------------------------------------------------------------------*/ + + + + + #include #include +#include #include #include #include -#include + #include #include #include -#include + #include + + + + + + + /* Compteur d'ouverture de la librairie */ unsigned int SM_Open_Counter = 0; + /* Flux de sortie des messages d'erreur générés par la librairie */ FILE * SM_stderr; @@ -22,10 +62,15 @@ extern char * strdup (const char *); #define max(A,B) ((A < B) ? B : A) + /* Limite supérieure d'adressage */ #define MEM_LIMIT 1000000000 + +#define SMD_CMD_VALUE_SUM (NDT_Command)65 + + /* Taille d'un segment = 100 Ko par défaut */ #define K 1024 @@ -34,10 +79,11 @@ extern char * strdup (const char *); char Info_Msg [256]; + /* Etats possibles pour un heap */ #define SMD_STATE_VALID 0 -#define SMD_STATE_UNVALIDATED 1 +#define SMD_STATE_UNVALIDATED 1 #define SMD_STATE_CORRUPTED 2 /* Référence sur le heap système */ @@ -49,17 +95,17 @@ SMT_Heap * System_Heap; NDT_Root * Opened_Heap_List; /* - Taille par défaut des chunks alloués dans le heap système : - Cette taille est fixée à la taille maximale des chunks pouvant - y être alloué (de type NDT_Node, NDT_Root, SMT_MHH ou SMT_DSH) + Taille par défaut des chunks alloués dans le heap système : + Cette taille est fixée à la taille maximale des chunks pouvant + y être alloué (de type NDT_Node, NDT_Root, SMT_MHH ou SMT_DSH) */ #define DEFAULT_CHUNK_SIZE max(max(sizeof(NDT_Root), sizeof(NDT_Node)), max(sizeof(SMT_MHH), sizeof(SMT_DSH))) /* - Nombre de chunk libre minimum avant extension du heap système par un - nouveau segment de données (fixé à 3 car l'ajout d'un nouveau segment - nécessite l'allocation de 2 chunks (un noeud et une entête de segment). + Nombre de chunk libre minimum avant extension du heap système par un + nouveau segment de données (fixé à 3 car l'ajout d'un nouveau segment + nécessite l'allocation de 2 chunks (un noeud et une entête de segment). */ #define FREE_CHUNK_LIMIT 3 @@ -76,8 +122,8 @@ char * SM_Context; #define CONTEXT_ENV_VAR "CONTEXT" /* - Variable globale permettant d'indiquer que l'on est en train - d'étendre le heap système par ajout d'un nouveau segment. + Variable globale permettant d'indiquer que l'on est en train + d'étendre le heap système par ajout d'un nouveau segment. */ unsigned int Adding_Segment = FALSE; @@ -86,8 +132,8 @@ SMT_Chunk * Tmp_Chunk; SMT_MHH * Tmp_MHH; /* - Définition des opérations de verouillage et de déverrouillage - NB : la valeur 1 d'un sémaphore correspond à l'état non verrouillé + Définition des opérations de verouillage et de déverrouillage + NB : la valeur 1 d'un sémaphore correspond à l'état non verrouillé */ /* Pose d'un verrou en lecture : 2 opérations : ( -1 puis +2 ) */ @@ -112,9 +158,9 @@ struct sembuf SM_SemOp_TSL [2] = { {0, 0, SEM_UNDO|IPC_NOWAIT}, {0, 2, SEM_UNDO typedef union semun { - int val; - struct semid_ds * buf; - unsigned short int * array; + int val; + struct semid_ds * buf; + unsigned short int * array; } semun; /*------------------------------------------------------------------------------*/