From: Marek P. <ma...@us...> - 2001-08-12 07:35:35
|
Update of /cvsroot/javaprofiler/library/src/commun3 In directory usw-pr-cvs1:/tmp/cvs-serv724/src/commun3 Modified Files: communShMem.cpp communShMem.h sharedMemory.h Log Message: changes in library setups; now, library can run in server or client mode (java part not implemented yet) Index: communShMem.cpp =================================================================== RCS file: /cvsroot/javaprofiler/library/src/commun3/communShMem.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** communShMem.cpp 2001/08/09 23:22:55 1.1 --- communShMem.cpp 2001/08/12 07:35:31 1.2 *************** *** 6,9 **** --- 6,10 ---- void* p = _shmem.getAddress(); + int shmemSize = _shmem.getSize(); jint size = ntohl( *(jint*)p); *************** *** 11,28 **** if( size) { ! jint num = size/_shmemSize; char* buf = new char[size]; char* q = buf; ! for( jint i = 0; i < num; i++, q += _shmemSize) { _sem2.release(); _sem1.wait(); ! memcpy( q, p, _shmemSize); } ! jint rest = size%_shmemSize; if( rest) { --- 12,29 ---- if( size) { ! jint num = size/shmemSize; char* buf = new char[size]; char* q = buf; ! for( jint i = 0; i < num; i++, q += shmemSize) { _sem2.release(); _sem1.wait(); ! memcpy( q, p, shmemSize); } ! jint rest = size%shmemSize; if( rest) { *************** *** 45,48 **** --- 46,50 ---- void* p = _shmem.getAddress(); + int shmemSize = _shmem.getSize(); jint size = b.getSize(); *************** *** 54,64 **** _sem1.wait(); ! jint num = size/_shmemSize; const char* q = b.getBuffer(); ! for( int i = 0; i < num; i++, q += _shmemSize) { ! memcpy( p, q, _shmemSize); _sem2.release(); --- 56,66 ---- _sem1.wait(); ! jint num = size/shmemSize; const char* q = b.getBuffer(); ! for( int i = 0; i < num; i++, q += shmemSize) { ! memcpy( p, q, shmemSize); _sem2.release(); *************** *** 66,70 **** } ! jint rest = size%_shmemSize; if( rest) { --- 68,72 ---- } ! jint rest = size%shmemSize; if( rest) { Index: communShMem.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/commun3/communShMem.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** communShMem.h 2001/08/09 23:22:55 1.1 --- communShMem.h 2001/08/12 07:35:31 1.2 *************** *** 2,29 **** #define _COMMUN_SH_MEM_H_ class CommunShMem: public Commun { Semaphore _sem1; Semaphore _sem2; SharedMemory _shmem; - int _shmemSize; - public: - // maximum 3 znaky CommunShMem( const String& shmemId, int size) : _sem1( String( "1") + shmemId + "XXXXXXXXXX"), _sem2( String( "2") + shmemId + "XXXXXXXXXX"), ! _shmem( String( "3") + shmemId + "XXXXXXXXXX"), - _shmemSize( size) - {}; virtual Commun& operator>>( Buffer& b); virtual Commun& operator<<( const Buffer& b); --- 2,62 ---- #define _COMMUN_SH_MEM_H_ + /** Shared memory communication. This class implements shared memory + ** communication and offers the user of this class the standard + ** interface of Commun class. Implementation is system dependent + ** (so it is different on WIN32 and UNIX systems). It should be + ** faster then using sockets. + ** + ** @see CommunSocket, Commun + ** + ** @author Marek Przeczek */ + class CommunShMem: public Commun { + /// read-write semaphore Semaphore _sem1; + /// write-read semaphore Semaphore _sem2; + /// shared memory SharedMemory _shmem; public: + + /** Constructor. Creates shared memory block and + ** needed semaphores for communication. If semaphores + ** or shared memory block already exist, they are used. + ** + ** @param shmemId shared memory identifier (3 characters long only) + ** @param size shared memory size */ CommunShMem( const String& shmemId, int size) : _sem1( String( "1") + shmemId + "XXXXXXXXXX"), _sem2( String( "2") + shmemId + "XXXXXXXXXX"), ! _shmem( String( "3") + shmemId + "XXXXXXXXXX", size) {}; + /** Read data. This operator is used to read data + ** from communication channel (shmem) to buffer. + ** + ** @param b reference to Buffer object + ** + ** @return reference to this Commun object + ** + ** @see operator<<() */ + virtual Commun& operator>>( Buffer& b); + + /** Write data. This operator is used to write data + ** from buffer to communication channel (shmem). + ** + ** @param b reference to Buffer object + ** + ** @return reference to this Commun object + ** + ** @see operator>>() */ virtual Commun& operator<<( const Buffer& b); Index: sharedMemory.h =================================================================== RCS file: /cvsroot/javaprofiler/library/src/commun3/sharedMemory.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** sharedMemory.h 2001/08/09 23:22:55 1.1 --- sharedMemory.h 2001/08/12 07:35:31 1.2 *************** *** 19,22 **** --- 19,25 ---- #endif + /// shared memory size + int _size; + public: *************** *** 29,37 **** ** @param size size of shared memory (in bytes) */ ! SharedMemory( const String& name, int size) { #ifdef WIN32 _shmid = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, ! PAGE_READWRITE | SEC_COMMIT, 0, size, name); _address = MapViewOfFile( _shmid, FILE_MAP_ALL_ACCESS, 0, 0, 0); #else --- 32,40 ---- ** @param size size of shared memory (in bytes) */ ! SharedMemory( const String& name, int size) : _size( size) { #ifdef WIN32 _shmid = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, ! PAGE_READWRITE | SEC_COMMIT, 0, _size, name); _address = MapViewOfFile( _shmid, FILE_MAP_ALL_ACCESS, 0, 0, 0); #else *************** *** 61,64 **** --- 64,73 ---- void* getAddress() { return _address;} + + /** Size of shared memory block. + ** + ** @return size of shared memory block */ + + int getSize() { return _size;} }; |