Conceptually callers should not care about how the shmem is implemented,
and it also removes the dependency on config.h from the headers.
---
 lib/msg_queue.cpp |   26 ++++++++++++++++++--------
 lib/msg_queue.h   |   18 ++++--------------
 lib/shmem.cpp     |   36 ++++++++++++++++++------------------
 lib/shmem.h       |    8 ++++----
 lib/synch.cpp     |   22 ++++++++++++----------
 lib/synch.h       |   12 +++++-------
 sched/feeder.cpp  |    2 +-
 sched/main.cpp    |    2 +-
 sched/main.h      |    2 +-
 9 files changed, 64 insertions(+), 64 deletions(-)

diff --git a/lib/msg_queue.cpp b/lib/msg_queue.cpp
index cef5ced..f3db2d7 100644
--- a/lib/msg_queue.cpp
+++ b/lib/msg_queue.cpp
@@ -25,14 +25,24 @@
 #include <unistd.h>
 #endif
 
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_IPC_H
+#include <sys/ipc.h>
+#endif
+#ifdef HAVE_SYS_MSG_H
+#include <sys/msg.h>
+#endif
+
 using std::perror;
 
 #include "msg_queue.h"
 
-int create_message_queue(key_t key) {
+int create_message_queue(long key) {
     int mq_id;
 
-    mq_id = msgget(key, IPC_CREAT | IPC_EXCL | 0666);
+    mq_id = msgget((key_t)key, IPC_CREAT | IPC_EXCL | 0666);
     if (mq_id < 0) {
         perror("create_message_queue: msgget");
         return -1;
@@ -40,10 +50,10 @@ int create_message_queue(key_t key) {
     return 0;
 }
 
-int receive_message(key_t key, void *msg, size_t msg_size, bool wait) {
+int receive_message(long key, void *msg, size_t msg_size, bool wait) {
     int mq_id, retval;
 
-    mq_id = msgget(key, 0666);
+    mq_id = msgget((key_t)key, 0666);
     if (mq_id < 0) {
         perror("receive_message: msgget");
         return -1;
@@ -58,10 +68,10 @@ int receive_message(key_t key, void *msg, size_t msg_size, 
bool wait) {
     return 0;
 }
 
-int send_message(key_t key, void *msg, size_t msg_size, bool wait) {
+int send_message(long key, void *msg, size_t msg_size, bool wait) {
     int mq_id, retval;
 
-    mq_id = msgget(key, 0666);
+    mq_id = msgget((key_t)key, 0666);
     if (mq_id < 0) {
         perror("send_message: msgget");
         return -1;
@@ -76,10 +86,10 @@ int send_message(key_t key, void *msg, size_t msg_size, 
bool wait) {
     return 0;
 }
 
-int destroy_message_queue(key_t key) {
+int destroy_message_queue(long key) {
     int mq_id, retval;
 
-    mq_id = msgget(key, 0666);
+    mq_id = msgget((key_t)key, 0666);
     if (mq_id < 0) {
         perror("delete_message_queue: msgget");
         return -1;
diff --git a/lib/msg_queue.h b/lib/msg_queue.h
index 0fde534..7b162c1 100644
--- a/lib/msg_queue.h
+++ b/lib/msg_queue.h
@@ -18,19 +18,9 @@
 #ifndef _MSG_QUEUE_
 #define _MSG_QUEUE_
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_IPC_H
-#include <sys/ipc.h>
-#endif
-#ifdef HAVE_SYS_MSG_H
-#include <sys/msg.h>
-#endif
-
-extern int create_message_queue(key_t);
-extern int receive_message(key_t,void*,size_t,bool);
-extern int send_message(key_t,void*,size_t,bool);
-extern int destroy_message_queue(key_t);
+extern int create_message_queue(long);
+extern int receive_message(long,void*,size_t,bool);
+extern int send_message(long,void*,size_t,bool);
+extern int destroy_message_queue(long);
 
 #endif
diff --git a/lib/shmem.cpp b/lib/shmem.cpp
index afd70ac..7fa404f 100644
--- a/lib/shmem.cpp
+++ b/lib/shmem.cpp
@@ -245,11 +245,11 @@ int detach_shmem(HANDLE hMap, void* p) {
 
 #elif defined(__EMX__)
 
-int create_shmem(key_t key, int size, void** pp) {
+int create_shmem(long key, int size, void** pp) {
     APIRET rc;
     char   buf[256];
 
-    sprintf(buf, "\\SHAREMEM\\BOINC\\%d", key);
+    sprintf(buf, "\\SHAREMEM\\BOINC\\%ld", key);
     //debug_printf( "create_shmem %s, %d, %p\n", buf, size, pp);
     rc = DosAllocSharedMem(pp, (PSZ)buf, size, PAG_READ | PAG_WRITE | 
PAG_EXECUTE | PAG_COMMIT | OBJ_ANY);
     if (rc == ERROR_ALREADY_EXISTS)
@@ -266,7 +266,7 @@ int create_shmem(key_t key, int size, void** pp) {
 
 }
 
-int destroy_shmem(key_t key){
+int destroy_shmem(long key){
     APIRET rc;
     void*  pp;
 
@@ -281,11 +281,11 @@ int destroy_shmem(key_t key){
     return 0;
 }
 
-int attach_shmem(key_t key, void** pp){
+int attach_shmem(long key, void** pp){
     APIRET rc;
     char   buf[256];
 
-    sprintf(buf, "\\SHAREMEM\\BOINC\\%d", key);
+    sprintf(buf, "\\SHAREMEM\\BOINC\\%ld", key);
     //debug_printf( "attach_shmem %s, %p\n", buf, pp);
     rc = DosGetNamedSharedMem(pp, (PSZ) buf, PAG_READ | PAG_WRITE);
     if (rc) {
@@ -347,7 +347,7 @@ int create_shmem_mmap(const char *path, size_t size, void** 
pp) {
     return 0;
 }
 
-int destroy_shmem_mmap(key_t key){
+int destroy_shmem_mmap(long key){
     return 0;
 }
 
@@ -386,7 +386,7 @@ int detach_shmem_mmap(void* p, size_t size) {
 
 // Compatibility routines for Unix/Linux/Mac V5 applications 
 //
-int create_shmem(key_t key, int size, gid_t gid, void** pp) {
+int create_shmem(long key, int size, gid_t gid, void** pp) {
     int id;
     
     // try 0666, then SHM_R|SHM_W
@@ -401,9 +401,9 @@ int create_shmem(key_t key, int size, gid_t gid, void** pp) 
{
     // it's a big headache for anyone it affects,
     // and it's not a significant security issue.
     //
-    id = shmget(key, size, IPC_CREAT|0666);
+    id = shmget((key_t)key, size, IPC_CREAT|0666);
     if (id < 0) {
-        id = shmget(key, size, IPC_CREAT|SHM_R|SHM_W);
+        id = shmget((key_t)key, size, IPC_CREAT|SHM_R|SHM_W);
     }
     if (id < 0) {
         perror("shmget");
@@ -440,11 +440,11 @@ int create_shmem(key_t key, int size, gid_t gid, void** 
pp) {
 // the key in the shared memory structure), so BOINC does it 
 // only after we are completey done with the segment.
 //
-int destroy_shmem(key_t key){
+int destroy_shmem(long key){
     struct shmid_ds buf;
     int id, retval;
 
-    id = shmget(key, 0, 0);
+    id = shmget((key_t)key, 0, 0);
     if (id < 0) return 0;           // assume it doesn't exist
     retval = shmctl(id, IPC_STAT, &buf);
     if (retval) {
@@ -459,11 +459,11 @@ int destroy_shmem(key_t key){
     return 0;
 }
 
-int attach_shmem(key_t key, void** pp){
+int attach_shmem(long key, void** pp){
     void* p;
     int id;
 
-    id = shmget(key, 0, 0);
+    id = shmget((key_t)key, 0, 0);
     if (id < 0) {
         perror("shmget in attach_shmem");
         return ERR_SHMGET;
@@ -483,11 +483,11 @@ int detach_shmem(void* p) {
     return retval;
 }
 
-int print_shmem_info(key_t key) {
+int print_shmem_info(long key) {
     int id;
     struct shmid_ds buf;
 
-    id = shmget(key, 0, 0);
+    id = shmget((key_t)key, 0, 0);
     if (id < 0) {
         return ERR_SHMGET;
     }
@@ -505,11 +505,11 @@ int print_shmem_info(key_t key) {
 // Platforms that don't have sys/shm.h will need stubs,
 // or alternate implementations
 
-int create_shmem(key_t, int size, gid_t gid, void**) {
+int create_shmem(long, int size, gid_t gid, void**) {
    perror("create_shmem: not supported on this platform");
    return ERR_SHMGET;
 }
-int attach_shmem(key_t, void**) {
+int attach_shmem(long, void**) {
    perror("attach_shmem: not supported on this platform");
    return ERR_SHMGET;
 }
@@ -517,7 +517,7 @@ int detach_shmem(void*) {
    perror("detach_shmem: not supported on this platform");
    return ERR_SHMGET;
 }
-int destroy_shmem(key_t) {
+int destroy_shmem(long) {
    perror("destroy_shmem: not supported on this platform");
    return ERR_SHMCTL;
 }
diff --git a/lib/shmem.h b/lib/shmem.h
index ff9daf0..ff598a9 100644
--- a/lib/shmem.h
+++ b/lib/shmem.h
@@ -43,15 +43,15 @@ extern int create_shmem_mmap(const char *path, size_t size, 
void** pp);
 extern int attach_shmem_mmap(const char *path, void** pp);
 extern int detach_shmem_mmap(void* p, size_t size);
 #endif
-extern int create_shmem(key_t, int size, gid_t gid, void**);
-extern int attach_shmem(key_t, void**);
+extern int create_shmem(long, int size, gid_t gid, void**);
+extern int attach_shmem(long, void**);
 extern int detach_shmem(void*);
-extern int shmem_info(key_t key);
+extern int shmem_info(long key);
 // Destroy a shared-memory segment.
 // If there are attachments to it,
 // print a message in a loop until the attachments are gone
 //
-extern int destroy_shmem(key_t);
+extern int destroy_shmem(long);
 #endif      // !defined(_WIN32)
 
 #endif      // BOINC_SHMEM_H
diff --git a/lib/synch.cpp b/lib/synch.cpp
index fd8df89..bfcfc46 100644
--- a/lib/synch.cpp
+++ b/lib/synch.cpp
@@ -23,6 +23,8 @@
 #include <cstdlib>
 #include <cstring>
 
+#include <sys/sem.h>
+
 using std::memset;
 
 #include "error_numbers.h"
@@ -39,11 +41,11 @@ union SEMUN {
     struct seminfo *__buf;
 };
 
-int create_semaphore(key_t key){
+int create_semaphore(long key){
     int id, retval;
     SEMUN s;
 
-    id = semget(key, 1, IPC_CREAT|IPC_EXCL|0777);
+    id = semget((key_t)key, 1, IPC_CREAT|IPC_EXCL|0777);
     if (id < 0) {
         return ERR_SEMGET;
     }
@@ -56,9 +58,9 @@ int create_semaphore(key_t key){
     return 0;
 }
 
-int destroy_semaphore(key_t key){
+int destroy_semaphore(long key){
     int id, retval;
-    id = semget(key, 0, 0);
+    id = semget((key_t)key, 0, 0);
     if (id < 0) {
         return ERR_SEMGET;
     }
@@ -69,11 +71,11 @@ int destroy_semaphore(key_t key){
     return 0;
 }
 
-int lock_semaphore(key_t key) {
+int lock_semaphore(long key) {
     struct sembuf s;
     int id, retval;
 
-    id = semget(key, 0, 0);
+    id = semget((key_t)key, 0, 0);
     if (id < 0) {
         return ERR_SEMGET;
     }
@@ -87,11 +89,11 @@ int lock_semaphore(key_t key) {
     return 0;
 }
 
-int unlock_semaphore(key_t key) {
+int unlock_semaphore(long key) {
     struct sembuf s;
     int id, retval;
 
-    id = semget(key, 0, 0);
+    id = semget((key_t)key, 0, 0);
     if (id < 0) {
         return ERR_SEMGET;
     }
@@ -105,9 +107,9 @@ int unlock_semaphore(key_t key) {
     return 0;
 }
 
-int get_key(char* path, int id, key_t& key) {
+int get_key(char* path, int id, long& key) {
     key = ftok(path, id);
-    if (key == (key_t)-1) return ERR_FTOK;
+    if (key == -1) return ERR_FTOK;
     return 0;
 }
 
diff --git a/lib/synch.h b/lib/synch.h
index 749a090..11a920d 100644
--- a/lib/synch.h
+++ b/lib/synch.h
@@ -18,12 +18,10 @@
 #ifndef _SYNCH_H_
 #define _SYNCH_H_
 
-#include <sys/sem.h>
-
-extern int create_semaphore(key_t);
-extern int destroy_semaphore(key_t);
-extern int lock_semaphore(key_t);
-extern int unlock_semaphore(key_t);
-extern int get_key(char* path, int id, key_t&);
+extern int create_semaphore(long);
+extern int destroy_semaphore(long);
+extern int lock_semaphore(long);
+extern int unlock_semaphore(long);
+extern int get_key(char* path, int id, long&);
 
 #endif
diff --git a/sched/feeder.cpp b/sched/feeder.cpp
index bacd5f8..835d366 100644
--- a/sched/feeder.cpp
+++ b/sched/feeder.cpp
@@ -132,7 +132,7 @@ using std::vector;
 #define ENUM_OVER           2
 
 SCHED_SHMEM* ssp;
-key_t sema_key;
+long sema_key;
 const char* order_clause="";
 char mod_select_clause[256];
 double sleep_interval = DEFAULT_SLEEP_INTERVAL;
diff --git a/sched/main.cpp b/sched/main.cpp
index b63ed29..4c1831b 100644
--- a/sched/main.cpp
+++ b/sched/main.cpp
@@ -77,7 +77,7 @@ bool use_files = false;     // use disk files for req/reply 
msgs (for debugging)
 
 GUI_URLS gui_urls;
 PROJECT_FILES project_files;
-key_t sema_key;
+long sema_key;
 int g_pid;
 static bool db_opened=false;
 SCHED_SHMEM* ssp = 0;
diff --git a/sched/main.h b/sched/main.h
index 969c4ba..1ed50a3 100644
--- a/sched/main.h
+++ b/sched/main.h
@@ -59,7 +59,7 @@
 
 extern GUI_URLS gui_urls;
 extern PROJECT_FILES project_files;
-extern key_t sema_key;
+extern long sema_key;
 extern int g_pid;
 extern SCHED_SHMEM* ssp;
 extern bool batch;
-- 
1.6.3.1

_______________________________________________
boinc_dev mailing list
boinc_dev@ssl.berkeley.edu
http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
To unsubscribe, visit the above URL and
(near bottom of page) enter your email address.

Reply via email to