summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <abaumann@yahoo.com>2012-08-21 09:39:49 +0200
committerAndreas Baumann <abaumann@yahoo.com>2012-08-21 09:39:49 +0200
commitcf1f5367d2a87cb0585009f343eeb3350efbb076 (patch)
treee97befc8c3a54a9f6d89457797537672b837706a
parente9dde47720316d5450c434121989c4b524fe79a6 (diff)
downloadcrawler-cf1f5367d2a87cb0585009f343eeb3350efbb076.tar.gz
crawler-cf1f5367d2a87cb0585009f343eeb3350efbb076.tar.bz2
fixed singleton double-instance problem on Windows, not a really nice solution
-rwxr-xr-xTODOS11
-rwxr-xr-x[-rw-r--r--]src/NonCopyable.hpp12
-rwxr-xr-x[-rw-r--r--]src/Singleton.hpp0
-rwxr-xr-xtests/modules/Common.hpp10
-rwxr-xr-xtests/modules/Makefile.W322
-rwxr-xr-xtests/modules/testmod2/Makefile.W323
6 files changed, 33 insertions, 5 deletions
diff --git a/TODOS b/TODOS
index f672b09..a0a396e 100755
--- a/TODOS
+++ b/TODOS
@@ -1,5 +1,14 @@
- singleton with registered pointers, so they can be shared between
- loadable modules on Windows, example is the logger singleton currently
+ loadable modules on Windows, example is the logger singleton currently:
+ - exported data segments
+ #pragma data_seg("SHARED")
+ #pragma data_seg()
+ #pragma comment(linker, "/section:SHARED,RWS")
+ - http://support.microsoft.com/kb/168958/en-us
+ - http://www.xing.com/net/moderncpp/allgemeines-zu-c-101269/singletons-in-dll-s-32375749
+ - http://stackoverflow.com/questions/1880052/c-duplicated-static-member
+ - http://stackoverflow.com/questions/4911994/sharing-a-global-static-variable-between-a-process-and-dll
+ - http://www.ogre3d.org/forums/viewtopic.php?p=75622&sid=ce193664e1d3d7c4af509e6f4e2718c6
- rewrite logger as proper singleton
- use traits in rewindinputstream, alternative wrappers for char/string
traits depending on underlying io stream
diff --git a/src/NonCopyable.hpp b/src/NonCopyable.hpp
index de43d5d..f56802c 100644..100755
--- a/src/NonCopyable.hpp
+++ b/src/NonCopyable.hpp
@@ -3,8 +3,16 @@
namespace __dont_touch
{
-
-class noncopyable
+
+#ifndef SHARED
+#define SINGLETON_EXPORT __declspec(dllexport)
+#define SINGLETON_EXTERN
+#else
+#define SINGLETON_EXPORT __declspec(dllimport)
+#define SINGLETON_EXTERN extern
+#endif
+
+class SINGLETON_EXPORT noncopyable
{
protected:
noncopyable( ) { }
diff --git a/src/Singleton.hpp b/src/Singleton.hpp
index 2bdf257..2bdf257 100644..100755
--- a/src/Singleton.hpp
+++ b/src/Singleton.hpp
diff --git a/tests/modules/Common.hpp b/tests/modules/Common.hpp
index dc1f22a..4be89bb 100755
--- a/tests/modules/Common.hpp
+++ b/tests/modules/Common.hpp
@@ -20,4 +20,14 @@ class Common : public Singleton< Common >
void print( string s ) { cout << m_name << ": " << s << endl; }
};
+#ifndef SHARED
+#define SINGLETON_EXPORT __declspec(dllexport)
+#define SINGLETON_EXTERN
+#else
+#define SINGLETON_EXPORT __declspec(dllimport)
+#define SINGLETON_EXTERN extern
+#endif
+
+SINGLETON_EXTERN template class SINGLETON_EXPORT Singleton< Common >;
+
#endif
diff --git a/tests/modules/Makefile.W32 b/tests/modules/Makefile.W32
index 8a745a0..6dfa78b 100755
--- a/tests/modules/Makefile.W32
+++ b/tests/modules/Makefile.W32
@@ -27,7 +27,7 @@ OBJS =
test1.exe: test1.obj
test2.exe: test2.obj
-local_all:
+local_all: test2.exe
local_clean:
@-erase -f *.RES *.DIFF *.ERR 2>NUL
diff --git a/tests/modules/testmod2/Makefile.W32 b/tests/modules/testmod2/Makefile.W32
index 9640019..f1ae5e1 100755
--- a/tests/modules/testmod2/Makefile.W32
+++ b/tests/modules/testmod2/Makefile.W32
@@ -15,7 +15,8 @@ INCLUDE_DIRS = \
INCLUDE_LDFLAGS = \
INCLUDE_LIBS = \
- $(TOPDIR)\src\crawler.lib
+ $(TOPDIR)\src\crawler.lib \
+ ..\test2.lib
DYNAMIC_MODULE = \
mod_test2.dll