示例#1
0
    void Execute() {
        switch(RandomProvider.GetNextAction()) {
            case ActionType::Allocate: {
                // Allocate an object of a random size.
                int size = RandomProvider.GetNextObjectSize();
                void* object = Allocator->Allocate(size);

                if(object == 0) {
                    std::cout<<"Object could not be allocated!";
                    std::cout<<"Consider building in 64 bit mode.";
                    exit(-1);
                }

                TouchData(object, size);
                InsertObject(object);
                break;
            }
            case ActionType::Deallocate: {
                if(PassedObjects.size() > 0) {
                    EnterCriticalSection(&PassedObjectsLock);
                    void* object = *(PassedObjects.end() - 1);
                    PassedObjects.pop_back();
                    LeaveCriticalSection(&PassedObjectsLock);
                    
                    if(!VerifyData(object)) {
                        std::cout<<"Data corruption detected!\n";
                    }
                    
                    Allocator->Deallocate(object);
                    
                }
                if(Objects.size() > 0 && (deallocateObjects != Objects.size())) {
                    // Randomly select an object to be deallocated.
                    int victim = SelectVictim();

                    if(victim != -1) {
                        // Deallocate the object and insert the location
                        // in the list of unused positions to be used when allocating.
                        void* object = Objects[victim];

                        if(!VerifyData(object)) {
                            std::cout<<"Data corruption detected!\n";
                        }

                        Allocator->Deallocate(object);
                        ResetSlot(victim);
                    }
                }

                break;
            }
            case ActionType::Pass: {
                if(Threads.size() > 0 && Objects.size() > 0 &&
                   (deallocateObjects != Objects.size())) {
                    // Select an object to be passed to one of the other threads.
                    int victim = SelectVictim();

                    if(victim != -1) {
                        int otherThread = RandomProvider.GetNextInt(Threads.size());
                        ThreadData* otherThreadData = Threads[otherThread];
                    
                        void* object = Objects[victim];
                        ResetSlot(victim);

                        EnterCriticalSection(&otherThreadData->PassedObjectsLock);
                        otherThreadData->PassedObjects.push_back(object);
                        LeaveCriticalSection(&otherThreadData->PassedObjectsLock);
                    }
                }

                break;
            }
        }
    }
示例#2
0
文件: MInput.cpp 项目: Keedu/maratis
MInput::MInput(void)
{
	// ASCII keys
	char name[2] = {0, 0};
	for(int i=65; i<=90; i++)
    {
		name[0] = i;
		createKey(name);
	}
    
    // create touch data
    for(int i=0; i<10; i++)
    {
        m_touches[i] = TouchData();
    }

	// keyboard keys
	createKey("BACKSPACE");
	createKey("TAB");
	createKey("ESCAPE");
	createKey("SPACE");
	createKey("DELETE");
	createKey("0");
	createKey("1");
	createKey("2");
	createKey("3");
	createKey("4");
	createKey("5");
	createKey("6");
	createKey("7");
	createKey("8");
	createKey("9");
	createKey("ENTER");
	createKey("UP");
	createKey("DOWN");
	createKey("LEFT");
	createKey("RIGHT");
	createKey("F1");
	createKey("F2");
	createKey("F3");
	createKey("F4");
	createKey("F5");
	createKey("F6");
	createKey("F7");
	createKey("F8");
	createKey("F9");
	createKey("F10");
	createKey("F11");
	createKey("F12");
	createKey("RSHIFT");
	createKey("LSHIFT");
	createKey("RCONTROL");
	createKey("LCONTROL");
	createKey("RALT");
	createKey("LALT");

	// mouse keys
	createKey("MOUSE_BUTTON1");
	createKey("MOUSE_BUTTON2");
	createKey("MOUSE_BUTTON3");

	// joystick keys
	createKey("JOY1_BUTTON1");
	createKey("JOY1_BUTTON2");
	createKey("JOY1_BUTTON3");
	createKey("JOY1_BUTTON4");
	createKey("JOY1_BUTTON5");
	createKey("JOY1_BUTTON6");
	createKey("JOY1_BUTTON7");
	createKey("JOY1_BUTTON8");

	createKey("JOY2_BUTTON1");
	createKey("JOY2_BUTTON2");
	createKey("JOY2_BUTTON3");
	createKey("JOY2_BUTTON4");
	createKey("JOY2_BUTTON5");
	createKey("JOY2_BUTTON6");
	createKey("JOY2_BUTTON7");
	createKey("JOY2_BUTTON8");

	// axis
	createAxis("MOUSE_X");
	createAxis("MOUSE_Y");
	createAxis("MOUSE_WHEEL", 1);

	createAxis("JOY1_X");
	createAxis("JOY1_Y");
	createAxis("JOY1_Z");
	createAxis("JOY1_R");
	createAxis("JOY1_U");
	createAxis("JOY1_V");

	createAxis("JOY2_X");
	createAxis("JOY2_Y");
	createAxis("JOY2_Z");
	createAxis("JOY2_R");
	createAxis("JOY2_U");
	createAxis("JOY2_V");
}