Пример #1
0
// Stop a module by name
bool ICQMain::stopModule(const char *name)
{
	int i = getModuleIndex(name);
	if (i < 0) {
		ICQ_LOG("module %s not found\n", name);
		return false;
	}

	Module *m = getModule(i);
	if (!m)
		return false;

	// Stop all work first
	destroyThreads();

	// Remove it from module list
	for (int e = 0; e < NUM_EVENTS; e++)
		moduleList[e].remove(m);

	// Walk through all sessions to remove it
	if (m->hasSessionEvent)
		sessionHash->walk(sessionWalker, m);

	// Remove and delete this module from system
	removeModule(i);

	// Recover previous work
	startThreads();
	return true;
}
Пример #2
0
/* Implementation */
int main (int argc, char **argv)
{
    int option = 0;
    long numberOfWorkers = DEFAULT_WORKERS;
    
    while ((option = getopt(argc, argv, "p:t:")) != -1)
    {
        switch (option)
        {
            case 'p':
                numberOfWorkers = atol(optarg);
                /*printf("Spawning %lu processes\n", numberOfWorkers);*/
                startProcesses(numberOfWorkers);
                break;
            case 't':
                numberOfWorkers = atol(optarg);
                /*printf("Spawning %lu threads\n", numberOfWorkers);*/
                startThreads(numberOfWorkers);
                break;
            case '?':
            default:
                usage(argv[0]);
        }
    }
    
    return 0;
}
Пример #3
0
void ThreadEngineBase::startBlocking()
{
    start();
    semaphore.acquire();
    startThreads();

    bool throttled = false;
#ifndef QT_NO_EXCEPTIONS
    try {
#endif
        while (threadFunction() == ThrottleThread) {
            if (threadThrottleExit()) {
                throttled = true;
                break;
            }
        }
#ifndef QT_NO_EXCEPTIONS
    } catch (QtConcurrent::Exception &e) {
        handleException(e);
    } catch (...) {
        handleException(QtConcurrent::UnhandledException());
    }
#endif

    if (throttled == false) {
        semaphore.release();
    }

    semaphore.wait();
    finish();
    exceptionStore.throwPossibleException();
}
Пример #4
0
int main(int argc, char* argv[]) {
	init();
	atexit(freeMem);
	if(argc <= 1) { // rendern zu OpenGL
		fileMode = 0;
		glutInit(&argc, argv);
		glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
		glutInitWindowSize(633, 641);
		glutCreateWindow("Mandelbrot");	
		initGL();
		glutKeyboardFunc(keyboard);
		glutMouseFunc(mouse);
		glutMotionFunc(mousemove);
		glutDisplayFunc(render);
		glutIdleFunc(repaint);
		glutReshapeFunc(reshape);
		glutMainLoop();
	} else { // rendern zur Datei
		fileMode = 1;
		sizeX = 1024;
		sizeY = 1024;
		maxIterations=500;
		//		loadPosition();
		startThreads();
		waitForThreads();
		writeTGA();
	}
	return EXIT_SUCCESS;	
}
Пример #5
0
void ThreadEngineBase::run() // implements QRunnable.
{
    if (this->isCanceled()) {
        threadExit();
        return;
    }

    startThreads();

#ifndef QT_NO_EXCEPTIONS
    try {
#endif
        while (threadFunction() == ThrottleThread) {
            // threadFunction returning ThrottleThread means it that the user
            // struct wants to be throttled by making a worker thread exit.
            // Respect that request unless this is the only worker thread left
            // running, in which case it has to keep going.
            if (threadThrottleExit())
                return;
        }

#ifndef QT_NO_EXCEPTIONS
    } catch (QtConcurrent::Exception &e) {
        handleException(e);
    } catch (...) {
        handleException(QtConcurrent::UnhandledException());
    }
#endif
    threadExit();
}
Пример #6
0
    // call after constructing to start - returns fairly quickly after launching its threads
    void ReplSetImpl::_go() {
        OperationContextImpl txn;

        try {
            loadLastOpTimeWritten(&txn);
        }
        catch (std::exception& e) {
            log() << "replSet error fatal couldn't query the local " << rsoplog
                  << " collection.  Terminating mongod after 30 seconds." << rsLog;
            log() << e.what() << rsLog;
            sleepsecs(30);
            dbexit(EXIT_REPLICATION_ERROR);
            return;
        }

        // initialize _me in SyncSourceFeedback
        bool meEnsured = false;
        while (!inShutdown() && !meEnsured) {
            try {
                syncSourceFeedback.ensureMe(&txn);
                meEnsured = true;
            }
            catch (const DBException& e) {
                warning() << "failed to write to local.me: " << e.what()
                          << " trying again in one second";
                sleepsecs(1);
            }
        }

        changeState(MemberState::RS_STARTUP2);
        startThreads();
        newReplUp(); // oplog.cpp
    }
void C_BCI_Package::Run()
{
    //Initialize the System
    bciState = BCI_INITIALIZATION;

    //Keep Track of the Mission Time
    stopwatch.start();

    //Make Connections to peripherals
    createConnections();

    //Configure Repetitive Visual Stimulus and send to Flasher
    pRVS->Generate();
    pFlasherIO->SendRVS();

    //Record our TM to an output file
    pTelemetryManager->RecordTMToFile(TM_DATA_OUTPUTFILE_BIN);
    pEEG_IO->RecordTMToFile(EEG_DATA_OUTPUTFILE_BIN);

    //Begin Thread Execution for EEG and BRS IO
    startThreads();

    debugLog->println(BCI_LOG, "Initialization Complete, Moving to STANDBY..." , true );

    //Move to Standby
    bciState = BCI_STANDBY;
    //This is all we need to do here, the Signals and Slots will
    //take care of notifying us for remote commands and Emergency Stops
    return;
}
SoundPool::SoundPool(int maxChannels, audio_stream_type_t streamType, int srcQuality)
{
    ALOGV("SoundPool constructor: maxChannels=%d, streamType=%d, srcQuality=%d",
            maxChannels, streamType, srcQuality);

    // check limits
    mMaxChannels = maxChannels;
    if (mMaxChannels < 1) {
        mMaxChannels = 1;
    }
    else if (mMaxChannels > 32) {
        mMaxChannels = 32;
    }
    ALOGW_IF(maxChannels != mMaxChannels, "App requested %d channels", maxChannels);

    mQuit = false;
    mDecodeThread = 0;
    mStreamType = streamType;
    mSrcQuality = srcQuality;
    mAllocated = 0;
    mNextSampleID = 0;
    mNextChannelID = 0;

    mCallback = 0;
    mUserData = 0;

    mChannelPool = new SoundChannel[mMaxChannels];
    for (int i = 0; i < mMaxChannels; ++i) {
        mChannelPool[i].init(this);
        mChannels.push_back(&mChannelPool[i]);
    }

    // start decode thread
    startThreads();
}
Пример #9
0
int main(int argc, char *argv[]) {
	int i,j,k;
	if (argc<2) {
		fprintf(stderr, "Usage: dijkstra <filename>\n");
		fprintf(stderr, "Only supports matrix size is #define'd.\n");
	}
	//Open the adjacency matrix file
	FILE *fp;
	fp = fopen (argv[1],"r");
	/*Step 1: geting the working vertexs and assigning values*/
  	for (i=0;i<NUM_NODES;i++) {
    		for (j=0;j<NUM_NODES;j++) {
     			fscanf(fp,"%d",&k);
			AdjMatrix[i][j]= k;
    		}
  	}
	fclose(fp);
	chStart=0,chEnd=1999; //15 for small input; 1999 for large input
	if (chStart == chEnd) {
		printf("Shortest path is 0 in cost. Just stay where you are.\n");
		
	}else{
		startBarrier(&myBarrier);	/* Start barrier 	*/
		startThreads();			/* Start pthreads */	
	}
	printResult();
//}
	exit(0);
}
Пример #10
0
void Socket::connect() {
    if (connected) {
        std::cerr << "Socket already connected" << std::endl;
        return;
    }

    struct sockaddr_in sockaddr;
    //std::cout << "Read message\n";
    sockfd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);

    memset(&sockaddr, 0, sizeof(sockaddr));
    sockaddr.sin_family = AF_INET;
    inet_pton(AF_INET, hostname, &sockaddr.sin_addr);
    sockaddr.sin_port = htons(port);

    if (::connect(sockfd, (struct sockaddr *) &sockaddr, sizeof(sockaddr))) {
        //TODO: error handling
        std::cerr << "Socket connect sad! :(" << std::endl;
        return;
    }

    connected = true;

    startThreads();
}
Пример #11
0
void
Application::start()
{
	startThreads();
	loadCommands();
	decryptLuts();
}
Пример #12
0
RawImage AriDecoder::decodeRawInternal() {
  mRaw->dim = iPoint2D(mWidth, mHeight);
  mRaw->createData();

  startThreads();

  mRaw->whitePoint = 4095;
  return mRaw;
}
Пример #13
0
BitmapManager::BitmapManager()
{
    if (s_pBitmapManager) {
        throw Exception(AVG_ERR_UNKNOWN, "BitmapMananger has already been instantiated.");
    }
    
    m_pCmdQueue = BitmapManagerThread::CQueuePtr(new BitmapManagerThread::CQueue);
    m_pMsgQueue = BitmapManagerMsgQueuePtr(new BitmapManagerMsgQueue(8));

    startThreads(1);

    s_pBitmapManager = this;
}
Пример #14
0
int main(int argc, char *argv[]){
	clock_t start, stop;
	double ct, cmin = DBL_MAX, cmax = 0;
	int i, j;
	int iterations;
	long n;
	if (argc<2) {
    		fprintf(stderr,"Usage: bitcnts <iterations>\n");
    		exit(-1);
	}
  	iterations=atoi(argv[1]);
  	puts("Bit counter algorithm benchmark\n");
	FUNCARGS* funcArgs = (FUNCARGS*)malloc(sizeof(FUNCARGS));
	//funcArgs->randSeed = rand();
	funcArgs->randSeed = 112500;
	funcArgs->iterations = iterations;
	startBarrier(&myBarrier);
    	startThreads(4,funcArgs);
	free(funcArgs);
	/*
	FUNCARGS* funcArgs = (FUNCARGS*)malloc(sizeof(FUNCARGS));
  	for (i = n = 0; i < FUNCS; i++) {
    		start = clock();
		funcArgs->funcI = i;
		//funcArgs->randSeed = rand();
		funcArgs->randSeed = 112500;
		funcArgs->iterations = iterations;
		startBarrier(&myBarrier);
    		startThreads(3,funcArgs);
		for(j=n=0;j<PROCESSORS;j++){
			n+=ns[j];
			ns[j] = 0;
		}
    		stop = clock();
    		ct = (stop - start) / (double)CLOCKS_PER_SEC;
    		if (ct < cmin) {
	 		cmin = ct;
	 		cminix = i;
    		}
    		if (ct > cmax) {
	 		cmax = ct;
	 		cmaxix = i;
    		}   
    		printf("%-38s> Time: %7.3f sec.; Bits: %ld\n", text[i], ct, n);
  	}
	free(funcArgs);
	*/
	printf("\nBest  > %s\n", text[cminix]);
  	printf("Worst > %s\n", text[cmaxix]);
  	return 0;
}
Пример #15
0
int main() {
  START();


  auto pApp = make_shared<SnakeApp>();
  pApp->setup();
  pApp->sound("./sound/eat.wav");
  pApp->startThreads();

  //try {
  //} catch (...) {
  //  ERR << "main exception" << LEND;
  //}
  END("");

}
Пример #16
0
void MainWindow::createMenus()
{
  QMenu   *menu;
  QAction *action;

  menu = menuBar()->addMenu(_("&File"));

  //menu->addAction(_("Update"), this, SLOT(updateAll()));
  m_action_start = menu->addAction(_("&Start"));
  connect(m_action_start, SIGNAL(triggered()),
          this,           SLOT(startThreads()));
  m_action_stop = menu->addAction(_("Stop"));
  menu->addSeparator();
  menu->addAction(standardAction(Exit));

  addHelpMenu();
}
Пример #17
0
int main()
{
	//testDB();
	//testShout();

	//db_printf(3,"Testing tagging library on current dir:\n");
	//testFlac();

	//Test remote streaming:
	//const char *shoutStream = "http://scfire-dtc-aa02.stream.aol.com:80/stream/1013";
	//musicFile f(shoutStream);

	startThreads();

	printf("Exit\n");
    return 0;
}
Пример #18
0
/**
 * Overloaded Constructor
 */
FBF::FBF(unsigned long number, unsigned long long int tableSize, unsigned int numOfHashes, unsigned long refreshTime, double appProvidedFPR, bool enableDynamicResizing) {
	trace.funcEntry("FBF::FBF");
	parameters.projected_element_count = PROJECTED_ELEMENT_COUNT;
	parameters.false_positive_probability = FALSE_POSITIVE_PROBABILITY;
	parameters.random_seed = RANDOM_SEED;
	if ( !parameters ) {
		cout<<"  ERROR :: Invalid parameters"<<endl;
	}
	parameters.compute_optimal_parameters(tableSize, numOfHashes);
	fbf.clear();
	for ( int counter = 0; counter < number; counter++ ) {
		fbf.emplace_back(bloom_filter(parameters));
		fbf[counter].clear();
	}
	cout<<"  INFO :: "<<fbf.size()<<" constituent bloom filters initialized in the FBF"<<endl;

	future = FUTURE;
	present = future + 1;
	pastStart = future + 2;
	numberOfBFs = fbf.size();
	pastEnd = numberOfBFs - 1;
	refreshRate = refreshTime;
	maxTolerableFPR = appProvidedFPR;
	this->enableDynamicResizing = enableDynamicResizing;
	stopRefreshFBFThread = false;
	stopdynamicResizingThread = false;
	thresholdFraction = UNSAFE_THRESHOLD_FRACTION;
	safeThresholdFraction = SAFE_THRESHOLD_FRACTION;
	multiplicativeBloomFilterIncrement = MULTIPLICATIVE_BLOOM_FILTER_INCREMENT;
	additiveBloomFilterIncrement = ADDITIVE_BLOOM_FILTER_INCREMENT;
	minRefreshRate = MIN_REFRESH_RATE;
	additiveRefreshRateDecrement = ADDITIVE_REFRESH_RATE_DECREMENT;
	minimumNumberOfBFs = MINIMUM_NUMBER_OF_BFS;
	additiveBloomFilterDecrement = ADDITIVE_BLOOM_FILTER_DECREMENT;
	additiveRefreshRateIncrement = ADDITIVE_REFRESH_RATE_INCREMENT;

	cout<<"  INFO :: FBFs initialized"<<endl;

	/*
	 * Start the refresh FBF and dynamic resizing threads
	 */
	startThreads();

	trace.funcExit("FBF::FBF");
}
Пример #19
0
// Start a module by name
bool ICQMain::startModule(const char *name)
{
	Module *m = getModule(name);
	if (m) {
		logger->log(LOG_WARNING, "module %s already started\n", name);
		return false;
	}

	ConfigParser file(LINQ_CONFIG_DIR"/modules.conf");
	Profile *prof = file.getProfile(name);

	// Shutdown threads first to avoid race condition
	destroyThreads();
	bool ret = startModule(prof);
	startThreads();

	return ret;
}
Пример #20
0
Option FlatUCBMod::getNextOption(int UCTPlayer, GameState gameState, std::vector<Move> moveHistory)
{
	for (int counter = 0; counter < UCBMOD_THREADITERATIONS; counter++)
		startThreads(UCTPlayer, gameState, moveHistory);

	std::vector<Node*> concatenatedValue;

	for (int i = 0; i < threadNodes.size(); i++)
	{
		bool contained = false;
		for (int n = 0; n < concatenatedValue.size(); n++)
		{
			if (concatenatedValue.at(n)->opt.type == threadNodes.at(i)->opt.type && concatenatedValue.at(n)->opt.absoluteCardId == threadNodes.at(i)->opt.absoluteCardId)
			{
				contained = true;
				concatenatedValue.at(n)->visited += threadNodes.at(i)->visited;
			}
		}

		if (!contained)
		{
			concatenatedValue.push_back(threadNodes.at(i));
		}
	}

	int mostVisits = 0;
	Option bestOption;
	for (int i = 0; i < concatenatedValue.size(); i++)
	{
		std::cout << concatenatedValue.at(i)->opt.type;
		std::cout << CardManager::cardLookup[concatenatedValue.at(i)->opt.absoluteCardId].name;
		std::cout << " visited: " << concatenatedValue.at(i)->visited << std::endl;
		if (concatenatedValue.at(i)->visited > mostVisits)
		{
			mostVisits = concatenatedValue.at(i)->visited;
			bestOption = concatenatedValue.at(i)->opt;
		}
	}

	concatenatedValue.clear();
	threadNodes.clear();
	resetNodes();
	return bestOption;
}
Пример #21
0
DefaultOperationTcpChannel::DefaultOperationTcpChannel(IKaaChannelManager& channelManager,
                                                       const KeyPair& clientKeys,
                                                       IKaaClientContext& context)
    : context_(context)
    , channelManager_(channelManager)
    , clientKeys_(clientKeys)
    , work_(io_)
    /*, sock_(io_) */
    , pingTimer_(io_)
    , connAckTimer_(io_)
    , responseProcessor(context)
{
    startThreads();

    responseProcessor.registerConnackReceiver(std::bind(&DefaultOperationTcpChannel::onConnack, this, std::placeholders::_1));
    responseProcessor.registerKaaSyncReceiver(std::bind(&DefaultOperationTcpChannel::onKaaSync, this, std::placeholders::_1));
    responseProcessor.registerPingResponseReceiver(std::bind(&DefaultOperationTcpChannel::onPingResponse, this));
    responseProcessor.registerDisconnectReceiver(std::bind(&DefaultOperationTcpChannel::onDisconnect, this, std::placeholders::_1));
}
Пример #22
0
int main0_dijkstra(int argc, char *argv[]) {
	
 
        int i,j,k;
	if (argc<2) {
		fprintf(stderr, "Usage: dijkstra <filename>\n");
		fprintf(stderr, "Only supports matrix size is #define'd.\n");
	}
	//Open the adjacency matrix file
	
	
	/*Step 1: geting the working vertexs and assigning values*/
  	for (i=0;i<NUM_NODES;i++) {
    		for (j=0;j<NUM_NODES;j++) {
     			fscanf(filein_dijkstra,"%d",&k);
			AdjMatrix[i][j]= k;
    		}
  	}

	

	int tasks = NUM_NODES*(NUM_NODES-1)/2;
	int x=0;
	for(i=0;i<15;i++){ //small:15; large:159
		for(j=i+1;j<16;j++){	//small:16; large:160
			nodes_tasks[x][0] = i;
			nodes_tasks[x][1] = j;
			x++;
		}
	}
	//pthread_attr_setdetachstate(&dijkstra_attr,0); // 0 indicates that software is dijkstra
	divide_task_group(tasks);


	

	startThreads();			/* Start pthreads */	




	return 0;
}
Пример #23
0
bool ICQMain::init(int argc, char *argv[])
{
	srand(time(&curTime));

	option.load(argc, argv);

	// Open logger
	logger->open(option.log_ip, option.log_port, option.log_level, "linqd");

	if (!initDB() || !c2s->init())
		return false;

	// Enumerate all of the modules
	ConfigParser parser(LINQ_CONFIG_DIR"/modules.conf");
	parser.start(this);

	// Start all event threads
	startThreads();

	logger->log(LOG_INFORMATION, "linqd is now started");
	return true;
}
Пример #24
0
//----------------------------------------------------------
//      Main entry point
//----------------------------------------------------------
int main(void)
{
    initSystem();

// ------------------------------------------
#ifdef USE_THREADS
    MESSAGE("Using threads");

    // never returns
    startThreads(appMain, systemMain);

    // if we're here, something went wrong
    ASSERT(!"systemMain returned?!");

// ------------------------------------------
#else

    ENABLE_INTS();

#ifdef USE_PROTOTHREADS
    startProtoSched();
#else
    MESSAGE("Not using threads");
    appMain();
#endif

    //
    // Do not allow to return from this function. The reason:
    // GCC 4.5+ disables interrupts after completion of main() function,
    // but MansOS applications may want to return from appMain()
    // and do all the "real work" in interrupt handlers.
    // Therefore, interrupts must be kept enabled.
    //
    for (;;) {}
#endif // USE_THREADS

    return 0;
}
Пример #25
0
    // call after constructing to start - returns fairly quickly after launching its threads
    void ReplSetImpl::_go() {
        OperationContextImpl txn;

        try {
            // Note: this sets lastOpTimeWritten, which the Applier uses to determine whether to
            // do an initial sync or not.
            loadLastOpTimeWritten(&txn);
        }
        catch (std::exception& e) {
            log() << "replSet error fatal couldn't query the local " << rsoplog
                  << " collection.  Terminating mongod after 30 seconds." << rsLog;
            log() << e.what() << rsLog;
            sleepsecs(30);
            dbexit(EXIT_REPLICATION_ERROR);
            return;
        }

        // initialize _me in SyncSourceFeedback
        bool meEnsured = false;
        while (!inShutdown() && !meEnsured) {
            try {
                syncSourceFeedback.ensureMe(&txn);
                meEnsured = true;
            }
            catch (const DBException& e) {
                warning() << "failed to write to local.me: " << e.what()
                          << " trying again in one second";
                sleepsecs(1);
            }
        }


        bool worked = getGlobalReplicationCoordinator()->setFollowerMode(MemberState::RS_STARTUP2);
        invariant(worked);
        startThreads();
        newReplUp(); // oplog.cpp
    }
Пример #26
0
void Rw2Decoder::DecodeRw2() {
  startThreads();
}
Пример #27
0
OldThreadPool::OldThreadPool(int nThreads, const std::string& threadNamePrefix)
    : OldThreadPool(DoNotStartThreadsTag(), nThreads, threadNamePrefix) {
    startThreads();
}
Пример #28
0
///b3Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
///Setup and initialize SPU/CELL/Libspe2
b3Win32ThreadSupport::b3Win32ThreadSupport(const Win32ThreadConstructionInfo & threadConstructionInfo)
{
	m_maxNumTasks = threadConstructionInfo.m_numThreads;
	startThreads(threadConstructionInfo);
}
Пример #29
0
void* Server::managerThreadFunction(void* argument)
{
	startThreads();
	return NULL;
}
Пример #30
0
///Win32ThreadSupport helps to initialize/shutdown libspe2, start/stop SPU tasks and communication
///Setup and initialize SPU/CELL/Libspe2
Win32ThreadSupport::Win32ThreadSupport(const Win32ThreadConstructionInfo & threadConstructionInfo)
{
	startThreads(threadConstructionInfo);
}