[prev in list] [next in list] [prev in thread] [next in thread] 

List:       monetdb-checkins
Subject:    MonetDB: default - Finish cleaning up interprocess.h (now gdk_in...
From:       Mark Raasveldt <commits+m.raasveldt=cwi.nl () monetdb ! org>
Date:       2016-06-30 14:03:18
Message-ID: hg.dc88e0ae3cfa.1467295398.6315528441665844383 () monetdb2 ! cwi-incubator ! nl
[Download RAW message or body]

Changeset: dc88e0ae3cfa for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=dc88e0ae3cfa
Modified Files:
	gdk/gdk_interprocess.c
	gdk/gdk_interprocess.h
	monetdb5/extras/pyapi/connection.c
	monetdb5/extras/pyapi/pyapi.c
Branch: default
Log Message:

Finish cleaning up interprocess.h (now gdk_interprocess.h).


diffs (truncated from 356 to 300 lines):

diff --git a/gdk/gdk_interprocess.c b/gdk/gdk_interprocess.c
--- a/gdk/gdk_interprocess.c
+++ b/gdk/gdk_interprocess.c
@@ -5,7 +5,6 @@
 
 #include "gdk.h"
 #include "gdk_private.h"
-#include "../monetdb5/mal/mal_exception.h"
 
 #include <stdlib.h>
 #include <assert.h>
@@ -65,13 +64,13 @@ GDKuniqueid(size_t offset) {
  * return: GDK_SUCCEED if successful, GDK_FAIL if not successful (with msg set to \
                error message)
 */
 gdk_return 
-GDKinitmmap(size_t id, size_t size, void **return_ptr, str *msg) {
+GDKinitmmap(size_t id, size_t size, void **return_ptr, size_t *return_size, str \
*msg) {  char address[100];
     void *ptr;
     int fd;
     int mod = MMAP_READ | MMAP_WRITE | MMAP_SEQUENTIAL | MMAP_SYNC  | MAP_SHARED;
     char *path = NULL;
-    snprintf_mmap_file(address, 100, id);
+    GDKmmapfile(address, 100, id);
 
     /* round up to multiple of GDK_mmap_pagesize with a
      * minimum of one 
@@ -99,7 +98,12 @@ GDKinitmmap(size_t id, size_t size, void
         goto cleanup;
     }
     GDKfree(path);
-    if (return_ptr != NULL) (*return_ptr) = ptr;
+    if (return_ptr != NULL) {
+        *return_ptr = ptr;
+    }
+    if (return_size != NULL) {
+        *return_size = size;
+    }
     return GDK_SUCCEED;
 cleanup:
     if (path) GDKfree(path);
@@ -118,7 +122,7 @@ GDKreleasemmap(void *ptr, size_t size, s
     char address[100];
     char *path;
     int ret;
-    snprintf_mmap_file(address, 100, id);
+    GDKmmapfile(address, 100, id);
     if (GDKmunmap(ptr, size) != GDK_SUCCEED) {
         interprocess_create_error("Failure in GDKmunmap: %s", strerror(errno));
         return GDK_FAIL;
@@ -278,68 +282,4 @@ GDKreleasesem(int sem_id, str *msg) {
     return GDK_SUCCEED;
 }
 
-str snprintf_mmap_file(str file, size_t max, size_t id) {
-    snprintf(file, max, "pymmap%zu", id);
-    return MAL_SUCCEED;
-}
-
-str init_mmap_memory(size_t base_id, size_t id_offset, size_t maxsize, void \
                ***return_ptr, size_t **return_size, char **single_ptr) {
-    char address[100];
-    void *ptr;
-    int fd;
-    size_t size = maxsize;
-    int mod = MMAP_READ | MMAP_WRITE | MMAP_SEQUENTIAL | MMAP_SYNC  | MAP_SHARED;
-    char *path = NULL;
-    snprintf_mmap_file(address, 100, base_id + id_offset);
-
-    /* round up to multiple of GDK_mmap_pagesize with a
-     * minimum of one 
-    size = (maxsize + GDK_mmap_pagesize - 1) & ~(GDK_mmap_pagesize - 1);
-    if (size == 0)
-        size = GDK_mmap_pagesize; */
-    fd = GDKfdlocate(0, address, "wb", "tmp");
-    if (fd < 0) {
-        return createException(MAL, "interprocess.get", "Failure in GDKfdlocate(0, \
                %s, \"wb\", NULL)", address);
-    }
-    path = GDKfilepath(0, BATDIR, address, "tmp");
-    if (path == NULL) {
-        return createException(MAL, "interprocess.get", "Failure in GDKfilepath(0, \
                "BATDIR",%s,\"tmp\")", address);
-    }
-    close(fd);
-    if (GDKextend(path, size) != GDK_SUCCEED) {
-        return createException(MAL, "interprocess.get", "Failure in \
                GDKextend(%s,%zu)", path, size);
-    }
-    ptr = GDKmmap(path, mod, size);
-    if (ptr == NULL) {
-        return createException(MAL, "interprocess.get", "Failure in GDKmmap(%s, %d, \
                %zu)", path, mod, size);
-    }
-    GDKfree(path);
-    if (return_ptr != NULL) (*return_ptr)[id_offset] = ptr;
-    if (return_size != NULL) (*return_size)[id_offset] = size;
-    if (single_ptr != NULL) *single_ptr = ptr;
-    return MAL_SUCCEED;
-}
-
-str release_mmap_memory(void *ptr, size_t size, size_t id) {
-    char address[100];
-    char *path;
-    int ret;
-    snprintf_mmap_file(address, 100, id);
-    if (GDKmunmap(ptr, size) != GDK_SUCCEED) {
-        return createException(MAL, "interprocess.get", "Failure in GDKmunmap(%p, \
                %zu)", ptr, size);
-    }
-    path = GDKfilepath(0, BATDIR, address, "tmp");
-    if (path == NULL) {
-        return createException(MAL, "interprocess.get", "Failure in GDKfilepath(0, \
                "BATDIR",%s,\"tmp\")", address);
-    }
-    ret = remove(path);
-    GDKfree(path);
-    if (ret < 0) {
-        perror(strerror(errno));
-        return createException(MAL, "interprocess.get", "Failure in remove(%s)", \
                path);
-    }
-    return MAL_SUCCEED;
-}
-
-
 #endif
diff --git a/gdk/gdk_interprocess.h b/gdk/gdk_interprocess.h
--- a/gdk/gdk_interprocess.h
+++ b/gdk/gdk_interprocess.h
@@ -29,7 +29,7 @@ gdk_export size_t GDKuniqueid(size_t off
  */
 
 //! Create a memory mapped file if it does not exist and open it
-gdk_export gdk_return GDKinitmmap(size_t id, size_t size, void **return_ptr, str \
*msg); +gdk_export gdk_return GDKinitmmap(size_t id, size_t size, void **return_ptr, \
size_t *return_size, str *msg);  //! Release a memory mapped file that was created \
through GDKinitmmap  gdk_export gdk_return GDKreleasemmap(void *ptr, size_t size, \
size_t id, str *msg);  //! snprintf the file name of a memory mapped file (as created \
by GDKinitmmap) @@ -52,17 +52,9 @@ gdk_export gdk_return GDKchangesemval_ti
 //! Destroy an interprocess semaphore
 gdk_export gdk_return GDKreleasesem(int sem_id, str *msg);
 
-str init_mmap_memory(size_t base_id, size_t id_offset, size_t maxsize, void \
                ***return_ptr, size_t **return_size, char **single_ptr);
-str release_mmap_memory(void *ptr, size_t size, size_t id);
-str snprintf_mmap_file(str file, size_t max, size_t id);
-/*size_t get_unique_id(size_t offset);*/
-
-//str create_process_semaphore(int id, int count, int *semid);
-//str get_process_semaphore(int sem_id, int count, int *semid);
-//str get_semaphore_value(int sem_id, int number, int *semval);
-//str change_semaphore_value(int sem_id, int number, int change);
-//str change_semaphore_value_timeout(int sem_id, int number, int change, int \
                timeout_mseconds, bool *succeed);
-//str release_process_semaphore(int sem_id);
+//str init_mmap_memory(size_t base_id, size_t id_offset, size_t maxsize, void \
***return_ptr, size_t **return_size, char **single_ptr); +//str \
release_mmap_memory(void *ptr, size_t size, size_t id); +//str snprintf_mmap_file(str \
file, size_t max, size_t id);  #endif
 
 #endif /* _GDK_INTERPROCES_H_ */
diff --git a/monetdb5/extras/pyapi/connection.c b/monetdb5/extras/pyapi/connection.c
--- a/monetdb5/extras/pyapi/connection.c
+++ b/monetdb5/extras/pyapi/connection.c
@@ -107,8 +107,7 @@ static PyObject *
             int i;
             
             // get a pointer to the shared memory holding the return values
-            msg = init_mmap_memory(self->query_ptr->mmapid, 0, \
                self->query_ptr->memsize, NULL, NULL, &ptr);
-            if (msg != MAL_SUCCEED) {
+            if (GDKinitmmap(self->query_ptr->mmapid + 0, self->query_ptr->memsize, \
(void**) &ptr, NULL, &msg) != GDK_SUCCEED) {  PyErr_Format(PyExc_Exception, "%s", \
msg);  return NULL;
             }
@@ -148,13 +147,13 @@ static PyObject *
                 numpy_array = PyMaskedArray_FromBAT(&input, 0, input.count, &msg, \
true);  if (!numpy_array) {
                     PyErr_Format(PyExc_Exception, "SQL Query Failed: %s", (msg ? msg \
                : "<no error>"));
-                    release_mmap_memory(ptr, self->query_ptr->memsize, \
self->query_ptr->mmapid); +                    GDKreleasemmap(ptr, \
self->query_ptr->memsize, self->query_ptr->mmapid, &msg);  return NULL;
                 }
                 PyDict_SetItem(result, PyString_FromString(colname), numpy_array);
                 Py_DECREF(numpy_array);
             }
-            release_mmap_memory(ptr, self->query_ptr->memsize, \
self->query_ptr->mmapid); +            GDKreleasemmap(ptr, self->query_ptr->memsize, \
self->query_ptr->mmapid, &msg);  return result;
         }
 
diff --git a/monetdb5/extras/pyapi/pyapi.c b/monetdb5/extras/pyapi/pyapi.c
--- a/monetdb5/extras/pyapi/pyapi.c
+++ b/monetdb5/extras/pyapi/pyapi.c
@@ -168,8 +168,8 @@ static bool enable_zerocopy_output = tru
             bat->theap.storage = batstore;                                           \
                \
             if (batstore == STORE_MMAPABS) {                                         \
                \
                 /* If we are taking data from a MMAP file, set the filename to the \
                absolute path */                     \
-                char address[999];                                                   \
                \
-                snprintf_mmap_file(address, 999, ret->mmap_id);                      \
\ +                char address[100];                                                 \
\ +                GDKmmapfile(address, 100, ret->mmap_id);                           \
                \
                 bat->theap.filename = GDKfilepath(NOFARM, BATDIR, address, "tmp");   \
                \
                 ret->mmap_id = -1;                                                   \
                \
             }                                                                        \
\ @@ -613,8 +613,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
 
 #ifdef HAVE_FORK
     /*[FORK_PROCESS]*/
-    if (mapped)
-    {
+    if (mapped) {
         lng pid;
         //we need 3 + pci->retc * 2 shared memory spaces
         //the first is for the header information
@@ -644,7 +643,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
         assert(memory_size > 0);
         //create the shared memory for the header
         MT_lock_set(&pyapiLock);
-        msg = init_mmap_memory(mmap_id, 0, memory_size, &mmap_ptrs, &mmap_sizes, \
NULL); +        GDKinitmmap(mmap_id + 0, memory_size, &mmap_ptrs[0], &mmap_sizes[0], \
&msg);  MT_lock_unset(&pyapiLock);
         if (msg != MAL_SUCCEED) {
             goto wrapup;
@@ -661,7 +660,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
 
         //create the shared memory space for queries
         MT_lock_set(&pyapiLock);
-        msg = init_mmap_memory(mmap_id, 1, sizeof(QueryStruct), &mmap_ptrs, \
&mmap_sizes, NULL); +        GDKinitmmap(mmap_id + 1, sizeof(QueryStruct), \
&mmap_ptrs[1], &mmap_sizes[1], &msg);  MT_lock_unset(&pyapiLock);
         if (msg != MAL_SUCCEED) {
             goto wrapup;
@@ -688,8 +687,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
         {
             child_process = true;
             query_ptr = NULL;
-            msg = init_mmap_memory(mmap_id, 1, sizeof(QueryStruct), NULL, NULL, \
                (char**)&query_ptr);
-            if (msg != MAL_SUCCEED) {
+            if (GDKinitmmap(mmap_id + 1, sizeof(QueryStruct), (void**) &query_ptr, \
NULL, &msg) != GDK_SUCCEED) {  goto wrapup;
             }
         } else {
@@ -786,9 +784,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
                             query_ptr->mmapid = GDKuniqueid(1); 
                             MT_lock_unset(&pyapiLock);
 
-                            msg = init_mmap_memory(query_ptr->mmapid, 0, size, NULL, \
                NULL, &result_ptr);
-
-                            if (msg != MAL_SUCCEED) {
+                            if (GDKinitmmap(query_ptr->mmapid + 0, size, (void**) \
&result_ptr, NULL, &msg) != GDK_SUCCEED) {  _connection_cleanup_result(output);
                                 GDKchangesemval(query_sem, 1, 1, &msg);
                                 goto wrapup;
@@ -853,15 +849,11 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
             {
                 //a child failed, get the error message from the child
                 ReturnBatDescr *descr = &(((ReturnBatDescr*)mmap_ptr)[0]);
-                char *err_ptr;
 
                 if (descr->bat_size == 0) {
                     msg = createException(MAL, "pyapi.eval", "Failure in child \
                process with unknown error.");
-                } else {
-                    msg = init_mmap_memory(mmap_id, 3, descr->bat_size, &mmap_ptrs, \
                &mmap_sizes, &err_ptr);
-                    if (msg == MAL_SUCCEED) {
-                        msg = createException(MAL, "pyapi.eval", "%s", err_ptr);
-                    }
+                } else if (GDKinitmmap(mmap_id + 3, descr->bat_size, &mmap_ptrs[3], \
&mmap_sizes[3], &msg) == GDK_SUCCEED) { +                    msg = \
createException(MAL, "pyapi.eval", "%s", (char*) mmap_ptrs[3]);  }
                 goto wrapup;
             }
@@ -891,7 +883,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
 
                 assert(total_size > 0);
                 MT_lock_set(&pyapiLock);
-                msg = init_mmap_memory(mmap_id, i + 3, total_size, &mmap_ptrs, \
&mmap_sizes, NULL); +                GDKinitmmap(mmap_id + i + 3, total_size, \
&mmap_ptrs[i + 3], &mmap_sizes[i + 3], &msg);  MT_lock_unset(&pyapiLock);
                 if (msg != MAL_SUCCEED) {
                     goto wrapup;
@@ -907,7 +899,7 @@ str PyAPIeval(Client cntxt, MalBlkPtr mb
 
                     assert(mask_size > 0);
                     MT_lock_set(&pyapiLock);
-                    msg = init_mmap_memory(mmap_id, pci->retc + (i + 3), mask_size, \
&mmap_ptrs, &mmap_sizes, NULL); +                    GDKinitmmap(mmap_id + pci->retc \
+ (i + 3), mask_size, &mmap_ptrs[pci->retc + (i + 3)], &mmap_sizes[pci->retc + (i + \
3)], &msg);  MT_lock_unset(&pyapiLock);
                     if (msg != MAL_SUCCEED) {
                         goto wrapup;
@@ -1357,21 +1349,19 @@ aggrwrapup:
     // We have successfully executed the Python function and converted the result \
                object to a C array
     // Now all that is left is to copy the C array to shared memory so the main \
process can read it and return it  if (mapped && child_process) {
-        char *mmap_ptr;
         ReturnBatDescr *ptr;
 
         // First we will fill in the header information, we will need to get a \
                pointer to the header data first
         // The main process has already created the header data for the child \
process  VERBOSE_MESSAGE("Getting shared memory.\n");
-        msg = init_mmap_memory(mmap_id, 0, memory_size, &mmap_ptrs, &mmap_sizes, \
                &mmap_ptr);
-        if (msg != MAL_SUCCEED) {
+        if (GDKinitmmap(mmap_id + 0, memory_size, &mmap_ptrs[0], &mmap_sizes[0], \
&msg) != GDK_SUCCEED) {  goto wrapup;
         }
 
         VERBOSE_MESSAGE("Writing headers.\n");
 
         // Now we will write data about our result (memory size, type, number of \
                elements) to the header
-        ptr = (ReturnBatDescr*)mmap_ptr;
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic