From f9859ad4116733e145d7b8eb31c3cc9318ff7564 Mon Sep 17 00:00:00 2001 From: "graehl@gmail.com" Date: Mon, 2 Aug 2010 07:57:23 +0000 Subject: fake tdict names for non-ids, push viterbi cost to root in hg, store as feature. type erased fsa feature via virtual interface. made lexical_cast assume C locale for speed. git-svn-id: https://ws10smt.googlecode.com/svn/trunk@465 ec762483-ff6d-05da-a07a-a48fb63a330f --- decoder/threadlocal.h | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 decoder/threadlocal.h (limited to 'decoder/threadlocal.h') diff --git a/decoder/threadlocal.h b/decoder/threadlocal.h new file mode 100755 index 00000000..d79f5d9d --- /dev/null +++ b/decoder/threadlocal.h @@ -0,0 +1,71 @@ +#ifndef THREADLOCAL_H +#define THREADLOCAL_H + +#ifndef SETLOCAL_SWAP +# define SETLOCAL_SWAP 0 +#endif + +#ifdef BOOST_NO_MT + +# define THREADLOCAL + +#else + +#ifdef _MSC_VER + +//FIXME: doesn't work with DLLs ... use TLS apis instead (http://www.boost.org/libs/thread/doc/tss.html) +# define THREADLOCAL __declspec(thread) + +#else + +# define THREADLOCAL __thread + +#endif + +#endif + +#include //swap + +// naturally, the below are only thread-safe if value is THREADLOCAL +template +struct SaveLocal { + D &value; + D old_value; + SaveLocal(D& val) : value(val), old_value(val) {} + ~SaveLocal() { +#if SETLOCAL_SWAP + swap(value,old_value); +#else + value=old_value; +#endif + } +}; + +template +struct SetLocal { + D &value; + D old_value; + SetLocal(D& val,const D &new_value) : value(val), old_value( +#if SETLOCAL_SWAP + new_value +#else + val +#endif + ) { +#if SETLOCAL_SWAP + swap(value,old_value); +#else + value=new_value; +#endif + } + ~SetLocal() { +#if SETLOCAL_SWAP + swap(value,old_value); +#else + value=old_value; +#endif + } +}; + + +#endif -- cgit v1.2.3