diff options
| author | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-02-09 17:35:28 +0900 |
|---|---|---|
| committer | Shinichiro Hamaji <shinichiro.hamaji@gmail.com> | 2016-02-09 17:37:07 +0900 |
| commit | d18c4275b6ad20c462a30fbb95bf93df33449415 (patch) | |
| tree | e5297e80992fc976b85c36d11963207579a81084 /symtab.cc | |
| parent | ac50ff4d3826924532f0a6180efe39a40860db55 (diff) | |
[C++] Make it possible to check the thread-safety of Symtab
Intern is used everywhere, we can easily introduce race
conditions by using it.
Diffstat (limited to 'symtab.cc')
| -rw-r--r-- | symtab.cc | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -14,8 +14,13 @@ // +build ignore +//#define ENABLE_TID_CHECK + #include "symtab.h" +#ifdef ENABLE_TID_CHECK +#include <pthread.h> +#endif #include <string.h> #include <unordered_map> @@ -35,6 +40,10 @@ Symbol::Symbol(int v) class Symtab { public: Symtab() { +#ifdef ENABLE_TID_CHECK + tid_ = pthread_self(); +#endif + CHECK(g_symbols == NULL); g_symbols = &symbols_; @@ -72,6 +81,11 @@ class Symtab { } Symbol Intern(StringPiece s) { +#ifdef ENABLE_TID_CHECK + if (tid_ != pthread_self()) + abort(); +#endif + if (s.size() <= 1) { return Symbol(s.empty() ? 0 : (unsigned char)s[0]); } @@ -81,6 +95,9 @@ class Symtab { private: unordered_map<StringPiece, Symbol> symtab_; vector<string*> symbols_; +#ifdef ENABLE_TID_CHECK + pthread_t tid_; +#endif }; static Symtab* g_symtab; |
