#ifndef __DatabaseForThread_h_ #define __DatabaseForThread_h_ #include "DatabaseWithRetry.h" /* This is a nice way to share database connections with other users in the * same thread. * * This was originally invented for use with container threads. When using * container threads a lot of unrelated code would all be running in the * same thread, so they could share a database connection, but how would they * communicate if they didn't know about each other? * * Traditional thread code would store the thread connection directly in the * thread object. This worked, but it was often messy. Even though this unit * wasn't required in those cases, it probably would have helped. */ // Name is the serverName passed to the DatabaseWithRetry constructor. // E.g. "@RO" or "wally-balls" or "bender|flexo". DatabaseWithRetry includes // some constants specifically recommended for this purpose, like // DatabaseWithRetry::CANDLES. DatabaseWithRetry *DatabaseForThread(std::string name); // Normally anyone can call DatabaseForThread at any time. It's encouraged. // However, sometimes we try to break up jobs into different threads. We try // to partition the fast requests into one set of threads and the slow requests // into a different set of threads. Call this in a "fast" thread to make sure // on one accidentally tries to access the database in this thread. void assertNoDatabaseThisThread(); // Similar to assertNoDatabaseThisThread(), but this disables a single // database. Other databases are allowed like normal. // assertNoDatabaseThisThread() and disableDatabaseThisThread() are // incompatible. You cannot call them both in the same thread. void disableDatabaseThisThread(std::string const &name); // Do not try to call assertNoDatabaseThisThread() more than once per thread. // Do not try to call disableDatabaseThisThread() more than once per name in // each thread. The current implementation will fail badly if you try. #endif