예제 #1
0
void PublicHubsFrame::on(Corrupted, const string& l) noexcept {
	if (l.empty()) {
		callAsync([=] { onFinished(TSTRING(HUBLIST_CACHE_CORRUPTED)); });
	} else {	
		callAsync([=] { onFinished(TSTRING(HUBLIST_DOWNLOAD_CORRUPTED) + _T(" (") + Text::toT(l) + _T(")")); });
	}
}
예제 #2
0
void UserConnection::pm(const string& message, bool thirdPerson) {

	AdcCommand c(AdcCommand::CMD_MSG);
	c.addParam(message);
	if (thirdPerson)
		c.addParam("ME", "1");
	send(c);

	// simulate an echo message.
	callAsync([=]{ handlePM(c, true); });
}
예제 #3
0
void ListFilter::addColumnBox(HWND parent, vector<ColumnInfo*>& aColumns, int initialSel /*-1*/, HWND async /*NULL*/) {
    RECT rc = { 0, 0, 100, 110 };
    column.Create(parent, rc, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL |
                  WS_VSCROLL | CBS_DROPDOWNLIST, WS_EX_CLIENTEDGE);
    column.SetFont(WinUtil::systemFont);
    columns = aColumns;
    for(auto& col : columns)
        column.AddString(((*col).name).c_str());

    column.AddString(CTSTRING(ANY));
    column.SetCurSel(initialSel != -1 ? initialSel : colCount);
    callAsync(async ? async : parent, [this] { columnChanged(false); });
}
예제 #4
0
/*! \param func Function call to execute in the worker thread

call() executes a CUDA call to in a worker thread. Any function
with any arguments can be passed in to be queued using boost::bind.
Examples:
\code
gpu.call(bind(function, arg1, arg2, arg3, ...));
gpu.call(bind(cudaMemcpy, &h_float, d_float, sizeof(float), cudaMemcpyDeviceToHost));
gpu.call(bind(cudaThreadSynchronize));
\endcode
The only requirement is that the function returns a cudaError_t. Since every
single CUDA Runtime API function does so, you can call any Runtime API function.
You can call any custom functions too, as long as you return a cudaError_t representing
the error of any CUDA functions called within. This is typical in kernel
driver functions. For example, a .cu file might contain:
\code
__global__ void kernel() { ... }
cudaError_t kernel_driver()
{
kernel<<<blocks, threads>>>();
#ifdef NDEBUG
return cudaSuccess;
#else
cudaThreadSynchronize();
return cudaGetLastError();
#endif
}
\endcode
It is recommended to just return cudaSuccess in release builds to keep the asynchronous
call stream going with no cudaThreadSynchronize() overheads.

call() ensures that \a func has been executed before it returns. This is
desired behavior, most of the time. For calling kernels or other asynchronous
CUDA functions, use callAsync(), but read the warnings in it's documentation
carefully and understand what you are doing. Why have callAsync() at all?
The original purpose for designing ThreadWorker is to allow execution on 
multiple GPUs simultaneously which can only be done with asynchronous calls.

An exception will be thrown if the CUDA call returns anything other than
cudaSuccess.
*/
  void ThreadWorker::call(const boost::function< ThreadWorker::error_t (void) > &func, int device)
{
  // this mutex lock is to prevent multiple threads from making
  // simultaneous calls. Thus, they can depend on the exception
  // thrown to exactly be the error from their call and not some
  // race condition from another thread
  // making ThreadWorker calls to a single ThreadWorker from multiple threads 
  // still isn't supported
  boost::mutex::scoped_lock lock(m_call_mutex);


  // call and then sync
  callAsync(func,device);
  sync(device);
}
예제 #5
0
void ProtocolPage::on(SettingChanged) noexcept {
    callAsync([this] {
        cAutoDetect.SetCheck((v6 ? SETTING(AUTO_DETECT_CONNECTION6) : SETTING(AUTO_DETECT_CONNECTION)) ? TRUE : FALSE);

        fixControls();

        // reload settings in case they have been changed (eg by the "Edit detected settings" feature).

        /*active->setChecked(false);
        upnp->setChecked(false);
        passive->setChecked(false);

        mapper->clear();*/

        //read();
    });
}
예제 #6
0
/*! Call sync() to synchronize the master thread with the worker thread.
After a call to sync() returns, it is guarunteed that all previous
queued calls (via callAsync()) have been called in the worker thread. 
For the CUDA enabled version of the library this will also call
cudaThreadSynchronize()

sync() will throw an exception if any of the queued calls resulted in
a return value not equal to cudaSuccess.
*/
  void ThreadWorker::sync(int device)
{

#ifdef HAVE_CUDA
  if(device != -1)
     callAsync(boost::bind(cudaDeviceSynchronize),device);
#endif
  // If we support intel offload need to wait on all streams
  if(device != -1){
    #pragma offload_wait stream(0)
  }


  // wait on the work done signal
  // wait on the work done signal
  boost::mutex::scoped_lock lock(m_mutex);
  while (m_work_to_do)
    m_cond_work_done.wait(lock);


  // if there was an error
  if (m_last_error & all_error)
  {
    if(m_last_error & cuda_error)
    {
#ifdef HAVE_CUDA
    // build the exception
    //cerr << endl << "***Error! " << string(cudaGetErrorString(m_last_error)) << " after " << m_tagged_file << ":" << m_tagged_line << endl << endl;
      cerr << endl << "***Error! " << " after " << m_tagged_file << ":" << m_tagged_line << endl << endl;
    //runtime_error error("CUDA Error");
#endif
    }
    else
    {
    // build the exception
    cerr << endl << "***Error! " << " after " << m_tagged_file << ":" << m_tagged_line << endl << endl;
    }
    runtime_error error("Error");

    // reset the error value so that it doesn't propagate to continued calls
    m_last_error = all_success;

    // throw
    throw(error);
  }	
}
예제 #7
0
void TrackCollection::callSync(func lambda, QString where) {
    QMutex mutex;
    //SleepableQThread::sleep(5);
    mutex.lock();
    callAsync( [&mutex, &lambda] (void) {
        lambda();
        //SleepableQThread::sleep(5);
        mutex.unlock();
    }, where);

    while (!mutex.tryLock(5)) {
        MainExecuter::getInstance().call();
        // DBG() << "Start animation";
        // animationIsShowed = true;
    }
    mutex.unlock(); // QMutexes should be always destroyed in unlocked state.
}
RemoteRcUnitServer::RemoteRcUnitServer(RcUnits* rcUnits, QIODevice *device, bool doInitialize)
    : RemoteRcUnitServerBase(device, device, false)
{
    mRcUnits = rcUnits;
    connect(this, SIGNAL(listUnits()), this, SLOT(onListUnits()));
    connect(this, SIGNAL(callMethod(uint,QByteArray,QByteArray,QVariantList)), rcUnits, SLOT(callAsync(uint,QByteArray,QByteArray,QVariantList)));
    connect(rcUnits, SIGNAL(asyncError(uint,QString)), SLOT(methodError(uint,QString)));
    connect(rcUnits, SIGNAL(asyncResponse(uint,QVariant)), SLOT(methodResponse(uint,QVariant)));
    connect(this, SIGNAL(enableTelecontrol(uint,QString)), SLOT(onEnableTelecontrol(uint,QString)));
    connect(this, SIGNAL(disableTelecontrol(uint,QString)), SLOT(onDisableTelecontrol(uint,QString)));
    connect(this, SIGNAL(handleTcData(uint,QMap<int,double>)), SLOT(onHandleTcData(uint,QMap<int,double>)));
    connect(this, SIGNAL(setTcButton(uint,int,bool)), SLOT(onSetTcButton(uint,int,bool)));
    connect(this, SIGNAL(updateTcSensitivity(uint,QString,QString,double,QList<bool>)), SLOT(onUpdateTcSensitivity(uint,QString,QString,double,QList<bool>)));
    if(doInitialize)
        initialize();
}
예제 #9
0
int DirectoryMonitor::Server::read() {
	DWORD		dwBytesXFered = 0;
	ULONG_PTR	ulKey = 0;
	OVERLAPPED*	pOl;

	auto ret = GetQueuedCompletionStatus(m_hIOCP, &dwBytesXFered, &ulKey, &pOl, INFINITE);
	auto dwError = GetLastError();
	if (!ret) {
		if (!m_hIOCP) {
			// shutting down
			return 0;
		}

		if (dwError == WAIT_TIMEOUT) {
			//harmless
			return 1;
		}
	}

	{
		WLock l(cs);
		auto mon = find_if(monitors | map_values, [ulKey](const Monitor* m) { return (ULONG_PTR)m->key == ulKey; });
		if (mon.base() != monitors.end()) {
			if (!(*mon)->m_hDirectory) {
				//this is going to be deleted
				deleteDirectory(mon.base());
				return 1;
			}

			try {
				if ((dwError != 0 && dwError != ERROR_INVALID_PARAMETER) || !ret) {
					// Too many changes to track, http://blogs.msdn.com/b/oldnewthing/archive/2011/08/12/10195186.aspx
					// The documentation only states the code ERROR_NOTIFY_ENUM_DIR for this, but according to the testing ERROR_NOT_ENOUGH_QUOTA and ERROR_ALREADY_EXISTS seem to be used instead....
					// (and ERROR_TOO_MANY_CMDS with network drives)
					if (dwError == ERROR_NOTIFY_ENUM_DIR || dwError == ERROR_NOT_ENOUGH_QUOTA || dwError == ERROR_ALREADY_EXISTS || dwError == ERROR_TOO_MANY_CMDS) {
						(*mon)->beginRead();
						auto monBase = (*mon)->server->base;
						monBase->callAsync([=] { monBase->fire(DirectoryMonitorListener::Overflow(), (*mon)->path); });
					} else {
						throw MonitorException(getErrorStr(dwError));
					}
				} else {
					if ((*mon)->errorCount > 0) {
						(*mon)->errorCount = 0;
					}

					if (dwBytesXFered > 0) {
						(*mon)->changes++;
						(*mon)->queueNotificationTask(dwBytesXFered);
					} /*else {
						LogManager::getInstance()->message("An empty notification was received when monitoring " + Text::fromT((*mon)->path) + " (report this)", LogMessage::SEV_WARNING);
					}*/

					(*mon)->beginRead();
				}
			} catch (const MonitorException& e) {
				(*mon)->errorCount++;
				if ((*mon)->errorCount < 60) {
					//we'll most likely get the error instantly again...
					Thread::sleep(1000);

					try {
						(*mon)->openDirectory(m_hIOCP);
						(*mon)->beginRead();
						return 1;
					} catch (const MonitorException& /*e*/) {
						//go to removal
					}
				}

				failDirectory((*mon)->path, e.getError());
			}
		}
	}

	return 1;
}
예제 #10
0
void Client::info() {
	callAsync([this] { infoImpl(); });
}
예제 #11
0
IClient::Result ClientWS::call(ConstStrA method, JSON::ConstValue params, JSON::ConstValue context) {
	return callAsync(method,params,context).getValue();
}
예제 #12
0
void AutoSearchFrame::on(AutoSearchManagerListener::UpdateItem, const AutoSearchPtr& as, bool aSetDirty) noexcept {
	callAsync([=] { updateItem(as); if (aSetDirty && SETTING(AUTOSEARCH_BOLD)) setDirty();  }); 
}
예제 #13
0
void SplashWindow::operator()(float progress) {
	if (this->progress == 0.00 || progress - this->progress >= 0.01) {
		this->progress = progress;
		callAsync([this] { draw(); });
	}
}
예제 #14
0
void AutoSearchFrame::on(AutoSearchManagerListener::SearchForeground, const AutoSearchPtr& as, const string& searchString) noexcept {
	callAsync([=] { SearchFrame::openWindow(Text::toT(searchString), 0, Search::SIZE_DONTCARE, as->getFileType()); });
}
예제 #15
0
void PublicHubsFrame::on(LoadedFromCache, const string& l, const string& d) noexcept { 
	callAsync([=] { onFinished(TSTRING(HUB_LIST_LOADED_FROM_CACHE) + _T(" (") + Text::toT(l) + _T(")") + _T(" Download Date: ") + Text::toT(d)); });
}
예제 #16
0
void PublicHubsFrame::on(DownloadFinished, const string& l, bool /*fromCoral*/) noexcept { 
	callAsync([=] { onFinished(TSTRING(HUB_LIST_DOWNLOADED) + _T(" (") + Text::toT(l) + _T(")")); });
}
예제 #17
0
void PublicHubsFrame::on(DownloadFailed, const string& l) noexcept { 
	callAsync([=] { setStatusText(TSTRING(DOWNLOAD_FAILED) + _T(" ") + Text::toT(l)); });
}
예제 #18
0
void PublicHubsFrame::on(DownloadStarting, const string& l) noexcept { 
	callAsync([=] { setStatusText(TSTRING(DOWNLOADING_HUB_LIST) + _T(" (") + Text::toT(l) + _T(")")); });
}
예제 #19
0
void WebServerPage::on(webserver::WebServerManagerListener::Started) noexcept {
	callAsync([=] {
		updateState(STATE_STARTED);
	});
}
예제 #20
0
void AutoSearchFrame::on(AutoSearchManagerListener::AddItem, const AutoSearchPtr& as) noexcept { 
	callAsync([=] { addItem(as); if(SETTING(AUTOSEARCH_BOLD)) setDirty();  });
}
예제 #21
0
void WebServerPage::on(webserver::WebServerManagerListener::Stopping) noexcept {
	callAsync([=] {
		updateState(STATE_STOPPING);
	});
}
예제 #22
0
LRESULT AutoSearchFrame::onCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) {
	
	CreateSimpleStatusBar(ATL_IDS_IDLEMESSAGE, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | SBARS_SIZEGRIP);
	ctrlStatus.Attach(m_hWndStatusBar);

	ctrlAutoSearch.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | 
		WS_HSCROLL | WS_VSCROLL | LVS_REPORT | LVS_SHOWSELALWAYS | LVS_SHAREIMAGELISTS, WS_EX_CLIENTEDGE, IDC_AUTOSEARCH);
	ctrlAutoSearch.SetExtendedListViewStyle(LVS_EX_LABELTIP | LVS_EX_FULLROWSELECT | LVS_EX_CHECKBOXES | LVS_EX_HEADERDRAGDROP | LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP);	
	ctrlAutoSearch.SetBkColor(WinUtil::bgColor);
	ctrlAutoSearch.SetTextBkColor(WinUtil::bgColor);
	ctrlAutoSearch.SetTextColor(WinUtil::textColor);

	// Insert columns
	WinUtil::splitTokens(columnIndexes, SETTING(AUTOSEARCHFRAME_ORDER), COLUMN_LAST);
	WinUtil::splitTokens(columnSizes, SETTING(AUTOSEARCHFRAME_WIDTHS), COLUMN_LAST);
	
	for(int j=0; j<COLUMN_LAST; j++) {
		int fmt = LVCFMT_LEFT;
		ctrlAutoSearch.InsertColumn(j, CTSTRING_I(columnNames[j]), fmt, columnSizes[j], j);
	}
	
	ctrlAutoSearch.SetColumnOrderArray(COLUMN_LAST, columnIndexes);
	ctrlAutoSearch.SetImageList(ResourceLoader::getAutoSearchStatuses(), LVSIL_SMALL);
	ctrlAutoSearch.setVisible(SETTING(AUTOSEARCHFRAME_VISIBLE));
	ctrlAutoSearch.setSortColumn(COLUMN_VALUE);

		//create buttons
	ctrlAdd.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
		BS_PUSHBUTTON , 0, IDC_ADD);
	ctrlAdd.SetWindowText(CTSTRING(ADD));
	ctrlAdd.SetFont(WinUtil::systemFont);

	ctrlRemove.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
		BS_PUSHBUTTON , 0, IDC_REMOVE);
	ctrlRemove.SetWindowText(CTSTRING(REMOVE));
	ctrlRemove.SetFont(WinUtil::systemFont);

	ctrlChange.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
		BS_PUSHBUTTON , 0, IDC_CHANGE);
	ctrlChange.SetWindowText(CTSTRING(SETTINGS_CHANGE));
	ctrlChange.SetFont(WinUtil::systemFont);

	ctrlDuplicate.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_DISABLED | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
		BS_PUSHBUTTON , 0, IDC_DUPLICATE);
	ctrlDuplicate.SetWindowText(CTSTRING(DUPLICATE));
	ctrlDuplicate.SetFont(WinUtil::systemFont);

	ctrlManageGroups.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
		BS_PUSHBUTTON, 0, IDC_MANAGE_GROUPS);
	ctrlManageGroups.SetWindowText(CTSTRING(MANAGE_GROUPS));
	ctrlManageGroups.SetFont(WinUtil::systemFont);

	AutoSearchManager::getInstance()->addListener(this);
	SettingsManager::getInstance()->addListener(this);

	{
		//Create itemInfos
		RLock l(AutoSearchManager::getInstance()->getCS());
		auto& lst = AutoSearchManager::getInstance()->getSearchItems();
		for (auto as : lst | map_values) {
			itemInfos.emplace(as->getToken(), ItemInfo(as, false));
		}
	}
	//fill the list
	callAsync([=] { updateList(); });

	WinUtil::SetIcon(m_hWnd, IDI_AUTOSEARCH);
	::SetTimer(m_hWnd, 0, 1000, 0);

	memzero(statusSizes, sizeof(statusSizes));
	statusSizes[0] = 16;
	ctrlStatus.SetParts(5, statusSizes);

	loading = false;
	bHandled = FALSE;
	return TRUE;

}
예제 #23
0
void SplashWindow::operator()(const string& status) {
	this->status = Text::toT(status);
	progress = 0;
	callAsync([this] { draw(); });
}