Mercurial > dwindows
comparison os2/dw.c @ 559:841445b0b457
Fixes for the shared memory and named semaphore code.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Sat, 17 Apr 2004 06:14:00 +0000 |
parents | 1a210e2f214b |
children | c0a708e2cba3 |
comparison
equal
deleted
inserted
replaced
558:05060ce4d6ae | 559:841445b0b457 |
---|---|
7939 * name: Name given to semaphore which can be opened | 7939 * name: Name given to semaphore which can be opened |
7940 * by other processes. | 7940 * by other processes. |
7941 */ | 7941 */ |
7942 HEV API dw_named_event_new(char *name) | 7942 HEV API dw_named_event_new(char *name) |
7943 { | 7943 { |
7944 int rc; | |
7945 char *semname = malloc(strlen(name)+8); | 7944 char *semname = malloc(strlen(name)+8); |
7946 HEV ev = 0; | 7945 HEV ev = 0; |
7947 | 7946 |
7948 if(!semname) | 7947 if(!semname) |
7949 return 0; | 7948 return 0; |
8053 case ERROR_INVALID_HANDLE: | 8052 case ERROR_INVALID_HANDLE: |
8054 rc = DW_ERROR_NON_INIT; | 8053 rc = DW_ERROR_NON_INIT; |
8055 break; | 8054 break; |
8056 | 8055 |
8057 case ERROR_SEM_BUSY: | 8056 case ERROR_SEM_BUSY: |
8058 rc = DW_ERROR_BUSY; | 8057 rc = DW_ERROR_INTERRUPT; |
8059 break; | 8058 break; |
8060 } | 8059 } |
8061 | 8060 |
8062 return rc; | 8061 return rc; |
8063 } | 8062 } |
8068 * handle: A pointer to receive a SHM identifier. | 8067 * handle: A pointer to receive a SHM identifier. |
8069 * dest: A pointer to a pointer to receive the memory address. | 8068 * dest: A pointer to a pointer to receive the memory address. |
8070 * size: Size in bytes of the shared memory region to allocate. | 8069 * size: Size in bytes of the shared memory region to allocate. |
8071 * name: A string pointer to a unique memory name. | 8070 * name: A string pointer to a unique memory name. |
8072 */ | 8071 */ |
8073 int API dw_named_memory_alloc(HSHM *handle, void **dest, int size, char *name) | 8072 HSHM API dw_named_memory_new(void **dest, int size, char *name) |
8074 { | 8073 { |
8075 char namebuf[1024]; | 8074 char namebuf[1024]; |
8076 | 8075 |
8077 sprintf(namebuf, "\\sharemem\\%s", name); | 8076 sprintf(namebuf, "\\sharemem\\%s", name); |
8078 | 8077 |
8079 if(DosAllocSharedMem((void *)dest, namebuf, size, PAG_COMMIT | PAG_WRITE | PAG_READ) != NO_ERROR) | 8078 if(DosAllocSharedMem((void *)dest, namebuf, size, PAG_COMMIT | PAG_WRITE | PAG_READ) != NO_ERROR) |
8080 return -1; | 8079 return 0; |
8081 | 8080 |
8082 return 0; | 8081 return 1; |
8083 } | 8082 } |
8084 | 8083 |
8085 /* | 8084 /* |
8086 * Aquires shared memory region with a name. | 8085 * Aquires shared memory region with a name. |
8087 * Parameters: | 8086 * Parameters: |
8088 * dest: A pointer to a pointer to receive the memory address. | 8087 * dest: A pointer to a pointer to receive the memory address. |
8089 * size: Size in bytes of the shared memory region to requested. | 8088 * size: Size in bytes of the shared memory region to requested. |
8090 * name: A string pointer to a unique memory name. | 8089 * name: A string pointer to a unique memory name. |
8091 */ | 8090 */ |
8092 int API dw_named_memory_get(HSHM *handle, void **dest, int size, char *name) | 8091 HSHM API dw_named_memory_get(void **dest, int size, char *name) |
8093 { | 8092 { |
8094 char namebuf[1024]; | 8093 char namebuf[1024]; |
8095 | 8094 |
8095 size = size; | |
8096 sprintf(namebuf, "\\sharemem\\%s", name); | 8096 sprintf(namebuf, "\\sharemem\\%s", name); |
8097 | 8097 |
8098 if(DosGetNamedSharedMem((void *)dest, namebuf, PAG_READ | PAG_WRITE) != NO_ERROR) | 8098 if(DosGetNamedSharedMem((void *)dest, namebuf, PAG_READ | PAG_WRITE) != NO_ERROR) |
8099 return -1; | 8099 return 0; |
8100 | 8100 |
8101 return 0; | 8101 return 1; |
8102 } | 8102 } |
8103 | 8103 |
8104 /* | 8104 /* |
8105 * Frees a shared memory region previously allocated. | 8105 * Frees a shared memory region previously allocated. |
8106 * Parameters: | 8106 * Parameters: |
8107 * handle: Handle obtained from DB_named_memory_allocate. | 8107 * handle: Handle obtained from DB_named_memory_allocate. |
8108 * ptr: The memory address aquired with DB_named_memory_allocate. | 8108 * ptr: The memory address aquired with DB_named_memory_allocate. |
8109 */ | 8109 */ |
8110 int API dw_named_memory_free(HSHM handle, void *ptr) | 8110 int API dw_named_memory_free(HSHM handle, void *ptr) |
8111 { | 8111 { |
8112 handle = handle; | |
8113 | |
8112 if(DosFreeMem(ptr) != NO_ERROR) | 8114 if(DosFreeMem(ptr) != NO_ERROR) |
8113 return -1; | 8115 return -1; |
8114 return 0; | 8116 return 0; |
8115 } | 8117 } |
8116 | 8118 |