Commit f3be46d2 authored by IOhannes m zmölnig's avatar IOhannes m zmölnig
Browse files

made shm support optional

parent 5f657214
......@@ -10,12 +10,17 @@
#ifndef _INCLUDE__GEM_PIXES_PIX_SHARE_H_
#define _INCLUDE__GEM_PIXES_PIX_SHARE_H_
#include <Gem/GemConfig.h>
#if (defined HAVE_SYS_IPC_H) && (defined HAVE_SYS_SHM_H)
# define USE_SHM 1
#endif
#include "Base/GemBase.h"
#include <sys/types.h>
#ifndef _WIN32
#if USE_SHM
# include <sys/ipc.h>
# include <sys/shm.h>
#else
#elif defined _WIN32
# include <windows.h>
# include <stdio.h>
# include <conio.h>
......
......@@ -27,10 +27,12 @@ pix_share_read :: ~pix_share_read()
void pix_share_read :: render(GemState *state)
{
#ifndef _WIN32
#if USE_SHM
if(shm_id>0) {
#else
#elif defined _WIN32
if(m_MapFile) {
#else
if(0) {
#endif /* _WIN32 */
if (shm_addr) {
t_pixshare_header *h=(t_pixshare_header *)shm_addr;
......
......@@ -59,15 +59,17 @@ int hash_str2us(std::string s)
//
/////////////////////////////////////////////////////////
pix_share_write :: pix_share_write(int argc, t_atom*argv) :
#ifdef _WIN32
#else
#if USE_SHM
shm_id(0), shm_addr(NULL),
#endif
m_size(0),
m_outlet(0)
{
#ifndef _WIN32
#if USE_SHM
memset(&shm_desc, 0, sizeof(shm_desc));
#elif defined _WIN32
#else
error("Gem has been compiled without shared memory support!")
#endif
if(argc<1) {
//~ throw(GemException("no ID given"));
......@@ -122,19 +124,16 @@ void pix_share_write :: freeShm()
if ( shm_addr ) {
UnmapViewOfFile( shm_addr );
}
shm_addr = NULL;
if ( m_MapFile ) {
CloseHandle( m_MapFile );
}
m_MapFile = NULL;
#else
#elif USE_SHM
if(shm_addr) {
if (shmdt(shm_addr) == -1) {
error("shmdt failed at %p", shm_addr);
}
}
shm_addr=NULL;
if(shm_id>0) {
if (shmctl(shm_id,IPC_STAT, &shm_desc) != -1) {
if(shm_desc.shm_nattch<=0) {
......@@ -145,7 +144,8 @@ void pix_share_write :: freeShm()
}
}
shm_id=0;
#endif /* _WIN32 */
#endif /* _WIN32, USE_SHM */
shm_addr = NULL;
}
int pix_share_write :: getShm(int argc,t_atom*argv)
......@@ -175,7 +175,7 @@ int pix_share_write :: getShm(int argc,t_atom*argv)
"gem_pix_share-FileMappingObject_%s", atom_getsymbol(argv)->s_name);
}
#else
#elif USE_SHM
if(shm_id>0) {
freeShm();
}
......@@ -190,7 +190,9 @@ int pix_share_write :: getShm(int argc,t_atom*argv)
if(fake<=0) {
return 8;
}
#endif /* _WIN32 */
#else
return -1;
#endif /* _WIN32, USE_SHM */
argc--;
argv++;
......@@ -309,7 +311,7 @@ int pix_share_write :: getShm(int argc,t_atom*argv)
m_fileMappingName);
}
#else
#elif USE_SHM
/* get a new segment with the size specified by the user
* OR an old segment with the size specified in its header
......@@ -365,7 +367,7 @@ int pix_share_write :: getShm(int argc,t_atom*argv)
error("couldn't get shm_id: error %d", errno);
return -1; // AV : added because i'm usure of what value is returned when we get this error...
}
#endif /* _WIN32 */
#endif /* _WIN32, SHM */
return 0;
}
......@@ -383,8 +385,10 @@ void pix_share_write :: render(GemState *state)
#ifndef _WIN32
if(shm_id>0) {
#else
#elif USE_SHM
if(m_MapFile) {
#else
if(0) {
#endif /* _WIN32 */
imageStruct *pix = &img->image;
size_t size=pix->xsize*pix->ysize*pix->csize;
......
......@@ -27,10 +27,10 @@ protected:
virtual void render(GemState *state);
unsigned char *shm_addr;
#ifndef _WIN32
#if USE_SHM
int shm_id;
struct shmid_ds shm_desc;
#else
#elif defined _WIN32
HANDLE m_MapFile;
char m_fileMappingName[MAXPDSTRING];
#endif
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment