/**
 * @brief	Cleans up threads for a single object (this object).
 *
 * Calls ThreadSingleMessageKeepLastUser::CleanupThreads if this is the last object using the
 * threads that has not been destroyed.\n\n
 *
 * Does nothing if object never used threads.
 */
void ThreadSingleMessageKeepLastUser::CleanupThreadsLocal()
{
	usingThreads.Enter();
	try
	{
		if(usingThreads == true)
		{
			CleanupThreads(classIndex);
		
			for(size_t n = 0;n<lastMessage.Size();n++)
			{
				if(lastMessage.IsAllocated(n) == true)
				{
					bool shouldCleanup = lastMessage[n].ShouldSenderCleanup();

					if(shouldCleanup == true)
					{
						lastMessage.Deallocate(n);
					}
				}
			}
			usingThreads = false;
		}
	}
	catch(...) {usingThreads.Leave(); throw;}
	usingThreads.Leave();
}
Ejemplo n.º 2
0
static void _sig_handler(int signo)
{
	if (signo == SIGINT || signo == SIGTERM)
	{
		CleanupThreads();
		exit(signo);
	}
}
Ejemplo n.º 3
0
int main(int argc, char **argv)
{
	int nthreads = 1;
	char *cachedir = "locals.txt";
	char option_char;

	while ((option_char = getopt_long(argc, argv, "t:c:h", gLongOptions, NULL)) != -1)
	{
		switch (option_char)
		{
			case 't': // thread-count
				nthreads = atoi(optarg);
				break;
			case 'c': //cache directory
				cachedir = optarg;
				break;
			case 'h': // help
				Usage();
				exit(0);
				break;
			default:
				Usage();
				exit(1);
		}
	}

	if (signal(SIGINT, _sig_handler) == SIG_ERR)
	{
		fprintf(stderr,"Can't catch SIGINT...exiting.\n");
		exit(EXIT_FAILURE);
	}

	if (signal(SIGTERM, _sig_handler) == SIG_ERR)
	{
		fprintf(stderr,"Can't catch SIGTERM...exiting.\n");
		exit(EXIT_FAILURE);
	}

	// Initialize cache
	simplecache_init(cachedir);

    // Initializing thread constructs
	InitializeThreadConstructs();
	InitializeThreadPool(nthreads);

	// Initializing synchronization queues
	InitializeSynchronizationQueues();

    HandleIncomingRequests();

    CleanupThreads();

	return 0;
}
Ejemplo n.º 4
0
	void TLServer_IP::OnClose() 
	   {
		m_MainWndIsClosing = TRUE;
		updateControls();

		if(!CleanupThreads())
		   { /* threads running */
			TRACE(_T("%s: TLServer_IP::OnClose: deferring close\n"), AfxGetApp()->m_pszAppName);
			return;
		   } /* threads running */

		//CWnd::OnOK();
	   }