Changeset 8:dba41f33ddce in xplcommon for test/testevent.cc


Ignore:
Timestamp:
12/29/12 08:01:50 (11 years ago)
Author:
István Váradi <ivaradi@…>
Branch:
default
Phase:
public
Message:

Clarified the blocking and non-blocking behaviour and extended the test program to test both

File:
1 edited

Legend:

Unmodified
Added
Removed
  • test/testevent.cc

    r4 r8  
    8989//------------------------------------------------------------------------------
    9090
     91class BlockingServerThread : public Thread
     92{
     93private:
     94    WaitableEvent event;
     95
     96public:
     97    WaitableEvent& getEvent();
     98
     99    virtual void run();
     100};
     101
     102//------------------------------------------------------------------------------
     103
     104inline WaitableEvent& BlockingServerThread::getEvent()
     105{
     106    return event;
     107}
     108
     109//------------------------------------------------------------------------------
     110
     111void BlockingServerThread::run()
     112{
     113    printf("BlockingServerThread::run: waiting...\n");
     114    if (event.check()) {
     115        printf("BlockingServerThread::run: waiting done\n");
     116    } else {
     117        printf("BlockingServerThread::run: waiting failed\n");
     118    }
     119    printf("BlockingServerThread::run: finished\n");
     120}
     121
     122
     123//------------------------------------------------------------------------------
     124//------------------------------------------------------------------------------
     125
    91126class ClientThread : public Thread
    92127{
     
    120155//------------------------------------------------------------------------------
    121156
    122 int main()
     157template <class Server> void runTest()
    123158{
    124     ServerThread serverThread;
     159    Server serverThread;
    125160    ClientThread clientThread(serverThread.getEvent());
    126161
     
    134169    serverThread.join();
    135170    printf("Both threads returned\n");
     171}
     172
     173//------------------------------------------------------------------------------
     174//------------------------------------------------------------------------------
     175
     176int main()
     177{
     178    printf("Running the event test with a non-blocking WaitableEvent\n\n");
     179    runTest<ServerThread>();
     180
     181    printf("\n\nRunning the event test with a blocking WaitableEvent\n\n");
     182    runTest<BlockingServerThread>();
    136183
    137184    return 0;
Note: See TracChangeset for help on using the changeset viewer.