Example #1
0
void XDbgProxy::sendThreadInfo()
{
	MyTrace("%s()", __FUNCTION__);

	DebugEventPacket event;
	memset(&event, 0, sizeof(event));
	DEBUG_EVENT& msg = event.event;
	DebugAckPacket ack;

	msg.dwDebugEventCode = CREATE_THREAD_DEBUG_EVENT;
	msg.dwProcessId = XDbgGetCurrentProcessId();
	
	DWORD threadId = getFirstThread();
	while (threadId) {

		msg.dwThreadId = threadId;
		msg.u.CreateThread.hThread = NULL;
		msg.u.CreateThread.lpStartAddress = (LPTHREAD_START_ROUTINE)
			GetThreadStartAddress(threadId);

		msg.u.CreateThread.lpThreadLocalBase = GetThreadTeb(threadId);
		sendDbgEvent(event, ack, false);
		threadId = getNextThread();
	}
}
Example #2
0
void MyThreadYield(void) {

	Thread *current = currentThread;
	
	insertIntoQueue(readyQueue, currentThread);
	currentThread = getNextThread();

	swapcontext(&(current->uctxt), &(currentThread->uctxt));
}
Example #3
0
void MyThreadJoinAll(void) {

	if(!isQueueEmpty(currentThread->children)) {
		Thread *this = currentThread;
		insertIntoQueue(blockedQueue, currentThread);
		currentThread = getNextThread();
		swapcontext(&(this->uctxt), &(currentThread->uctxt));
	}	
}	
Example #4
0
void MyThreadExit(void) {
	Thread *this = currentThread;
		
	removeParentFromBlockedQueue(this);	 
	updateParentFieldForChildren(this);
		
	currentThread = getNextThread();	
	freeThread(this);	

	setcontext(&(currentThread->uctxt));
}
Example #5
0
void MySemaphoreWait(MySemaphore semaphore) {
	Semaphore *sem = semaphore;
	
	(sem->value)--;
	
	if(sem->value < 0) {
		insertIntoQueue(sem->blockedQueue, currentThread);
		Thread *this = currentThread;
		currentThread = getNextThread();
		swapcontext(&(this->uctxt), &(currentThread->uctxt));	
	}	
}	
Example #6
0
int MyThreadJoin(void *thread) {

	Thread *child = (Thread *)thread;
	
	if(child->parent != currentThread)
		return -1;
	
	if(isPresent(currentThread->children, child)) {
		currentThread->waitingFor = child;
		insertIntoQueue(blockedQueue, currentThread);
		currentThread = getNextThread();
		swapcontext(&(child->parent->uctxt), &(currentThread->uctxt));
	}
	return 0;		
}	
Example #7
0
void Perft::run() {

    if (!load()) {
        perftRes.hash = nullptr;
        if (mbSize) {
            alloc();
        }
    }

    if (fen.empty()) {
        fen = STARTPOS;
    }
    if (!perftRes.depth) {
        perftRes.depth = 1;
    }
    if (!perftRes.nCpu) {
        perftRes.nCpu = 1;
    }
    PerftThread *p = new PerftThread();
    if (!fen.empty()) {
        p->loadFen(fen);
    }
    p->setPerft(true);
    int side = p->getSide() ? 1 : 0;
    p->display();
    cout << "fen:\t\t\t" << fen << endl;
    cout << "depth:\t\t\t" << perftRes.depth << endl;
    cout << "#cpu:\t\t\t" << perftRes.nCpu << endl;
    cout << "cache size:\t\t" << mbSize << endl;
    cout << "dump file:\t\t" << dumpFile << endl;
    cout << endl << Time::getLocalTime() << " start perft test..." << endl;

    Timer t2(minutesToDump * 60);
    if (perftRes.hash && !dumpFile.empty()) {
        signal(SIGINT, Perft::ctrlChandler);
        cout << "dump hash table in " << dumpFile << " every " << minutesToDump << " minutes" << endl;
        cout << "type 'dump' to dump now" << endl;
        t2.registerObservers([this]() {
            dump();
        });
        t2.start();
    }

    cout << endl << endl << setw(6) << "move" << setw(20) << "tot";
    cout << setw(8) << "#";
    cout << endl;

    time.resetAndStart();
    p->incListId();
    u64 friends = side ? p->getBitmap<WHITE>() : p->getBitmap<BLACK>();
    u64 enemies = side ? p->getBitmap<BLACK>() : p->getBitmap<WHITE>();
    p->generateCaptures(side, enemies, friends);
    p->generateMoves(side, friends | enemies);
    int listcount = p->getListSize();
    count = listcount;
    delete (p);
    p = nullptr;
    ASSERT(perftRes.nCpu > 0);
    int block = listcount / perftRes.nCpu;
    int i, s = 0;
    setNthread(perftRes.nCpu);
    for (i = 0; i < perftRes.nCpu - 1; i++) {
        PerftThread &perftThread = getNextThread();
        perftThread.setParam(fen, s, s + block, &perftRes);
        s += block;
    }
    PerftThread &perftThread = getNextThread();
    perftThread.setParam(fen, s, listcount, &perftRes);
    startAll();
    joinAll();
}