From 4516ba618a3364bd4f769dd81e3a592c4a9c8a51 Mon Sep 17 00:00:00 2001 From: Geraldo Luis da Silva Ribeiro Date: Tue, 26 Apr 2016 20:20:46 -0300 Subject: [PATCH] Port to OSX. --- Makefile | 2 ++ example.cc | 3 ++- lmdb++.h | 12 +++++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a548411..a75452c 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,7 @@ check: check.o $(CXX) $(LDFLAGS) -o $@ $^ $(LDADD) && ./$@ example: example.o + $(MKDIR) env $(CXX) $(LDFLAGS) -o $@ $^ $(LDADD) && ./$@ %.o: %.cc lmdb++.h @@ -51,6 +52,7 @@ uninstall: $(RM) $(DESTDIR)$(includedir)/lmdb++.h clean: + $(RM) env/* $(RM) README.html README.md check example $(PACKAGE_TARSTRING).tar.* *.o *~ README: README.html README.md diff --git a/example.cc b/example.cc index 171f6f8..a0fb3b9 100644 --- a/example.cc +++ b/example.cc @@ -8,7 +8,8 @@ int main() { /* Create and open the LMDB environment: */ auto env = lmdb::env::create(); env.set_mapsize(1UL * 1024UL * 1024UL * 1024UL); /* 1 GiB */ - env.open("./example.mdb", 0, 0664); + //env.open("./example.mdb", 0, 0664); + env.open( "./env" ); /* Insert some key/value pairs in a write transaction: */ auto wtxn = lmdb::txn::begin(env); diff --git a/lmdb++.h b/lmdb++.h index ab75f8c..8d51c89 100644 --- a/lmdb++.h +++ b/lmdb++.h @@ -20,6 +20,16 @@ #endif // _MSC_VER check #endif +#if HAS_CXX11_THREAD_LOCAL + #define ATTRIBUTE_TLS thread_local +#elif defined (__GNUC__) + #define ATTRIBUTE_TLS __thread +#elif defined (_MSC_VER) + #define ATTRIBUTE_TLS __declspec(thread) +#else // !C++11 && !__GNUC__ && !_MSC_VER + #error "Define a thread local storage qualifier for your compiler/platform!" +#endif + //////////////////////////////////////////////////////////////////////////////// #include /* for MDB_*, mdb_*() */ @@ -96,7 +106,7 @@ class lmdb::error : public std::runtime_error { * Returns the underlying LMDB error code. */ virtual const char* what() const noexcept { - static thread_local char buffer[1024]; + static ATTRIBUTE_TLS char buffer[1024]; std::snprintf(buffer, sizeof(buffer), "%s: %s", origin(), ::mdb_strerror(code())); return buffer;