Commit d4868b64 authored by unknown's avatar unknown
Browse files

shared memory abstraction ported to windows

parent 04687138
......@@ -462,15 +462,6 @@ void ortp_shm_close(void *mem){
shmdt(mem);
}
#else
void *ortp_shm_open(unsigned int keyid, int size, int create){
ortp_error("No shared memory support for this OS.");
}
void ortp_shm_close(void *mem){
}
#endif
#elif defined(WIN32) && !defined(_WIN32_WCE)
......@@ -564,11 +555,69 @@ int ortp_client_pipe_close(ortp_pipe_t sock){
return CloseHandle(sock);
}
void *ortp_shm_open(unsigned int keyid, int size, int create{
return NULL;
typedef struct MapInfo{
HANDLE h;
void *mem;
}MapInfo;
static OList *maplist=NULL;
void *ortp_shm_open(unsigned int keyid, int size, int create){
HANDLE h;
char name[64];
void *buf;
snprintf(name,sizeof(name),"%x",keyid);
if (create){
h = CreateFileMapping(
INVALID_HANDLE_VALUE, // use paging file
NULL, // default security
PAGE_READWRITE, // read/write access
0, // maximum object size (high-order DWORD)
size, // maximum object size (low-order DWORD)
name); // name of mapping object
}else{
h = OpenFileMapping(
FILE_MAP_ALL_ACCESS, // read/write access
FALSE, // do not inherit the name
name); // name of mapping object
}
if (h==(HANDLE)-1) {
ortp_error("Fail to open file mapping (create=%i)",create);
return NULL;
}
buf = (LPTSTR) MapViewOfFile(h, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0,
0,
size);
if (buf!=NULL){
MapInfo *i=(MapInfo*)ortp_new(MapInfo,1);
i->h=h;
i->mem=buf;
maplist=o_list_append(maplist,i);
}else{
CloseHandle(h);
ortp_error("MapViewOfFile failed");
}
return buf;
}
void ortp_shm_close(void *mem){
OList *elem;
for(elem=maplist;elem!=NULL;elem=elem->next){
MapInfo *i=(MapInfo*)elem->data;
if (i->mem==mem){
CloseHandle(i->h);
UnmapViewOfFile(mem);
ortp_free(i);
maplist=o_list_remove_link(maplist,elem);
return;
}
}
ortp_error("No shared memory at %p was found.",mem);
}
#endif
......@@ -43,6 +43,7 @@ typedef struct _OList OList;
OList * o_list_append(OList *elem, void * data);
OList * o_list_remove(OList *list, void *data);
OList * o_list_free(OList *elem);
OList *o_list_remove_link(OList *list, OList *elem);
#ifndef MIN
#define MIN(a,b) (((a)>(b)) ? (b) : (a))
......
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