Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1299655

[RFC 01/31] mars: add new module lamport

From Thomas Schoebel-Theuer <tst@schoebel-theuer.de>
Newsgroups linux.kernel
Subject [RFC 01/31] mars: add new module lamport
Date 2015-12-31 12:50 +0100
Message-ID <qLJTY-3U9-39@gated-at.bofh.it> (permalink)
References <qLJKi-3PB-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Signed-off-by: Thomas Schoebel-Theuer <tst@schoebel-theuer.de>
---
 drivers/staging/mars/lamport.c | 61 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/brick/lamport.h  | 26 ++++++++++++++++++
 2 files changed, 87 insertions(+)
 create mode 100644 drivers/staging/mars/lamport.c
 create mode 100644 include/linux/brick/lamport.h

diff --git a/drivers/staging/mars/lamport.c b/drivers/staging/mars/lamport.c
new file mode 100644
index 0000000..373093f
--- /dev/null
+++ b/drivers/staging/mars/lamport.c
@@ -0,0 +1,61 @@
+/*
+ * MARS Long Distance Replication Software
+ *
+ * Copyright (C) 2010-2014 Thomas Schoebel-Theuer
+ * Copyright (C) 2011-2014 1&1 Internet AG
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/semaphore.h>
+
+#include <linux/brick/lamport.h>
+
+/*  TODO: replace with spinlock if possible (first check) */
+struct semaphore lamport_sem = __SEMAPHORE_INITIALIZER(lamport_sem, 1);
+struct timespec lamport_now = {};
+
+void get_lamport(struct timespec *now)
+{
+	int diff;
+
+	down(&lamport_sem);
+
+	*now = CURRENT_TIME;
+	diff = timespec_compare(now, &lamport_now);
+	if (diff >= 0) {
+		timespec_add_ns(now, 1);
+		memcpy(&lamport_now, now, sizeof(lamport_now));
+		timespec_add_ns(&lamport_now, 1);
+	} else {
+		timespec_add_ns(&lamport_now, 1);
+		memcpy(now, &lamport_now, sizeof(*now));
+	}
+
+	up(&lamport_sem);
+}
+
+void set_lamport(struct timespec *old)
+{
+	int diff;
+
+	down(&lamport_sem);
+
+	diff = timespec_compare(old, &lamport_now);
+	if (diff >= 0) {
+		memcpy(&lamport_now, old, sizeof(lamport_now));
+		timespec_add_ns(&lamport_now, 1);
+	}
+
+	up(&lamport_sem);
+}
diff --git a/include/linux/brick/lamport.h b/include/linux/brick/lamport.h
new file mode 100644
index 0000000..9aac0ce
--- /dev/null
+++ b/include/linux/brick/lamport.h
@@ -0,0 +1,26 @@
+/*
+ * MARS Long Distance Replication Software
+ *
+ * Copyright (C) 2010-2014 Thomas Schoebel-Theuer
+ * Copyright (C) 2011-2014 1&1 Internet AG
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ */
+
+#ifndef LAMPORT_H
+#define LAMPORT_H
+
+#include <linux/time.h>
+
+extern void get_lamport(struct timespec *now);
+extern void set_lamport(struct timespec *old);
+
+#endif
-- 
2.6.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[RFC 00/31] Current state of MARS Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:40 +0100
  [RFC 07/31] mars: add new module lib_pairing_heap Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:40 +0100
  [RFC 31/31] mars: activate build Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:40 +0100
  [RFC 04/31] mars: add new module brick_checking Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 29/31] mars: add new module Makefile Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 17/31] mars: add new module xio_bio Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 15/31] mars: add new module lib_mapfree Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 27/31] mars: add new module mars_proc Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 21/31] mars: add new module xio_copy Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 20/31] mars: add new module xio_if Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 13/31] mars: add new module xio Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 25/31] mars: add new module light_net Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 23/31] mars: add new module xio_server Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 01/31] mars: add new module lamport Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 19/31] mars: add new module xio_client Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 11/31] mars: add new module lib_timing Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 08/31] mars: add new module lib_queue Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 18/31] mars: add new module xio_sio Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 16/31] mars: add new module lib_log Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100
  [RFC 26/31] mars: add new module light_server_strategy Thomas Schoebel-Theuer <tst@schoebel-theuer.de> - 2015-12-31 12:50 +0100

csiph-web