Exemplo n.º 1
0
void AnotherMainWindow::on_CreateDir_accepted()
{
    switch(_createDirP->OperationType)
    {
    case DirWorker::Create:
        _dirWorker->CreateNewDir(_createDirP->DirName);
        break;
    case DirWorker::SetCurrent:
        _dirWorker->SetCurrentDir(_createDirP->DirName);
        on_CurrentDir_changed();
        break;
    case DirWorker::Delete:
        _dirWorker->DeleteDir(_createDirP->DirName);
        break;
    case DirWorker::FromDir:
        _taskOptions->FromDir = _createDirP->DirName;
        _taskOptions->FromDirSet = true;
        _createDirP = new DirCreateParams();
        _createDirP->DialogTitle = "Куда копировать";
        _createDirP->OperationType = DirWorker::ToDir;
        _createDirDialog->ShowDialog( _createDirP);
        break;
    case DirWorker::ToDir:
        _taskOptions->ToDir = _createDirP->DirName;
        if(_taskOptions->FromDirSet)
            DoTask();
        break;
    }
}
Exemplo n.º 2
0
void CEmitter::operator()() const
{
	TRACE(_T("hello this is emitter thread!\n"));
	concurrency::parallel_for(size_t(0), size_t(50), [&](size_t i)
	{
		//TRACE(_T("%d\n"),i);
		DoTask(i);
	});
}
Exemplo n.º 3
0
void WaitForFinished(std::shared_ptr<ITaskGroup> taskgroup)
{
	while (DoTask(taskgroup)) {
	}

	while (!taskgroup->wait_for(boost::chrono::seconds(5))) {
		LOG_L(L_WARNING, "Hang in ThreadPool");
	}

	//LOG("WaitForFinished %i", taskgroup->GetExceptions().size());
	//for (auto& r: taskgroup->results())
	//	r.get();
}
Exemplo n.º 4
0
INT WINAPI YDWEStartup(HINSTANCE current, HINSTANCE previous, LPSTR pCommandLine, INT showType)
{
	INT exitCode = -1;

	try
	{
		DoTask();
		exitCode = 0;
	}
	catch (std::exception const& e)
	{
		MessageBoxW(NULL, ydwe::util::u2w_ref(e.what()).c_str(), __("Error"), MB_OK | MB_ICONERROR);
	}
	catch (...)
	{
		MessageBoxW(NULL, __("Unknown error"), __("Error"), MB_OK | MB_ICONERROR);
	}

	return exitCode;
}
Exemplo n.º 5
0
__FORCE_ALIGN_STACK__
static void WorkerLoop(int id)
{
	SetThreadNum(id);
	Threading::SetThreadName(IntToString(id, "worker%i"));
	boost::shared_lock<boost::shared_mutex> lk(taskMutex, boost::defer_lock);
	boost::mutex m;
	boost::unique_lock<boost::mutex> lk2(m);

	while (!exitThread) {
		const auto spinlockStart = boost::chrono::high_resolution_clock::now() + boost::chrono::milliseconds(spinlockMs);

		while (!DoTask(lk) && !exitThread) {
			if (spinlockStart < boost::chrono::high_resolution_clock::now()) {
			#ifndef BOOST_THREAD_USES_CHRONO
				const boost::system_time timeout = boost::get_system_time() + boost::posix_time::microseconds(1);
				newTasks.timed_wait(lk2, timeout);
			#else
				newTasks.wait_for(lk2, boost::chrono::nanoseconds(100));
			#endif
			}
		}
	}
}
Exemplo n.º 6
0
	void DelayedTask::Update(float dt)
	{
		mRemainingToCallTime -= dt;
		if (mRemainingToCallTime < 0)
			DoTask();
	}
/* void onStartLookup (in wstring searchString, in nsIAutoCompleteResults previousSearchResult, in nsIAutoCompleteListener listener); */
NS_IMETHODIMP
nsLDAPAutoCompleteSession::OnStartLookup(const PRUnichar *searchString,
        nsIAutoCompleteResults *previousSearchResult,
        nsIAutoCompleteListener *listener)
{
    NS_ENSURE_ARG_POINTER(listener);
    if (!mFormatter)
    {
        NS_WARNING("mFormatter should not be null for nsLDAPAutoCompleteSession::OnStartLookup");
        return NS_ERROR_NOT_INITIALIZED;
    }

    nsresult rv; // Hold return values from XPCOM calls

#ifdef PR_LOGGING
    // Initialize logging, if it hasn't been already.
    if (!sLDAPAutoCompleteLogModule) {
        sLDAPAutoCompleteLogModule = PR_NewLogModule("ldapautocomplete");

        NS_ABORT_IF_FALSE(sLDAPAutoCompleteLogModule,
                          "failed to initialize ldapautocomplete log module");
    }
#endif

    PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
           ("nsLDAPAutoCompleteSession::OnStartLookup entered\n"));

    mListener = listener;

    // Ignore the empty string, strings with @ in them, and strings
    // that are too short.
    if (searchString[0] == 0 ||
            nsDependentString(searchString).FindChar(PRUnichar('@'), 0) != -1 ||
            nsDependentString(searchString).FindChar(PRUnichar(','), 0) != -1 ||
            ( !IS_CJK_CHAR_FOR_LDAP(searchString[0]) ?
              mMinStringLength && NS_strlen(searchString) < mMinStringLength :
              mCjkMinStringLength && NS_strlen(searchString) <
              mCjkMinStringLength ) ) {

        FinishAutoCompleteLookup(nsIAutoCompleteStatus::ignored, 0, mState);
        return NS_OK;
    } else {
        mSearchString = searchString;        // save it for later use
    }

    // Make sure this was called appropriately.
    if (mState == SEARCHING || mState == BINDING) {
        NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): called while "
                 "search already in progress; no lookup started.");
        FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
                                 NS_ERROR_FAILURE, mState);
        return NS_ERROR_FAILURE;
    }

    // See if this is a narrow search that we could potentially do locally.
    if (previousSearchResult) {

        // Get the string representing previous search results.
        nsString prevSearchStr;

        rv = previousSearchResult->GetSearchString(
                 getter_Copies(prevSearchStr));
        if ( NS_FAILED(rv) ) {
            NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): couldn't "
                     "get search string from previousSearchResult");
            FinishAutoCompleteLookup(nsIAutoCompleteStatus::failureItems,
                                     NS_ERROR_FAILURE, mState);
            return NS_ERROR_FAILURE;
        }

        // Does the string actually contain anything?
        if ( prevSearchStr.get() && prevSearchStr.get()[0]) {

            PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
                   ("nsLDAPAutoCompleteSession::OnStartLookup(): starting "
                    "narrowing search\n"));

            // XXXdmose for performance, we should really do a local,
            // synchronous search against the existing dataset instead of
            // just kicking off a new LDAP search here.  When implementing
            // this, need to be sure that only previous results which did not
            // hit the size limit and were successfully completed are used.
            //
            mState = SEARCHING;
            return DoTask();
        }
    }

    // Init connection if necessary
    //
    switch (mState) {
    case UNBOUND:

        // Initialize the connection.
        //
        rv = InitConnection();
        if (NS_FAILED(rv)) {

            // InitConnection() will have already called
            // FinishAutoCompleteLookup for us as necessary
            //
            return rv;
        }

        return NS_OK;

    case BOUND:

        PR_LOG(sLDAPAutoCompleteLogModule, PR_LOG_DEBUG,
               ("nsLDAPAutoComplete::OnStartLookup(): subsequent search "
                "starting"));

        // Kick off an LDAP search
        mState = SEARCHING;
        return DoTask();

    case INITIALIZING:
        // We don't need to do anything here (for now at least), because
        // we can't really abandon the initialization. If we allowed the
        // initialization to be aborted, we could potentially lock the
        // UI thread again, since the DNS service might be stalled.
        //
        return NS_OK;

    case BINDING:
    case SEARCHING:
        // We should never get here
        NS_ERROR("nsLDAPAutoCompleteSession::OnStartLookup(): unexpected "
                 "value of mStatus");
        return NS_ERROR_UNEXPECTED;
    }

    return NS_ERROR_UNEXPECTED;     /*NOTREACHED*/
}