Initial support for LibNode 2.1.x.

Not working version...
Update revision number to 2.0 !
This commit is contained in:
agibert 2005-01-24 22:57:06 +00:00
parent 626c9e80f1
commit bb73fb28cc
3 changed files with 1099 additions and 598 deletions

View File

@ -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,7 +90,7 @@ 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 */
@ -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,7 +174,7 @@ char SM_Error_Msg [512];
/* Structure de la base de heaps */
/*------------------------------------------------------------------------------*/
typedef struct {
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 */
@ -154,18 +185,18 @@ typedef struct {
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;
} 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 {
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 */
@ -176,37 +207,37 @@ typedef struct {
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;
} SMT_MHH;
/* Heap ouvert */
typedef struct {
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;
} SMT_Heap;
/*------------------------------------------------------------------------------*/
/* Structure d'un DSH (Data Segment Header) */
/* Rappel : un DSH est une valeur attachée à un DSN (noeud de DSR) */
/*------------------------------------------------------------------------------*/
typedef struct {
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;
} SMT_DSH;
/*------------------------------------------------------------------------------*/
/* Structure d'un chunk */
/* Rappel : un chunk est la valeur attachée à un noeud de ACR ou FCR */
/*------------------------------------------------------------------------------*/
typedef struct {
typedef struct {
size_t Size; /* Taille allouée au chunk */
void * Data; /* Adresse de la zone de données du chunk */
} SMT_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
}

File diff suppressed because it is too large Load Diff

View File

@ -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 <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/ipc.h>
#include <ver.h>
#include <shmem.h>
/* 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,6 +79,7 @@ extern char * strdup (const char *);
char Info_Msg [256];
/* Etats possibles pour un heap */
#define SMD_STATE_VALID 0