libshmem/lib/libshmem.h

395 lines
14 KiB
C
Raw Normal View History

/*----------------------------------------------------------------------------*/
/* libshmem.h */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/* 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 License as published */
/* by the Free Software Foundation, either version 3 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 Drummer. If not, see */
/* <https://www.gnu.org/licenses/>. */
/*----------------------------------------------------------------------------*/
2024-04-18 00:54:07 +02:00
/*----------------------------------------------------------------------------*/
/* Includes */
/*----------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
2000-07-28 16:13:54 +02:00
#include <string.h>
#include <unistd.h>
#include <errno.h>
2000-07-28 16:13:54 +02:00
#include <sys/sem.h>
#include <sys/shm.h>
#include <sys/ipc.h>
2000-07-28 16:13:54 +02:00
#include <shmem.h>
2024-04-18 00:54:07 +02:00
/*----------------------------------------------------------------------------*/
/* Definitions */
/*----------------------------------------------------------------------------*/
#define LGD_MODULE_NAME "sm"
2000-07-28 16:13:54 +02:00
/* Compteur d'ouverture de la librairie */
unsigned int SM_Open_Counter = 0;
2000-07-28 16:13:54 +02:00
/* Flux de sortie des messages d'erreur g<>n<EFBFBD>r<EFBFBD>s par la librairie */
FILE * SM_stderr;
extern char * strdup (const char *);
#define max(A,B) ((A < B) ? B : A)
2000-07-28 16:13:54 +02:00
/* Limite sup<75>rieure d'adressage */
#define MEM_LIMIT 1000000000
//#define SMD_CMD_VALUE_SUM (NDT_Command)65
#define NDD_CMD_VALUE_SUM (NDT_Command)NDD_CMD_USER_TRAVERSE
2000-07-28 16:13:54 +02:00
/* Taille d'un segment = 100 Ko par d<>faut */
#define K 1024
#define NB_BLOCS 100
#define SEGMENT_DEFAULT_SIZE NB_BLOCS * K
char Info_Msg [256];
2000-07-28 16:13:54 +02:00
/* Etats possibles pour un heap */
#define SMD_STATE_VALID 0
#define SMD_STATE_UNVALIDATED 1
2000-07-28 16:13:54 +02:00
#define SMD_STATE_CORRUPTED 2
/* R<>f<EFBFBD>rence sur le heap syst<73>me */
SMT_Heap * System_Heap;
/* Liste des heaps ouverts par le processus courant */
NDT_Root * Opened_Heap_List;
2000-07-28 16:13:54 +02:00
/*
Taille par d<EFBFBD>faut des chunks allou<EFBFBD>s dans le heap syst<EFBFBD>me :
Cette taille est fix<EFBFBD>e <EFBFBD> la taille maximale des chunks pouvant
y <EFBFBD>tre allou<EFBFBD> (de type NDT_Node, NDT_Root, SMT_MHH ou SMT_DSH)
2000-07-28 16:13:54 +02:00
*/
#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<EFBFBD>me par un
nouveau segment de donn<EFBFBD>es (fix<EFBFBD> <EFBFBD> 3 car l'ajout d'un nouveau segment
n<EFBFBD>cessite l'allocation de 2 chunks (un noeud et une ent<EFBFBD>te de segment).
2000-07-28 16:13:54 +02:00
*/
#define FREE_CHUNK_LIMIT 3
2000-07-28 16:13:54 +02:00
int SM_Instance;
char * SM_Context;
/* Contexte et instance d'utilisation de la librairie */
#define DEFAULT_INSTANCE 1000
#define INSTANCE_ENV_VAR "INSTANCE"
#define DEFAULT_CONTEXT "CTX"
#define CONTEXT_ENV_VAR "CONTEXT"
/*
Variable globale permettant d'indiquer que l'on est en train
d'<EFBFBD>tendre le heap syst<EFBFBD>me par ajout d'un nouveau segment.
2000-07-28 16:13:54 +02:00
*/
unsigned int Adding_Segment = FALSE;
SMT_Chunk * Tmp_Chunk;
SMT_MHH * Tmp_MHH;
/*
D<EFBFBD>finition des op<EFBFBD>rations de verouillage et de d<EFBFBD>verrouillage
NB : la valeur 1 d'un s<EFBFBD>maphore correspond <EFBFBD> l'<EFBFBD>tat non verrouill<EFBFBD>
2000-07-28 16:13:54 +02:00
*/
/* Pose d'un verrou en lecture : 2 op<6F>rations : ( -1 puis +2 ) */
struct sembuf SM_SemOp_SSL [2] = { {0, -1, SEM_UNDO}, {0, 2, SEM_UNDO} };
/* Lib<69>ration d'un verrou en lecture : 2 op<6F>rations ( -2 puis +1 ) */
struct sembuf SM_SemOp_RSL [2] = { {0, -2, SEM_UNDO|IPC_NOWAIT}, {0, 1, SEM_UNDO|IPC_NOWAIT} };
/* Pose d'un verrou en <20>criture : 2 op<6F>rations ( -1 puis 0 ) */
struct sembuf SM_SemOp_SEL [2] = { {0, -1, SEM_UNDO}, {0, 0, SEM_UNDO} };
/* Lib<69>ration d'un verrou en <20>criture : 2 op<6F>rations ( 0 puis +1 ) */
struct sembuf SM_SemOp_REL [2] = { {0, 0, SEM_UNDO|IPC_NOWAIT}, {0, 1, SEM_UNDO|IPC_NOWAIT} };
/* Transformation d'un verrou en <20>criture en un verrou en lecture : 2 op<6F>rations ( 0 puis +2 ) */
struct sembuf SM_SemOp_TSL [2] = { {0, 0, SEM_UNDO|IPC_NOWAIT}, {0, 2, SEM_UNDO|IPC_NOWAIT} };
typedef union semun
{
int val;
struct semid_ds * buf;
unsigned short int * array;
2000-07-28 16:13:54 +02:00
} semun;
/*------------------------------------------------------------------------------*/
/* */
/*------------------------------------------------------------------------------*/
#define SM_LIBSHMEM_OPEN_CHECK() if( !SM_Base) { LG_LOG_ERROR_0( "LibShMem library is not open"); return( SMS_ERRAPI); }
#define SM_HEAP_NAME_CHECK(ptr) if( !(ptr)) { LG_LOG_ERROR_0( "Heap name is undefined"); return( SMS_ERRAPI); }
#define SM_HEAP_CHECK( ptr) if( !(ptr)) { LG_LOG_ERROR_0( "Heap is undefined"); return( SMS_ERRAPI); }
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Allocation de m<>moire dans la base */
/*------------------------------------------------------------------------------*/
NDT_Status SM_Base_Alloc( void **, size_t, void *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<>sallocation de m<>moire dans la base */
/*------------------------------------------------------------------------------*/
NDT_Status SM_Base_Free( void *, void *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Allocation de m<>moire dans le heap syst<73>me */
/*------------------------------------------------------------------------------*/
NDT_Status SM_System_Alloc( void **, size_t, void *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* D<>sallocation de m<>moire dans le heap syst<73>me */
/*------------------------------------------------------------------------------*/
NDT_Status SM_System_Free( void *, void *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Initialisation de la base */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Init (void);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Terminaison de la base */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_End (void);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture de la base */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Open (void);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture de la base */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Close (void);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur la base : */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Lock (SMT_Flags);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69>ration d'un verrou sur la base : */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Base_Unlock (SMT_Flags);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager de la liste des heaps ouverts */
/*------------------------------------------------------------------------------*/
NDT_Status SM_Opened_Heap_List_Manager ( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager du MHR (Memory Heap Root) */
/*------------------------------------------------------------------------------*/
NDT_Status MHR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Destruction d'un MHH (Memory Heap Header) */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_MHH_End (SMT_MHH *);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un DSR (Data Segment Root) */
/*------------------------------------------------------------------------------*/
NDT_Status SM_DSR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Ouverture d'un segment de donn<6E>es */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_DataSegment_Open (SMT_DSH *);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fermeture d'un segment de donn<6E>es */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_DataSegment_Close (SMT_DSH *);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Compression d'un segment de donn<6E>es */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
size_t SM_DataSegment_Compress (SMT_DSH *, NDT_Root *);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un ACR (Allocated Chunk Root) */
/*------------------------------------------------------------------------------*/
NDT_Status SM_ACR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Fonction manager pour un FCR (Free Chunk Root) */
/*------------------------------------------------------------------------------*/
NDT_Status SM_FCR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Pose d'un verrou sur un heap : */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Heap_Lock_Set (SMT_MHH *, SMT_Flags);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Changement d'un verrou sur un heap : */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Heap_Lock_Change (SMT_MHH *, SMT_Flags);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Lib<69>ration d'un verrou sur un heap : */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Heap_Lock_Release (SMT_MHH *, SMT_Flags);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Op<4F>ration sur un s<>maphore */
/*------------------------------------------------------------------------------*/
2000-07-28 16:13:54 +02:00
SMT_Status SM_Semaphore_Operate (int, struct sembuf *, unsigned int);
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* R<>cup<75>re sous forme explicite l'<27>tat d'un verrou */
/*------------------------------------------------------------------------------*/
char * SM_Lock_Status_Get (const char *, void *);
2000-07-28 16:13:54 +02:00
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* Add context prefix to heap name */
2000-07-28 16:13:54 +02:00
/*------------------------------------------------------------------------------*/
/* (O) Prefixed: Prefixed heap name */
/* (I) Unprefixed: Unprefixed heap name */
/*------------------------------------------------------------------------------*/
SMT_Status SM_Name_Prefix( char *, const char *);
2024-04-18 00:54:07 +02:00
/*------------------------------------------------------------------------------*/