| 3237 | namespace { |
| 3238 | |
| 3239 | class ThreadCleanup |
| 3240 | { |
| 3241 | public: |
| 3242 | static void add(FPTR_VOID_PTR cleanup, void* arg); |
| 3243 | static void remove(FPTR_VOID_PTR cleanup, void* arg); |
| 3244 | static void destructor(void*); |
| 3245 | |
| 3246 | static void assertNoCleanupChain() |
| 3247 | { |
| 3248 | fb_assert(!chain); |
| 3249 | } |
| 3250 | |
| 3251 | private: |
| 3252 | FPTR_VOID_PTR function; |
| 3253 | void* argument; |
| 3254 | ThreadCleanup* next; |
| 3255 | |
| 3256 | static ThreadCleanup* chain; |
| 3257 | static GlobalPtr<Mutex> cleanupMutex; |
| 3258 | |
| 3259 | ThreadCleanup(FPTR_VOID_PTR cleanup, void* arg, ThreadCleanup* chain) |
| 3260 | : function(cleanup), argument(arg), next(chain) { } |
| 3261 | |
| 3262 | static void initThreadCleanup(); |
| 3263 | static void finiThreadCleanup(); |
| 3264 | |
| 3265 | static ThreadCleanup** findCleanup(FPTR_VOID_PTR cleanup, void* arg); |
| 3266 | }; |
| 3267 | |
| 3268 | ThreadCleanup* ThreadCleanup::chain = NULL; |
| 3269 | GlobalPtr<Mutex> ThreadCleanup::cleanupMutex; |