NodeType FetchFileStatus(const AnyString& filename, yuint64& size, yint64& lastModified, bool followSymLink) { size = 0u; lastModified = 0; return (YUNI_LIKELY(not filename.empty())) ? Stat(filename, size, lastModified, followSymLink) : IO::typeUnknown; }
void QueueService::stop(uint timeout) { std::unique_ptr<ThreadArray> threads; // the thread pool // getting the thread pool { MutexLocker locker(*this); if (pStatus != State::running) return; threads.reset((ThreadArray*) pThreads); pThreads = nullptr; pStatus = State::stopping; } // Destroying the thread pool if (YUNI_LIKELY(threads)) { // stopping all threads (**before** deleting them) threads->stop(timeout); threads.reset(nullptr); } MutexLocker locker(*this); // marking the queue service as stopped, just in case // (thread workers should already marked us as 'stopped') pStatus = State::stopped; // signalling that the queueservice is stopped. This signal // will come after pSignalAllThreadHaveStopped in this case pSignalShouldStop.notify(); }
NodeType TypeOf(const AnyString& filename, bool followSymLink) { yuint64 size; // useless yint64 lastModified; return (YUNI_LIKELY(not filename.empty())) ? Stat(filename, size, lastModified, followSymLink) : IO::typeUnknown; }
bool QueueService::start() { MutexLocker locker(*this); if (YUNI_LIKELY(pStatus == State::stopped)) { pSignalAllThreadHaveStopped.reset(); pSignalShouldStop.reset(); delete (ThreadArray*) pThreads; pThreads = new ThreadArray(); // alias to the thread pool ThreadArray& array = *((ThreadArray*) pThreads); // recreate the thread pool // adding the minimum number of threads array.clear(); for (uint i = 0; i != pMinimumThreadCount; ++i) array += new Yuni::Private::QueueService::QueueThread(*this); // Start all threads at once array.start(); // Ok now we have started pStatus = State::running; } return true; }
DBI::Error Transaction::truncate(const AnyString& tablename) { if (YUNI_UNLIKELY(not IsValidIdentifier(tablename))) return errInvalidIdentifier; assert(!(!pChannel)); // the adapter ::yn_dbi_adapter& adapter = pChannel->adapter; // The DBI interface should provide the most appropriate way for // truncating a table (autoincrement / cascade...) if (YUNI_LIKELY(adapter.truncate)) { return (DBI::Error) adapter.truncate(adapter.dbh, tablename.c_str(), tablename.size()); } else { // Fallback to a failsafe method // -- stmt << "TRUNCATE " << tablename << ';'; // The SQL command Truncate is not supported by all databases. `DELETE FROM` // is not the most efficient way for truncating a table // but it should work almost everywhere String stmt; stmt << "DELETE FROM " << tablename << ';'; return perform(stmt); } }
Cursor Transaction::prepare(const AnyString& stmt) { assert(!(!pChannel)); // the adapter ::yn_dbi_adapter& adapter = pChannel->adapter; if (YUNI_UNLIKELY(nullHandle == pTxHandle)) { if (errNone != pChannel->begin(pTxHandle)) return Cursor(adapter, nullptr); } // query handle void* handle = nullptr; if (YUNI_LIKELY(not stmt.empty() and adapter.dbh)) { assert(adapter.query_new != NULL and "invalid adapter query_new"); assert(adapter.query_ref_acquire != NULL and "invalid adapter query_ref_acquire"); assert(adapter.query_ref_release != NULL and "invalid adapter query_ref_release"); adapter.query_new(&handle, adapter.dbh, stmt.c_str(), stmt.size()); } return Cursor(adapter, handle); }
DBI::Error Transaction::perform(const AnyString& script) { assert(!(!pChannel)); // the adapter ::yn_dbi_adapter& adapter = pChannel->adapter; assert(adapter.query_exec != NULL); if (YUNI_LIKELY(nullHandle != pTxHandle)) { return (DBI::Error) adapter.query_exec(adapter.dbh, script.c_str(), script.size()); } else { // start a new transaction DBI::Error error = pChannel->begin(pTxHandle); if (YUNI_LIKELY(error == errNone)) error = (DBI::Error) adapter.query_exec(adapter.dbh, script.c_str(), script.size()); return error; } }
DBI::Error Transaction::vacuum() { assert(!(!pChannel)); // the adapter ::yn_dbi_adapter& adapter = pChannel->adapter; if (YUNI_LIKELY(adapter.vacuum)) { return (DBI::Error) adapter.vacuum(adapter.dbh); } else { // Fallback to the standard SQL command return perform("VACUUM"); } }