Exemple #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;
}
Exemple #2
0
  TaskSchedulerTBB::~TaskSchedulerTBB() 
  {
    /* let all threads leave the thread loop */
    terminateThreadLoop();

    /* destroy all threads that we created */
    destroyThreads();
  }
Exemple #3
0
ICQMain::~ICQMain()
{
	destroyThreads();

	for (int i = 0; i < MAX_NUM_MODULES; i++) {
		if (modules[i])
			removeModule(i);
	}

	delete c2s;
	delete sessionHash;
	delete logger;
}
Exemple #4
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;
}
Exemple #5
0
/*! @brief Destructor for the nubot
 */
NUbot::~NUbot()
{
    #if DEBUG_NUBOT_VERBOSITY > 0
        debug << "NUbot::~NUbot()." << endl;
    #endif
    
    #ifdef USE_MOTION
        m_motion->kill();
        m_platform->kill();
        m_platform->msleep(1500);
    #endif
    
    destroyThreads();
    destroyModules();
    destroyNetwork();
    destroyBlackboard();
    destroyPlatform();
    
    #if DEBUG_NUBOT_VERBOSITY > 0
        debug << "NUbot::~NUbot(). Finished!" << endl;
    #endif
}
int main(int argc ,char *argv[])
{
    int freeIndex= 0;
    int n = 3,opt;
    /*
    while((opt = getopt(argc,argv,"n") != -1))
    {
	switch(opt)
	{
	    case 'n':
		n = atoi(optarg);
		break;
	    default:
		printf("error opt");
		exit(-1);
	}
    }
    */

    if(signal(SIGINT,sig_int) == SIG_ERR)
    {
	perror("signal error");
	exit(-2);
    }
    setbuf(stdout,NULL);
    //setbuf(stdin,NULL);
    createThreads(n);
    while(!g_isExit)
    {
	read(STDIN_FILENO,g_buf,MAX_SIZE);
	pthread_mutex_lock(&g_pthreads[freeIndex].mutex);
	pthread_cond_signal(&g_pthreads[freeIndex].cond);
	pthread_mutex_unlock(&g_pthreads[freeIndex].mutex);
	freeIndex = (freeIndex + 1)%n;
    }
    destroyThreads(n);
}