aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Nazaryev <sergey@nazaryev.ru>2016-05-16 17:05:13 +0000
committerSergey Nazaryev <sergey@nazaryev.ru>2016-05-16 17:05:13 +0000
commit850f75c98f2e1c4ea4dcef1bb5c81ede82a96637 (patch)
treedf678517c8cbb0af61a9549076ecfcccf61a86f3
downloaddistcomp-labs-850f75c98f2e1c4ea4dcef1bb5c81ede82a96637.zip
distcomp-labs-850f75c98f2e1c4ea4dcef1bb5c81ede82a96637.tar.gz
distcomp-labs-850f75c98f2e1c4ea4dcef1bb5c81ede82a96637.tar.bz2
Inital release
-rw-r--r--Makefile52
-rw-r--r--common/common.h17
-rw-r--r--common/ipc.h115
3 files changed, 184 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0b429fd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,52 @@
+all: pa1.tar.gz pa2.tar.gz pa3.tar.gz pa4.tar.gz pa5.tar.gz
+
+pa1.tar.gz: pa1
+ make clean -C $<
+ tar -czf $@ pa1/child.{c,h} \
+ pa1/parent.{c,h} \
+ pa1/pa1.c \
+ pa1/main.h \
+ pa1/dist.{c,h} \
+ pa1/.version \
+ pa1/ipc.c
+
+pa2.tar.gz: pa2
+ make clean -C $<
+ tar -czf $@ pa2/child.{c,h} \
+ pa2/parent.{c,h} \
+ pa2/pa23.{c,h} \
+ pa2/ipc.c \
+ pa2/banking.c
+
+pa3.tar.gz: pa3
+ make clean -C $<
+ tar -czf $@ pa3/child.{c,h} \
+ pa3/parent.{c,h} \
+ pa3/pa3.{c,h} \
+ pa3/lamport.{c,h} \
+ pa3/ipc.c \
+ pa3/banking.c
+
+pa4.tar.gz: pa4
+ make clean -C $<
+ tar -czf $@ pa4/child.{c,h} \
+ pa4/parent.{c,h} \
+ pa5/dist.{c,h} \
+ pa4/pa3.{c,h} \
+ pa4/lamport.{c,h} \
+ pa4/queue.{c,h} \
+ pa4/ipc.c \
+ pa4/cs.c
+
+pa5.tar.gz: pa5
+ make clean -C $<
+ tar -czf $@ pa5/child.{c,h} \
+ pa5/parent.{c,h} \
+ pa5/dist.{c,h} \
+ pa5/pa3.{c,h} \
+ pa5/lamport.{c,h} \
+ pa5/ipc.c \
+ pa5/cs.c
+
+clean:
+ rm -f pa1.tar.gz pa2.tar.gz pa3.tar.gz pa4.tar.gz pa5.tar.gz
diff --git a/common/common.h b/common/common.h
new file mode 100644
index 0000000..9be7008
--- /dev/null
+++ b/common/common.h
@@ -0,0 +1,17 @@
+/**
+ * @file common.h
+ * @Author Michael Kosyakov and Evgeniy Ivanov (ifmo.distributedclass@gmail.com)
+ * @date March, 2014
+ * @brief Common definitions and constants for for programming assignments
+ *
+ * Students must not modify this file!
+ */
+
+#ifndef __IFMO_DISTRIBUTED_CLASS_COMMON__H
+#define __IFMO_DISTRIBUTED_CLASS_COMMON__H
+
+// Not extern for simplicity only
+static const char * const events_log = "events.log";
+static const char * const pipes_log = "pipes.log";
+
+#endif // __IFMO_DISTRIBUTED_CLASS_COMMON__H
diff --git a/common/ipc.h b/common/ipc.h
new file mode 100644
index 0000000..8bc5a9e
--- /dev/null
+++ b/common/ipc.h
@@ -0,0 +1,115 @@
+/**
+ * @file ipc.h
+ * @Author Michael Kosyakov and Evgeniy Ivanov (ifmo.distributedclass@gmail.com)
+ * @date March, 2014
+ * @brief A simple IPC library for programming assignments
+ *
+ * Students must not modify this file!
+ */
+
+#ifndef __IFMO_DISTRIBUTED_CLASS_IPC__H
+#define __IFMO_DISTRIBUTED_CLASS_IPC__H
+
+#include <stddef.h>
+#include <stdint.h>
+
+//------------------------------------------------------------------------------
+
+typedef int8_t local_id;
+typedef int16_t timestamp_t;
+
+enum {
+ MESSAGE_MAGIC = 0xAFAF,
+ MAX_MESSAGE_LEN = 4096,
+ PARENT_ID = 0,
+ MAX_PROCESS_ID = 15
+};
+
+typedef enum {
+ STARTED = 0, ///< message with string (doesn't include trailing '\0')
+ DONE, ///< message with string (doesn't include trailing '\0')
+ ACK, ///< empty message
+ STOP, ///< empty message
+ TRANSFER, ///< message with TransferOrder
+ BALANCE_HISTORY, ///< message with BalanceHistory
+ CS_REQUEST, ///< empty message
+ CS_REPLY, ///< empty message
+ CS_RELEASE ///< empty message
+} MessageType;
+
+typedef struct {
+ uint16_t s_magic; ///< magic signature, must be MESSAGE_MAGIC
+ uint16_t s_payload_len; ///< length of payload
+ int16_t s_type; ///< type of the message
+ timestamp_t s_local_time; ///< set by sender, depends on particular PA:
+ ///< physical time in PA2 or Lamport's scalar
+ ///< time in PA3
+} __attribute__((packed)) MessageHeader;
+
+enum {
+ MAX_PAYLOAD_LEN = MAX_MESSAGE_LEN - sizeof(MessageHeader)
+};
+
+typedef struct {
+ MessageHeader s_header;
+ char s_payload[MAX_PAYLOAD_LEN]; ///< Must be used as a buffer, unused "tail"
+ ///< shouldn't be transfered
+} __attribute__((packed)) Message;
+
+//------------------------------------------------------------------------------
+
+/** Send a message to the process specified by id.
+ *
+ * @param self Any data structure implemented by students to perform I/O
+ * @param dst ID of recepient
+ * @param msg Message to send
+ *
+ * @return 0 on success, any non-zero value on error
+ */
+int send(void * self, local_id dst, const Message * msg);
+
+//------------------------------------------------------------------------------
+
+/** Send multicast message.
+ *
+ * Send msg to all other processes including parrent.
+ * Should stop on the first error.
+ *
+ * @param self Any data structure implemented by students to perform I/O
+ * @param msg Message to multicast.
+ *
+ * @return 0 on success, any non-zero value on error
+ */
+int send_multicast(void * self, const Message * msg);
+
+//------------------------------------------------------------------------------
+
+/** Receive a message from the process specified by id.
+ *
+ * Might block depending on IPC settings.
+ *
+ * @param self Any data structure implemented by students to perform I/O
+ * @param from ID of the process to receive message from
+ * @param msg Message structure allocated by the caller
+ *
+ * @return 0 on success, any non-zero value on error
+ */
+int receive(void * self, local_id from, Message * msg);
+
+//------------------------------------------------------------------------------
+
+/** Receive a message from any process.
+ *
+ * Receive a message from any process, in case of blocking I/O should be used
+ * with extra care to avoid deadlocks.
+ *
+ * @param self Any data structure implemented by students to perform I/O
+ * @param msg Message structure allocated by the caller
+ *
+ * @return 0 on success, any non-zero value on error
+ */
+int receive_any(void * self, Message * msg);
+
+//------------------------------------------------------------------------------
+
+#endif // __IFMO_DISTRIBUTED_CLASS_IPC__H