[sheepdog] [PATCH v2 04/10] move work queue codes from sheep to lib

MORITA Kazutaka morita.kazutaka at gmail.com
Mon May 13 17:11:12 CEST 2013


From: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/Makefile.am       |    2 +-
 {sheep => include}/work.h |   26 ++++++++++++++++++++++++++
 lib/Makefile.am           |    2 +-
 {sheep => lib}/work.c     |    0
 sheep/Makefile.am         |    4 ++--
 sheep/sheep_priv.h        |   26 --------------------------
 6 files changed, 30 insertions(+), 30 deletions(-)
 rename {sheep => include}/work.h (66%)
 rename {sheep => lib}/work.c (100%)

diff --git a/include/Makefile.am b/include/Makefile.am
index 84bec41..0acb76e 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -2,4 +2,4 @@ MAINTAINERCLEANFILES    = Makefile.in config.h.in
 
 noinst_HEADERS          = bitops.h event.h logger.h sheepdog_proto.h util.h \
 			  list.h net.h sheep.h exits.h strbuf.h rbtree.h \
-			  sha1.h option.h internal_proto.h shepherd.h
+			  sha1.h option.h internal_proto.h shepherd.h work.h
diff --git a/sheep/work.h b/include/work.h
similarity index 66%
rename from sheep/work.h
rename to include/work.h
index 0317b00..dc95791 100644
--- a/sheep/work.h
+++ b/include/work.h
@@ -24,6 +24,32 @@ enum wq_thread_control {
 	WQ_UNLIMITED, /* Unlimited # of threads created */
 };
 
+static inline bool is_main_thread(void)
+{
+	return gettid() == getpid();
+}
+
+static inline bool is_worker_thread(void)
+{
+	return !is_main_thread();
+}
+
+/*
+ * Helper macros to guard variables from being accessed out of the
+ * main thread.  Note that we can use these only for pointers.
+ */
+#define main_thread(type) struct { type __val; }
+#define main_thread_get(var)			\
+({						\
+	assert(is_main_thread());		\
+	(var).__val;				\
+})
+#define main_thread_set(var, val)		\
+({						\
+	assert(is_main_thread());		\
+	(var).__val = (val);			\
+})
+
 /*
  * 'get_nr_nodes' is the function to get the current number of nodes and used
  * for dynamic work queues.  'create_cb' will be called when worker threads are
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 7d4f93a..a95ce4c 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -5,7 +5,7 @@ INCLUDES                = -I$(top_builddir)/include -I$(top_srcdir)/include
 noinst_LIBRARIES	= libsheepdog.a
 
 libsheepdog_a_SOURCES	= event.c logger.c net.c util.c rbtree.c strbuf.c \
-			  sha1.c option.c
+			  sha1.c option.c work.c
 
 # support for GNU Flymake
 check-syntax:
diff --git a/sheep/work.c b/lib/work.c
similarity index 100%
rename from sheep/work.c
rename to lib/work.c
diff --git a/sheep/Makefile.am b/sheep/Makefile.am
index 32bc1c0..0854cbc 100644
--- a/sheep/Makefile.am
+++ b/sheep/Makefile.am
@@ -24,7 +24,7 @@ INCLUDES		= -I$(top_builddir)/include -I$(top_srcdir)/include \
 
 sbin_PROGRAMS		= sheep
 
-sheep_SOURCES		= sheep.c group.c request.c gateway.c store.c vdi.c work.c \
+sheep_SOURCES		= sheep.c group.c request.c gateway.c store.c vdi.c \
 			  journal.c ops.c recovery.c cluster/local.c \
 			  object_cache.c object_list_cache.c sockfd_cache.c \
 			  plain_store.c config.c migrate.c md.c \
@@ -48,7 +48,7 @@ sheep_LDADD	  	= ../lib/libsheepdog.a -lpthread -lm\
 sheep_DEPENDENCIES	= ../lib/libsheepdog.a
 
 
-noinst_HEADERS		= work.h sheep_priv.h cluster.h farm/farm.h trace/trace.h
+noinst_HEADERS		= sheep_priv.h cluster.h farm/farm.h trace/trace.h
 
 EXTRA_DIST		= 
 
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index ab2636a..27aec3f 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -214,32 +214,6 @@ extern struct store_driver *sd_store;
 extern char *obj_path;
 extern char *epoch_path;
 
-static inline bool is_main_thread(void)
-{
-	return gettid() == getpid();
-}
-
-static inline bool is_worker_thread(void)
-{
-	return !is_main_thread();
-}
-
-/*
- * Helper macros to guard variables from being accessed out of the
- * main thread.  Note that we can use these only for pointers.
- */
-#define main_thread(type) struct { type __val; }
-#define main_thread_get(var)			\
-({						\
-	assert(is_main_thread());		\
-	(var).__val;				\
-})
-#define main_thread_set(var, val)		\
-({						\
-	assert(is_main_thread());		\
-	(var).__val = (val);			\
-})
-
 /* One should call this function to get sys->epoch outside main thread */
 static inline uint32_t sys_epoch(void)
 {
-- 
1.7.9.5




More information about the sheepdog mailing list