#ifndef __ThreadScope_h__ #define __ThreadScope_h__ namespace core { /// /// ThreadScope /// /// Extension point for per-OS-thread setup/teardown in an EPoll worker /// pool. EPoll's threads are long-lived (one persistent event loop per /// thread, for the process's whole lifetime, not spawned per-request) - /// onThreadStart() runs once at the top of each thread, before it /// enters its event loop; onThreadEnd() runs once as that thread is /// shutting down. A single ThreadScope instance is shared across every /// worker thread (passed to EPoll::start()), so overrides should only /// touch thread-LOCAL state from these hooks, never the ThreadScope /// object's own fields, without their own synchronization. /// /// Concrete motivating case: a C library that requires explicit /// per-thread initialization before use from a multi-threaded program /// (e.g. the MySQL client library's mysql_thread_init()/ /// mysql_thread_end() - see APIServer's MysqlThreadScope) has no other /// clean way to hook into an EPoll worker thread's lifetime. /// class ThreadScope { public: ThreadScope() {} virtual ~ThreadScope() {} virtual void onThreadStart() {} virtual void onThreadEnd() {} }; } #endif