Переглянути джерело

Created stubs for malloc, free, ...

max 8 роки тому
батько
коміт
f2ff8ee596
4 змінених файлів з 80 додано та 5 видалено
  1. 3 2
      src/myco-ipc.h
  2. 37 0
      src/myco-memory.c
  3. 33 0
      src/myco-memory.h
  4. 7 3
      test/worker.c

+ 3 - 2
src/myco-ipc.h

@@ -15,10 +15,11 @@
 
 /**
  * SECTION: myco-ipc
- * @Short_description: common header for ipc between agents and daemon
+ * @Short_description: common header for ipc between agents, workers and daemon
  * @Title: MycoIpc
  *
- * MycoIpc organizes the message queues that are used between daemon and agents.
+ * MycoIpc organizes the message queues that are used between agents, workers 
+ * and daemons.
  */
 
 #ifndef __MYCO_IPC_H

+ 37 - 0
src/myco-memory.c

@@ -0,0 +1,37 @@
+/* Copyright (C) 2016 Max Riechelmann <max.riechelmann@student.kit.edu>
+   (Karlsruhe Institute of Technology)
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published by the
+   Free Software Foundation; either version 2.1 of the License, or (at your
+   option) any later version.
+   This library is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+   details.
+   You should have received a copy of the GNU Lesser General Public License along
+   with this library; if not, write to the Free Software Foundation, Inc., 51
+   Franklin St, Fifth Floor, Boston, MA 02110, USA
+   */
+
+
+#include "myco-memory.h"
+
+void *myco_malloc(size_t size) {
+    void *ptr;
+    ptr = malloc(size);
+    return ptr;
+}
+
+void myco_free(void *ptr) {
+    return free(ptr);
+}
+
+void *myco_calloc(size_t nmeb, size_t size) {
+    fprintf(stderr, "calloc is not implemented, use malloc and free");
+    return NULL;
+}
+
+void *myco_realloc(void *ptr, size_t size) {
+    fprintf(stderr, "realloc is not implemented, use malloc and free");
+    return NULL;
+}

+ 33 - 0
src/myco-memory.h

@@ -0,0 +1,33 @@
+/* Copyright (C) 2016 Max Riechelmann <max.riechelmann@student.kit.edu>
+   (Karlsruhe Institute of Technology)
+   This library is free software; you can redistribute it and/or modify it
+   under the terms of the GNU Lesser General Public License as published by the
+   Free Software Foundation; either version 2.1 of the License, or (at your
+   option) any later version.
+   This library is distributed in the hope that it will be useful, but WITHOUT
+   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+   FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+   details.
+   You should have received a copy of the GNU Lesser General Public License along
+   with this library; if not, write to the Free Software Foundation, Inc., 51
+   Franklin St, Fifth Floor, Boston, MA 02110, USA
+   */
+
+/**
+ * SECTION: myco-memory
+ * @Short_description: memory management implementation.
+ * @Title: MycoMemory
+ *
+ * MycoMemory provides the common memory routines (malloc, free, ...) due to the
+ * fact that our transactional approach relies on giving freed pages back to the
+ * operating system. The default free implementation does not have that feature.
+ */
+
+#ifndef __MYCO_MEMORY_H
+#define __MYCO_MEMORY_H
+
+#include <stdlib.h>
+#include <signal.h>
+#include <sys/uio.h>
+
+#endif //__MYCO_MEMORY_H

+ 7 - 3
test/worker.c

@@ -11,19 +11,23 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "../src/myco-ipc.c"
+#include "../src/myco-memory.c"
 
 int main(int argc, char **argv) {
+    void *resource_pointer;
+    int resource_size;
     int message_queue_id;
     message msg;
-
     message_queue_id = atoi(argv[0]);
-    printf("Worker is running with message queue id %d.\n", message_queue_id);
 
-    sprintf(msg.message, "FOOBAR\n");
+    resource_size = 1024;
+    resource_pointer = myco_malloc(resource_size);
 
+    sprintf(msg.message, "ALLOCATED MEMORY OF SIZE %d AT %p\n", resource_size, resource_pointer);
     myco_send(message_queue_id, msg);
 
 
+    myco_free(resource_pointer);
     while (1)
         sleep(1);