76 lines
2.0 KiB
C++
76 lines
2.0 KiB
C++
#include <common/console.hpp>
|
|
#include <common/string.hpp>
|
|
#include <common/pointer.hpp>
|
|
#include <common/pvector.hpp>
|
|
#include <common/profile.hpp>
|
|
#include <thread/mthread.hpp>
|
|
#include <thtest/foo.hpp>
|
|
|
|
void yieldTask(void);
|
|
void parseCommandLine(DWORD &itemCount,DWORD &timeToLive);
|
|
|
|
int PASCAL WinMain(HINSTANCE hInstance,HINSTANCE /*hPrevInstance*/,LPSTR /*lpszCmdLine*/,int /*nCmdShow*/)
|
|
{
|
|
PureVector<SmartPointer<Foo> > vectorFoo;
|
|
DWORD itemCount(25);
|
|
DWORD timeToLive(30000);
|
|
DWORD endTime(::GetTickCount());
|
|
Point windowPoint;
|
|
|
|
parseCommandLine(itemCount,timeToLive);
|
|
vectorFoo.size(itemCount);
|
|
|
|
for(int itemIndex=0;itemIndex<itemCount;itemIndex++)
|
|
{
|
|
vectorFoo[itemIndex]=new Foo;
|
|
vectorFoo[itemIndex].disposition(PointerDisposition::Delete);
|
|
(vectorFoo[itemIndex])->setPoint(windowPoint);
|
|
ThreadMessage userMessage(ThreadMessage::TM_USER,Foo::FooStart,0);
|
|
((MessageThread*)(vectorFoo[itemIndex]))->postMessage(userMessage);
|
|
windowPoint.x(windowPoint.x()+50);
|
|
if(windowPoint.x()>760)
|
|
{
|
|
windowPoint.x(0);
|
|
windowPoint.y(windowPoint.y()+50);
|
|
}
|
|
}
|
|
while(endTime+timeToLive>::GetTickCount())yieldTask();
|
|
#if 0
|
|
for(itemIndex=0;itemIndex<itemCount;itemIndex++)
|
|
{
|
|
ThreadMessage userMessage(ThreadMessage::TM_USER,Foo::FooStart,0);
|
|
(vectorFoo[itemIndex])->suspend();
|
|
// ::Sleep(50);
|
|
}
|
|
#endif
|
|
return FALSE;
|
|
}
|
|
|
|
void yieldTask(void)
|
|
{
|
|
MSG msg;
|
|
|
|
while(::PeekMessage((MSG far *)&msg,0,0,0,PM_REMOVE))
|
|
{
|
|
::TranslateMessage(&msg);
|
|
::DispatchMessage(&msg);
|
|
::Sleep(50);
|
|
}
|
|
}
|
|
|
|
void parseCommandLine(DWORD &itemCount,DWORD &timeToLive)
|
|
{
|
|
Profile thProfile("THREADS.INI","UNSET");
|
|
String strTimeToLive;
|
|
String strThreads;
|
|
|
|
thProfile.readProfileString(String("THREADS"),String("COUNT"),strThreads);
|
|
::OutputDebugString(strThreads+String("\n"));
|
|
thProfile.readProfileString(String("THREADS"),String("TIMETOLIVE"),strTimeToLive);
|
|
::OutputDebugString(strTimeToLive+String("\n"));
|
|
if(!(String("UNSET")==strThreads))itemCount=::atoi((LPSTR)strThreads);
|
|
if(!(String("UNSET")==strTimeToLive))timeToLive=::atoi((LPSTR)strTimeToLive);
|
|
}
|
|
|
|
|