예제 #1
0
	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;
	}
예제 #2
0
파일: service.cpp 프로젝트: libyuni/libyuni
	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();
	}
예제 #3
0
	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;
	}
예제 #4
0
파일: service.cpp 프로젝트: libyuni/libyuni
	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;
	}
예제 #5
0
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);
    }
}
예제 #6
0
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);
}
예제 #7
0
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;
    }
}
예제 #8
0
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");
    }
}