| 154 | bool Hooks::_initialized = false; |
| 155 | |
| 156 | bool Hooks::init(bool attach) { |
| 157 | if (!__sync_bool_compare_and_swap(&_initialized, false, true)) { |
| 158 | return false; |
| 159 | } |
| 160 | |
| 161 | Profiler::setupSignalHandlers(); |
| 162 | |
| 163 | if (attach) { |
| 164 | Profiler::instance()->updateSymbols(false); |
| 165 | _orig_pthread_create = ADDRESS_OF(pthread_create); |
| 166 | _orig_pthread_exit = ADDRESS_OF(pthread_exit); |
| 167 | _orig_dlopen = ADDRESS_OF(dlopen); |
| 168 | patchLibraries(); |
| 169 | } |
| 170 | |
| 171 | atexit(shutdown); |
| 172 | |
| 173 | return true; |
| 174 | } |
| 175 | |
| 176 | void Hooks::shutdown() { |
| 177 | Profiler::instance()->shutdown(_global_args); |