2011-07-29 00:18:10 +02:00
|
|
|
/*
|
|
|
|
* This file is a part of Winix
|
|
|
|
* and is not publicly distributed
|
|
|
|
*
|
2014-02-12 17:30:49 +01:00
|
|
|
* Copyright (c) 2011-2014, Tomasz Sowa
|
2011-07-29 00:18:10 +02:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef headerfile_winix_core_threadmanager
|
|
|
|
#define headerfile_winix_core_threadmanager
|
|
|
|
|
2012-05-19 19:04:33 +02:00
|
|
|
#include <string>
|
2011-07-29 00:18:10 +02:00
|
|
|
#include <vector>
|
|
|
|
#include "basethread.h"
|
|
|
|
#include "synchro.h"
|
|
|
|
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
namespace Winix
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
|
|
|
|
class ThreadManager
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ThreadManager();
|
|
|
|
|
|
|
|
// synchro object
|
|
|
|
void SetSynchro(Synchro * psynchro);
|
|
|
|
|
|
|
|
// initializing
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
// adding a new thread to the queue
|
|
|
|
// the thread will be running only if we call StartAll() before
|
|
|
|
// otherwise the thread will be waiting for StartAll()
|
2012-05-19 19:04:33 +02:00
|
|
|
void Add(BaseThread * pbase, const wchar_t * thread_name);
|
|
|
|
void Add(BaseThread & pbase, const wchar_t * thread_name);
|
|
|
|
void Add(BaseThread * pbase, const std::wstring & thread_name);
|
|
|
|
void Add(BaseThread & pbase, const std::wstring & thread_name);
|
2011-07-29 00:18:10 +02:00
|
|
|
|
|
|
|
// starting all threads
|
|
|
|
void StartAll();
|
|
|
|
|
|
|
|
// sending a stop signal to all threads
|
|
|
|
// and waiting until they finish
|
|
|
|
void StopAll();
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-05-19 19:04:33 +02:00
|
|
|
struct ThreadItem
|
|
|
|
{
|
|
|
|
BaseThread * object;
|
|
|
|
std::wstring name;
|
|
|
|
};
|
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
Synchro * synchro;
|
2012-05-19 19:04:33 +02:00
|
|
|
typedef std::vector<ThreadItem> ThreadTab;
|
2011-07-29 00:18:10 +02:00
|
|
|
ThreadTab thread_tab;
|
|
|
|
bool were_started;
|
|
|
|
|
|
|
|
void Start(size_t i);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-02-12 17:30:49 +01:00
|
|
|
|
|
|
|
} // namespace Winix
|
|
|
|
|
|
|
|
|
2011-07-29 00:18:10 +02:00
|
|
|
#endif
|
|
|
|
|