Compare commits
10 Commits
8e908f867c
...
0e2be6c11b
Author | SHA1 | Date | |
---|---|---|---|
|
0e2be6c11b | ||
|
998062740e | ||
|
7fb191ce32 | ||
|
168b1818c6 | ||
|
736a074b28 | ||
|
a71fd35b9e | ||
|
193e13bc58 | ||
|
c89aef3694 | ||
|
d956060f49 | ||
|
1f4d73bc70 |
6
Makefile
6
Makefile
@ -1,7 +1,7 @@
|
||||
# $RCSfile: Makefile,v $
|
||||
# $Revision: 1.1 $
|
||||
# $Revision: 1.2 $
|
||||
# $Name: $
|
||||
# $Date: 2005/01/24 23:24:30 $
|
||||
# $Date: 2005/06/26 23:04:11 $
|
||||
# $Author: agibert $
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
@ -10,7 +10,7 @@
|
||||
|
||||
|
||||
|
||||
SUBDIRS := include lib util doc
|
||||
SUBDIRS := include lib util demo doc
|
||||
|
||||
FILE_DOC := *.txt
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# $RCSfile: ReleaseNotes.txt,v $
|
||||
# $Revision: 2.0 $
|
||||
# $Revision: 2.1 $
|
||||
# $Name: $
|
||||
# $Date: 2005/01/24 23:58:23 $
|
||||
# $Date: 2005/06/27 00:17:36 $
|
||||
# $Author: agibert $
|
||||
|
||||
|
||||
@ -9,11 +9,13 @@
|
||||
|
||||
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
LibShMem V 2.0.0 - A. Gibert - xx/02/05
|
||||
LibShMem V 2.0.0 - A. Gibert - xx/06/05
|
||||
------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
All: This new LibShMem branch (2.0.x) support the new LibShMem branch (2.1.x),
|
||||
LibShMem: ...
|
||||
All: This new LibShMem branch (2.0.x) support the new LibNode branch (2.1.x),
|
||||
LibShMem: Add HP-UX 11 support,
|
||||
Improve Manager structure in a more LibNode 2 way,
|
||||
SMDemo0: Add a new demo !
|
||||
|
||||
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
SRC := smdemo0.c
|
||||
TARGETS := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c
|
||||
FILE_BIN := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c
|
||||
SRC := smdemo0.c smdemo0_snd.c smdemo0_rcv.c
|
||||
TARGETS := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c \
|
||||
smdemo0_snd smdemo0_snd-c smdemo0_snd-static smdemo0_snd-static-c \
|
||||
smdemo0_rcv smdemo0_rcv-c smdemo0_rcv-static smdemo0_rcv-static-c
|
||||
FILE_BIN := smdemo0 smdemo0-c smdemo0-static smdemo0-static-c \
|
||||
smdemo0_snd smdemo0_snd-c smdemo0_snd-static smdemo0_snd-static-c \
|
||||
smdemo0_rcv smdemo0_rcv-c smdemo0_rcv-static smdemo0_rcv-static-c
|
||||
FILE_LIB := smdemo0.dat
|
||||
|
||||
|
||||
@ -10,12 +14,12 @@ include ../Makefile.rule
|
||||
|
||||
|
||||
|
||||
DEP_STATIC += ../lib/libnode.a
|
||||
DEP_DYNAMIC += ../lib/libnode.so
|
||||
INCLUDE += -I . -I ../include
|
||||
LIBDIR += -L . -L ../lib
|
||||
LIB_STATIC += ../lib/libnode.a -ldl
|
||||
LIB_DYNAMIC += -lnode -ldl
|
||||
DEP_STATIC += ../lib/libshmem.a ../../libnode/lib/libnode.a
|
||||
DEP_DYNAMIC += ../lib/libshmem.so ../../libnode/lib/libnode.so
|
||||
INCLUDE += -I . -I ../include -I ../../libnode/include
|
||||
LIBDIR += -L . -L ../lib -L ../../libnode/lib
|
||||
LIB_STATIC += ../lib/libshmem.a ../../libnode/lib/libnode.a -ldl
|
||||
LIB_DYNAMIC += -lshmem -lnode -ldl
|
||||
CFLAGS += -rdynamic
|
||||
|
||||
ifdef _LIBVER_SUPPORT
|
||||
@ -52,3 +56,26 @@ smdemo0-static: smdemo0.c $(DEP_STATIC)
|
||||
smdemo0-static-c: smdemo0.c $(DEP_STATIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
|
||||
|
||||
smdemo0_snd: smdemo0_snd.c $(DEP_DYNAMIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
|
||||
|
||||
smdemo0_snd-c: smdemo0_snd.c $(DEP_DYNAMIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
|
||||
|
||||
smdemo0_snd-static: smdemo0_snd.c $(DEP_STATIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
|
||||
|
||||
smdemo0_snd-static-c: smdemo0_snd.c $(DEP_STATIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
|
||||
|
||||
smdemo0_rcv: smdemo0_rcv.c $(DEP_DYNAMIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
|
||||
|
||||
smdemo0_rcv-c: smdemo0_rcv.c $(DEP_DYNAMIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $(LIBDIR) $(LIB_DYNAMIC) $<
|
||||
|
||||
smdemo0_rcv-static: smdemo0_rcv.c $(DEP_STATIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_NOCHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
|
||||
|
||||
smdemo0_rcv-static-c: smdemo0_rcv.c $(DEP_STATIC)
|
||||
$(CC) -o $@ $(CFLAGS) $(ND_CHECK_FLAGS) $(INCLUDE) $< $(LIB_STATIC)
|
||||
|
380
demo/smdemo0.c
Normal file
380
demo/smdemo0.c
Normal file
@ -0,0 +1,380 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: smdemo0.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2005/06/26 23:16:38 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is a program test 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 <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
|
||||
#include <node.h>
|
||||
|
||||
|
||||
#ifndef SM_MODE
|
||||
# define SM_MODE 0 /* Utilisation des API sécurisés */
|
||||
#endif
|
||||
|
||||
#include <shmem.h>
|
||||
|
||||
|
||||
|
||||
#define LOG_ERROR 10
|
||||
#define LOG_WARNING 20
|
||||
#define LOG_INFO 30
|
||||
#define LOG_TRACE 40
|
||||
|
||||
#define FATHER_ID 0
|
||||
|
||||
#define SON_SND_ID 1
|
||||
#define SON_SND_NAME "snd"
|
||||
|
||||
#define SON_RCV_ID 2
|
||||
#define SON_RCV_NAME "rcv"
|
||||
|
||||
|
||||
|
||||
#define INST_MAX 256
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Log_Print( int, int, int, int, char *, ...);
|
||||
|
||||
int Do_Fork_Exec( char **, int, int, int, int *, int);
|
||||
|
||||
void Make_Son_Cmd_Name( char *, char *, char *);
|
||||
|
||||
int main( int , char **);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Log_Print( int Log_Level, int Verbose_Level, int Proc_Id, int Inst_Id, char *Format_Str, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *prompt[] = { "father", "snd", "rcv"};
|
||||
int fmt_size = 255;
|
||||
char fmt[ fmt_size + 1];
|
||||
|
||||
|
||||
if( Log_Level <= Verbose_Level)
|
||||
{
|
||||
va_start( args, Format_Str);
|
||||
|
||||
if( Proc_Id == FATHER_ID)
|
||||
{
|
||||
snprintf( fmt, fmt_size, "%s: %s", prompt[Proc_Id], Format_Str);
|
||||
}
|
||||
else
|
||||
{
|
||||
snprintf( fmt, fmt_size, "%s%02d : %s", prompt[Proc_Id], Inst_Id, Format_Str);
|
||||
}
|
||||
|
||||
vfprintf( stderr, fmt, args);
|
||||
fflush( stderr);
|
||||
|
||||
va_end( args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int Do_Fork_Exec( char **ArgV_Tab, int Proc_Id, int Inst_Id, int Dir, int Pipe_Desc[2], int Verbose_Level)
|
||||
{
|
||||
pid_t pid;
|
||||
int rc;
|
||||
char cmd[1024] = "";
|
||||
int i;
|
||||
|
||||
|
||||
for( i = 0; ArgV_Tab[i] != NULL; i++)
|
||||
{
|
||||
if( i > 0)
|
||||
{
|
||||
strcat( cmd, " ");
|
||||
}
|
||||
|
||||
strcat( cmd, ArgV_Tab[i]);
|
||||
}
|
||||
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Forking Inst_Id: (%d) Dir: (%d) Cmd: [%s]...\n", Inst_Id, Dir, cmd);
|
||||
|
||||
switch( pid = fork())
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
Log_Print( LOG_INFO, Verbose_Level, Proc_Id, Inst_Id, "PId: (%d) PPId: (%d) Exec_File: [%s]\n", getpid(), getppid(), ArgV_Tab[0]);
|
||||
|
||||
if( ( rc = close( Pipe_Desc[ 1 - Dir])) == -1)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Proc_Id, Inst_Id, "close() failed: (%d) !\n", errno);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
if( ( rc = dup2( Pipe_Desc[ Dir], Dir)) == -1)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Proc_Id, Inst_Id, "dup2() failed: (%d) !\n", errno);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
if( ( rc = execv( ArgV_Tab[0], ArgV_Tab)) == -1)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Proc_Id, Inst_Id, "execv() failed: (%d) !\n", errno);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
case -1:
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, Inst_Id, "fork() failed: (%d) !\n", errno);
|
||||
|
||||
return( -1);
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
Log_Print( LOG_INFO, Verbose_Level, FATHER_ID, Inst_Id, "PId: (%d) Son_PId: (%d)\n", getpid(), pid);
|
||||
|
||||
return( 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Make_Son_Cmd_Name( char *Son_Cmd_Name, char *Father_Cmd_Name, char *Son_Name)
|
||||
{
|
||||
char *ptr;
|
||||
|
||||
|
||||
if( ( ptr = strstr( Father_Cmd_Name, "-")) == NULL)
|
||||
{
|
||||
ptr = Father_Cmd_Name + strlen( Father_Cmd_Name);
|
||||
}
|
||||
|
||||
strncpy( Son_Cmd_Name, Father_Cmd_Name, ( ptr - Father_Cmd_Name));
|
||||
Son_Cmd_Name[ ( ptr - Father_Cmd_Name)] = '\0';
|
||||
strcat( Son_Cmd_Name, "_");
|
||||
strcat( Son_Cmd_Name, Son_Name);
|
||||
strcat( Son_Cmd_Name, ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main( int ArgC, char **ArgV)
|
||||
{
|
||||
char *Heap_Name;
|
||||
int Inst_Nb;
|
||||
int Chunk_Nb;
|
||||
size_t Chunk_Size;
|
||||
int Verbose_Level = 30;
|
||||
|
||||
SMT_Heap *heap_ptr;
|
||||
size_t heap_size = 1024;
|
||||
int locked;
|
||||
SMT_Status status;
|
||||
int rc;
|
||||
int pipe_desc[2];
|
||||
pid_t pid;
|
||||
char *ptr;
|
||||
char *argv_tab[10];
|
||||
char son_cmd[256];
|
||||
char inst_id_str[32];
|
||||
char chunk_nb_str[32];
|
||||
char chunk_size_str[32];
|
||||
char verbose_level_str[32];
|
||||
int inst_id;
|
||||
short error = 0;
|
||||
|
||||
|
||||
if( ArgC != 6)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Usage: %s Inst_Nb Heap_Name Chunck_Nb Chunk_Size Verbose_Level\n", ArgV[0]);
|
||||
exit( -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Inst_Nb = atoi( ArgV[1]);
|
||||
Heap_Name = ArgV[2];
|
||||
Chunk_Nb = atoi( ArgV[3]);
|
||||
Chunk_Size = atoi( ArgV[4]);
|
||||
Verbose_Level = atoi( ArgV[5]);
|
||||
|
||||
if( Inst_Nb > INST_MAX)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Inst_Nb: (%d) > (%d) !\n", Inst_Nb, INST_MAX);
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
Log_Print( LOG_INFO, Verbose_Level, FATHER_ID, 0, "Inst_Nb: (%d) Heap_Name: [%s] Chunck_Nb: (%d) Chunck_Size: (%d) Verbose_Level: (%d)...\n",
|
||||
Inst_Nb, Heap_Name, Chunk_Nb, Chunk_Size, Verbose_Level);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( ( status = SM_Library_Open( 0, NULL, ( SMD_OPEN | SMD_DEBUG_ALL))) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't open LibShMem (%d) !\n", status);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "LibShMem opened !\n");
|
||||
|
||||
if( ( status = SM_Heap_Open( Heap_Name, &heap_ptr, heap_size, ( SMD_OPEN | SMD_CREATE | SMD_NO_LOCK), &locked)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't create heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Heap opened !\n");
|
||||
|
||||
for( inst_id = 0, error = 0; ( inst_id < Inst_Nb) && ( error == 0); inst_id++)
|
||||
{
|
||||
if( pipe( pipe_desc) == -1)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Con't open pipe (%d) !\n", errno);
|
||||
error = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
argv_tab[0] = son_cmd;
|
||||
Make_Son_Cmd_Name( argv_tab[0], ArgV[0], SON_SND_NAME);
|
||||
|
||||
argv_tab[1] = inst_id_str;
|
||||
sprintf( argv_tab[1], "%d", inst_id);
|
||||
|
||||
argv_tab[2] = Heap_Name;
|
||||
|
||||
argv_tab[3] = chunk_nb_str;
|
||||
sprintf( argv_tab[3], "%d", Chunk_Nb);
|
||||
|
||||
argv_tab[4] = chunk_size_str;
|
||||
sprintf( argv_tab[4], "%d", Chunk_Size);
|
||||
|
||||
argv_tab[5] = verbose_level_str;
|
||||
sprintf( argv_tab[5], "%d", Verbose_Level);
|
||||
|
||||
argv_tab[6] = NULL;
|
||||
|
||||
if( Do_Fork_Exec( argv_tab, SON_SND_ID, inst_id, 1, pipe_desc, Verbose_Level) == -1)
|
||||
{
|
||||
error = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
argv_tab[0] = son_cmd;
|
||||
Make_Son_Cmd_Name( argv_tab[0], ArgV[0], SON_RCV_NAME);
|
||||
|
||||
argv_tab[1] = inst_id_str;
|
||||
sprintf( argv_tab[1], "%d", inst_id);
|
||||
|
||||
argv_tab[2] = Heap_Name;
|
||||
|
||||
argv_tab[3] = verbose_level_str;
|
||||
sprintf( argv_tab[3], "%d", Verbose_Level);
|
||||
|
||||
argv_tab[4] = NULL;
|
||||
|
||||
if( Do_Fork_Exec( argv_tab, SON_RCV_ID, inst_id, 0, pipe_desc, Verbose_Level) == -1)
|
||||
{
|
||||
error = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( rc = close( pipe_desc[ 0])) == -1)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "close() pipe[0] failed: (%d)\n", errno);
|
||||
}
|
||||
|
||||
if( ( rc = close( pipe_desc[ 1])) == -1)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "close() pipe[1] failed: (%d)\n", errno);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( error == 0)
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Waiting sons to complet...\n");
|
||||
|
||||
for( inst_id = 0; inst_id < ( Inst_Nb * 2); inst_id++)
|
||||
{
|
||||
pid = wait( NULL);
|
||||
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Son PId: (%d) exited !\n", pid);
|
||||
}
|
||||
}
|
||||
|
||||
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't lock heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( status = SM_Heap_Close( heap_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't close heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "Heap closed !\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ( status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, FATHER_ID, 0, "Can't close LibShMem (%d) !\n", status);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, FATHER_ID, 0, "LibShMem closed !\n");
|
||||
}
|
||||
|
||||
exit( 0);
|
||||
}
|
204
demo/smdemo0_rcv.c
Normal file
204
demo/smdemo0_rcv.c
Normal file
@ -0,0 +1,204 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: smdemo0_rcv.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2005/06/26 23:16:38 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is a program test 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 <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <node.h>
|
||||
|
||||
#ifndef SM_MODE
|
||||
# define SM_MODE 0 /* Utilisation des API sécurisés */
|
||||
#endif
|
||||
|
||||
#include <shmem.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LOG_ERROR 10
|
||||
#define LOG_WARNING 20
|
||||
#define LOG_INFO 30
|
||||
#define LOG_TRACE 40
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Log_Print( int, int, int, char *, ...);
|
||||
|
||||
int main( int, char **);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Log_Print( int Log_Level, int Verbose_Level, int Inst_Id, char *Format_Str, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *prompt = "rcv";
|
||||
int fmt_size = 255;
|
||||
char fmt[fmt_size + 1];
|
||||
|
||||
|
||||
if( Log_Level <= Verbose_Level)
|
||||
{
|
||||
va_start( args, Format_Str);
|
||||
|
||||
snprintf( fmt, fmt_size, "%s%02d : %s", prompt, Inst_Id, Format_Str);
|
||||
vfprintf( stderr, fmt, args);
|
||||
fflush( stderr);
|
||||
|
||||
va_end( args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main( int ArgC, char **ArgV)
|
||||
{
|
||||
int Inst_Id;
|
||||
char *Heap_Name;
|
||||
int Verbose_Level = 30;
|
||||
|
||||
SMT_Heap *heap_ptr;
|
||||
int locked;
|
||||
SMT_Status status = SMS_OK;
|
||||
char *chunk_ptr;
|
||||
int chunk_id = 0;
|
||||
char input_str[100];
|
||||
size_t input_size = 99;
|
||||
|
||||
|
||||
if( ArgC != 4)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, 0, "Usage: %s Inst_Id Heap_Name Verbose_Level\n", ArgV[0]);
|
||||
exit( -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Inst_Id = atoi( ArgV[1]);
|
||||
Heap_Name = ArgV[2];
|
||||
Verbose_Level = atoi( ArgV[3]);
|
||||
|
||||
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Inst_Id: (%d) Heap_Name: [%s] Verbose_Level: (%d)...\n",
|
||||
Inst_Id, Heap_Name, Verbose_Level);
|
||||
fflush( stderr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( ( status = SM_Library_Open( 0, NULL, ( SMD_OPEN | SMD_DEBUG_ALL))) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open LibShMem (%d) !\n", status);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem opened !\n");
|
||||
|
||||
if( ( status = SM_Heap_Open( Heap_Name, &heap_ptr, 0, ( SMD_OPEN | SMD_NO_LOCK), &locked)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap opened !\n");
|
||||
|
||||
while( ( fgets( input_str, input_size, stdin) != NULL) && ( status == SMS_OK))
|
||||
{
|
||||
if( ( chunk_ptr = (char *)atol( input_str)) == NULL)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Garbage on stdin [%s], skiping !\n", input_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Received message: [%s] Id: (%d) Address: (%lu)\n", chunk_ptr, chunk_id, chunk_ptr);
|
||||
|
||||
chunk_id++;
|
||||
|
||||
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( status = SM_Chunk_Free( heap_ptr, chunk_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't free chunk (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Chunk: (%lu) freed !\n", chunk_ptr);
|
||||
|
||||
if( ( status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't unlock heap (%d) !\n", status);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Number of message received: (%d) !\n", chunk_id);
|
||||
|
||||
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( status = SM_Heap_Close( heap_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap closed !\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ( status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close LibShMem (%d) !\n", status);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem closed !\n");
|
||||
}
|
||||
|
||||
exit( 0);
|
||||
}
|
204
demo/smdemo0_snd.c
Normal file
204
demo/smdemo0_snd.c
Normal file
@ -0,0 +1,204 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: smdemo0_snd.c,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 1.1 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2005/06/26 23:16:38 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* This file is a program test 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 <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <node.h>
|
||||
|
||||
#ifndef SM_MODE
|
||||
# define SM_MODE 0 /* Utilisation des API sécurisés */
|
||||
#endif
|
||||
|
||||
#include <shmem.h>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define LOG_ERROR 10
|
||||
#define LOG_WARNING 20
|
||||
#define LOG_INFO 30
|
||||
#define LOG_TRACE 40
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Log_Print( int, int, int, char *, ...);
|
||||
|
||||
int main( int ArgC, char **ArgV);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Log_Print( int Log_Level, int Verbose_Level, int Inst_Id, char *Format_Str, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *prompt = "snd";
|
||||
int fmt_size = 255;
|
||||
char fmt[ fmt_size + 1];
|
||||
|
||||
|
||||
if( Log_Level <= Verbose_Level)
|
||||
{
|
||||
va_start( args, Format_Str);
|
||||
|
||||
snprintf( fmt, fmt_size, "%s%02d : %s", prompt, Inst_Id, Format_Str);
|
||||
vfprintf( stderr, fmt, args);
|
||||
fflush( stderr);
|
||||
|
||||
va_end( args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
int main( int ArgC, char **ArgV)
|
||||
{
|
||||
int Inst_Id;
|
||||
char *Heap_Name;
|
||||
int Chunk_Nb;
|
||||
size_t Chunk_Size;
|
||||
int Verbose_Level = 30;
|
||||
|
||||
SMT_Heap *heap_ptr;
|
||||
size_t heap_size = 1024;
|
||||
int locked;
|
||||
SMT_Status status;
|
||||
char *chunk_ptr;
|
||||
int chunk_id;
|
||||
|
||||
|
||||
if( ArgC != 6)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, 0, "Usage: %s Inst_Id Heap_Name Chunck_Nb Chunk_Size Verbose_Level\n", ArgV[0]);
|
||||
exit( -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Inst_Id = atoi( ArgV[1]);
|
||||
Heap_Name = ArgV[2];
|
||||
Chunk_Nb = atoi( ArgV[3]);
|
||||
Chunk_Size = atoi( ArgV[4]);
|
||||
Verbose_Level = atoi( ArgV[5]);
|
||||
|
||||
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Inst_Id: (%d) Heap_Name: [%s] Chunck_Nb: (%d) Chunck_Size: (%d) Verbose_Level: (%d)...\n",
|
||||
Inst_Id, Heap_Name, Chunk_Nb, Chunk_Size, Verbose_Level);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if( ( status = SM_Library_Open( 0, NULL, ( SMD_OPEN | SMD_DEBUG_ALL))) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open LibShMem (%d) !\n", status);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem opened !\n");
|
||||
|
||||
if( ( status = SM_Heap_Open( Heap_Name, &heap_ptr, heap_size, ( SMD_OPEN | SMD_NO_LOCK), &locked)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't open heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap opened !\n");
|
||||
|
||||
for( chunk_id = 0; ( chunk_id < Chunk_Nb) && ( status == SMS_OK); chunk_id++)
|
||||
{
|
||||
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( status = SM_Chunk_Alloc( heap_ptr, Chunk_Size, (void **)&chunk_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't alloc chunk (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( status = SM_Heap_Unlock( heap_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't unlock heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Chunk allocated !\n");
|
||||
|
||||
snprintf( chunk_ptr, Chunk_Size, "Hello brother: (%d) !", chunk_id);
|
||||
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Message: [%s] writen into the chunk: (%lu)\n", chunk_ptr, chunk_ptr);
|
||||
|
||||
fprintf( stdout, "%lu\n", chunk_ptr);
|
||||
fflush( stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Log_Print( LOG_INFO, Verbose_Level, Inst_Id, "Number of message sendeded: (%d) !\n", chunk_id);
|
||||
|
||||
if( ( ( status = SM_Heap_Lock( heap_ptr, SMD_WRITE, &locked)) != SMS_OK) && ( locked == TRUE))
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't lock heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ( status = SM_Heap_Close( heap_ptr)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close heap (%d) !\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "Heap closed !\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( ( status = SM_Library_Close( SMD_CLOSE)) != SMS_OK)
|
||||
{
|
||||
Log_Print( LOG_ERROR, Verbose_Level, Inst_Id, "Can't close LibShMem (%d) !\n", status);
|
||||
|
||||
exit( -1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log_Print( LOG_TRACE, Verbose_Level, Inst_Id, "LibShMem closed !\n");
|
||||
}
|
||||
|
||||
exit( 0);
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: shmem.h,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 2.2 $ */
|
||||
/* $Revision: 2.3 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2005/02/23 23:31:06 $ */
|
||||
/* $Date: 2005/06/26 23:07:40 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
@ -207,6 +207,7 @@ extern "C" {
|
||||
size_t Segment_Size; /* Taille des segments de mémoire composant le heap */
|
||||
size_t Limit_Size; /* Taille limite du heap (par défaut : pas de limite) */
|
||||
int Auto_Compress; /* Nombre de chunks libres à partir duquel le heap est automatiquement compressé */
|
||||
long Compress_Nb; /* Nomber of time the heap has been compressed */
|
||||
} SMT_MHH;
|
||||
|
||||
/* Heap ouvert */
|
||||
|
925
lib/libshmem.c
925
lib/libshmem.c
File diff suppressed because it is too large
Load Diff
@ -1,9 +1,9 @@
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $RCSfile: libshmem.h,v $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* $Revision: 2.2 $ */
|
||||
/* $Revision: 2.3 $ */
|
||||
/* $Name: $ */
|
||||
/* $Date: 2005/02/23 23:31:06 $ */
|
||||
/* $Date: 2005/06/26 23:02:35 $ */
|
||||
/* $Author: agibert $ */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
|
||||
@ -234,16 +234,6 @@ SMT_Status SM_MHH_End (SMT_MHH *);
|
||||
/*------------------------------------------------------------------------------*/
|
||||
NDT_Status SM_DSR_Manager( NDT_Root *, NDT_Index_Id, NDT_Node *, NDT_Command, va_list);
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* Initialisation d'un nouveau segment de données (noeud du DSR) */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
SMT_DSH *SM_DataSegment_Init (SMT_MHH *, size_t);
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* Terminaison d'un segment de données */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
SMT_Status SM_DataSegment_End (NDT_Root *, SMT_DSH *);
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
/* Ouverture d'un segment de données */
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
107
util/smadmin.c
107
util/smadmin.c
@ -3,10 +3,14 @@
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
#include <node.h>
|
||||
#define SM_MODE 0 /* Utilisation des API sécurisés */
|
||||
|
||||
#ifndef SM_MODE
|
||||
# define SM_MODE 0 /* Utilisation des API sécurisés */
|
||||
#endif
|
||||
|
||||
#include <shmem.h>
|
||||
|
||||
//VER_INFO_EXPORT (smadmin, "$Revision: 2.1 $", "$Name: $", __FILE__, "$Author: agibert $")
|
||||
//VER_INFO_EXPORT (smadmin, "$Revision: 2.3 $", "$Name: $", __FILE__, "$Author: agibert $")
|
||||
|
||||
#define USAGE "Usage : %s [ --help | --version [-v] | --create | --destroy ]\n"
|
||||
|
||||
@ -30,8 +34,15 @@
|
||||
#define ACR_DUMP 17
|
||||
#define FCR_DUMP 18
|
||||
|
||||
#define NAME_LEN 100
|
||||
#define NAME_SIZE ( NAME_LEN + 1)
|
||||
|
||||
#define TMP_LEN 100
|
||||
#define TMP_SIZE ( TMP_LEN + 1)
|
||||
|
||||
char menu [1000];
|
||||
char tmp [100];
|
||||
|
||||
char tmp [TMP_SIZE];
|
||||
|
||||
void init_menu (void);
|
||||
int print_menu (void);
|
||||
@ -39,7 +50,7 @@ int print_menu (void);
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
int choice;
|
||||
char name [100];
|
||||
char name [NAME_SIZE];
|
||||
int Mode, Locked;
|
||||
void * ptr;
|
||||
char answer [10];
|
||||
@ -127,10 +138,14 @@ int main (int argc, char ** argv)
|
||||
|
||||
case MHH_INIT:
|
||||
fprintf (stdout, "\nNew heap name ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
fprintf (stdout, "\nHeap segment size ? ");
|
||||
gets (tmp);
|
||||
size = atoi (tmp);
|
||||
fgets( tmp, NAME_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
size = atol (tmp);
|
||||
fprintf (stdout, "\nReturn code = %s\n", \
|
||||
SM_Heap_Open (name, &Heap, size, \
|
||||
SMD_CREATE, &Locked) == SMS_OK ? "OK" : "NOK" );
|
||||
@ -138,9 +153,13 @@ int main (int argc, char ** argv)
|
||||
|
||||
case MHH_OPEN:
|
||||
fprintf (stdout, "\nHeap name to open ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
fprintf (stdout, "\nOpening mode (read=1 write=2) ? ");
|
||||
gets (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
if (tmp[0] == '1') Mode = SMD_READ;
|
||||
else Mode = SMD_WRITE;
|
||||
if (!strcmp (name, HEAP_SYSTEM))
|
||||
@ -157,7 +176,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case MHH_COMPRESS:
|
||||
fprintf (stdout, "\nHeap name à compresser ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||
{
|
||||
size_t Compress;
|
||||
@ -169,7 +190,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case MHH_END:
|
||||
fprintf (stdout, "\nHeap name to remove ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (!strcmp (name, HEAP_SYSTEM))
|
||||
{
|
||||
fprintf (stdout, \
|
||||
@ -184,7 +207,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case MHH_CLOSE:
|
||||
fprintf (stdout, "\nHeap name to close ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (!strcmp (name, HEAP_SYSTEM))
|
||||
{
|
||||
fprintf (stdout, \
|
||||
@ -201,7 +226,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case MHH_CHECK:
|
||||
fprintf (stdout, "\nHeap name to check/recover ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||
{
|
||||
Nb_Detected = Nb_Corrected = 0;
|
||||
@ -212,41 +239,55 @@ int main (int argc, char ** argv)
|
||||
|
||||
case ALLOC_CHUNK:
|
||||
fprintf (stdout, "\nHeap name ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
fprintf (stdout, "\nAllocation size ? ");
|
||||
gets (tmp);
|
||||
size = atoi (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
size = atol (tmp);
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||
{
|
||||
SM_Chunk_Alloc (Heap, size, &ptr);
|
||||
if (Locked == TRUE) SM_Heap_Unlock (Heap);
|
||||
}
|
||||
fprintf (stdout, "\nAddress = 0x%p (%d)\n", ptr, (unsigned int)ptr);
|
||||
fprintf (stdout, "\nAddress = 0x%p (%lu)\n", ptr, ptr);
|
||||
break;
|
||||
|
||||
case WRITE_CHUNK:
|
||||
fprintf (stdout, "\nAddress ? ");
|
||||
gets (tmp);
|
||||
ptr = (void *)atoi (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
ptr = (void *)atol (tmp);
|
||||
fprintf (stdout, "\nString to put in ? ");
|
||||
gets (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
strcpy ( (char *)ptr, tmp);
|
||||
fprintf (stdout, "\nOK\n");
|
||||
break;
|
||||
|
||||
case READ_CHUNK:
|
||||
fprintf (stdout, "\nAddress ? ");
|
||||
gets (tmp);
|
||||
ptr = (void *)atoi (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
ptr = (void *)atol (tmp);
|
||||
fprintf (stdout, "\nValeur du pointeur = %s\n", (char *)ptr);
|
||||
break;
|
||||
|
||||
case FREE_CHUNK:
|
||||
fprintf (stdout, "\nHeap name ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
fprintf (stdout, "\nAddress ? ");
|
||||
gets (tmp);
|
||||
ptr = (void *)atoi (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
ptr = (void *)atol (tmp);
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_WRITE, &Locked) == SMS_OK)
|
||||
{
|
||||
fprintf (stdout, "\nReturn code = %s\n", \
|
||||
@ -258,7 +299,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case DSR_DUMP:
|
||||
fprintf (stdout, "\nHeap name ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
||||
{
|
||||
ND_DataStruct_Info_Print( stdout, Heap->MHH->DSR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||
@ -269,7 +312,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case ACR_DUMP:
|
||||
fprintf (stdout, "\nHeap name ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
||||
{
|
||||
ND_DataStruct_Info_Print( stdout, Heap->MHH->ACR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||
@ -280,7 +325,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
case FCR_DUMP:
|
||||
fprintf (stdout, "\nHeap name ? ");
|
||||
gets (name);
|
||||
fgets( name, NAME_SIZE, stdin);
|
||||
name[ strlen( name) - 1] = '\0';
|
||||
|
||||
if (SM_Heap_Open (name, &Heap, 0, SMD_OPEN | SMD_READ, &Locked) == SMS_OK)
|
||||
{
|
||||
ND_DataStruct_Info_Print( stdout, Heap->MHH->FCR, NDD_RECURSIVE_MODE_PARENT_CHILD, 0, 0);
|
||||
@ -333,7 +380,9 @@ int print_menu (void)
|
||||
while (tmp[0] == '\0')
|
||||
{
|
||||
printf ("\nChoice ? ");
|
||||
gets (tmp);
|
||||
fgets( tmp, TMP_SIZE, stdin);
|
||||
tmp[ strlen( tmp) - 1] = '\0';
|
||||
|
||||
}
|
||||
|
||||
return atoi (tmp);
|
||||
|
Loading…
Reference in New Issue
Block a user