Skip to content

Commit

Permalink
Merge pull request #501 from mikekaganski/master
Browse files Browse the repository at this point in the history
thread_local: one more (hopefully portable) attempt
  • Loading branch information
ibell committed Feb 25, 2015
2 parents f2e23cd + 4c84211 commit 004d497
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions include/CoolPropTools.h
Expand Up @@ -37,6 +37,27 @@
#include <pwd.h>
#endif

// see http://stackoverflow.com/questions/18298280/how-to-declare-a-variable-as-thread-local-portably
#ifndef thread_local
#if __STDC_VERSION__ >= 201112 && !defined __STDC_NO_THREADS__
# define thread_local _Thread_local
#elif defined _WIN32 && ( \
defined _MSC_VER || \
defined __ICL || \
defined __DMC__ || \
defined __BORLANDC__ )
#define thread_local __declspec(thread)
/* note that ICC (linux) and Clang are covered by __GNUC__ */
#elif defined __GNUC__ || \
defined __SUNPRO_C || \
defined __xlC__
#define thread_local __thread
#else
#error "Cannot define thread_local"
// #define thread_local
#endif
#endif

typedef long double CoolPropDbl;

#ifndef M_PI
Expand Down
2 changes: 1 addition & 1 deletion src/CoolPropTools.cpp
Expand Up @@ -17,7 +17,7 @@
#include <stdint.h>
#include <iostream>

static unsigned long long ftw_summer; // An evil global variable for the ftw function
static thread_local unsigned long long ftw_summer; // An evil global variable for the ftw function
int ftw_function(const char *fpath, const struct stat *sb, int tflag, struct FTW *ftwbuf){
ftw_summer += sb->st_size;
return 0; /* To tell nftw() to continue */
Expand Down

0 comments on commit 004d497

Please sign in to comment.