]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Threadengine stuff
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Feb 2008 17:06:20 +0000 (17:06 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 21 Feb 2008 17:06:20 +0000 (17:06 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8980 e03df62e-2008-0410-955e-edbf42e46eb7

configure
include/threadengines/threadengine_pthread.h
src/testsuite.cpp

index 2948e0b40a67461de3ce24c143732267c0bc089c..b231602495aaa90185576cf96608dd71e1a2a004 100755 (executable)
--- a/configure
+++ b/configure
@@ -1153,6 +1153,7 @@ sub writefiles {
 #define OPTIMISATION $config{OPTIMITEMP}
 #define LIBRARYDIR "$config{LIBRARY_DIR}"
 #define SYSTEM "$incos"
+
 EOF
 print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
 
@@ -1199,7 +1200,7 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
                        print FILEHANDLE "#define USE_SELECT\n";
                        $se = "socketengine_select";
                }
-               print FILEHANDLE "\n#endif\n";
+               print FILEHANDLE "\n#include \"include/threadengines/threadengine_pthread.h\"\n\n#endif\n";
                close(FILEHANDLE);
        }
 
index 2c821d93dbe85d125c0186a9b708a7081c8acf5b..e8f7a4087f89a21f6bad2fe18364d1614206964e 100644 (file)
@@ -40,4 +40,12 @@ class CoreExport PThreadEngine : public ThreadEngine
        void FreeThread(Thread* thread);
 };
 
+class ThreadEngineFactory : public classbase
+{
+       ThreadEngine* Create(InspIRCd* ServerInstance)
+       {
+               return new PThreadEngine(ServerInstance);
+       }
+};
+
 #endif
index f02b3aed36602b48da13b55d86c47aedd2ce8c42..a129ecc728c3f153c73a7630bace673cca2acc2d 100644 (file)
 
 #include "inspircd.h"
 #include "testsuite.h"
+#include "threadengine.h"
 #include <iostream>
 
 using namespace std;
 
+class TestSuiteThread : public Thread
+{
+       TestSuiteThread() : Thread()
+       {
+       }
+
+       virtual ~TestSuiteThread()
+       {
+       }
+
+       virtual void Run()
+       {
+               while (1)
+               {
+                       cout << "Test suite thread run...\n";
+                       sleep(10);
+               }
+       }
+};
+
 TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
 {
        cout << "\n\n*** STARTING TESTSUITE ***\n";
 
        std::string modname;
+       std::string choice;
+
+       ServerInstance->SE->Blocking(fileno(stdin));
 
        while (1)
        {
@@ -31,8 +55,13 @@ TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
                cout << "(2) Load a module\n";
                cout << "(3) Unload a module\n";
                cout << "(4) Threading tests\n";
-       
-               switch (fgetc(stdin))
+
+               cout << endl << "(X) Exit test suite\n";
+
+               cout << "\nChoice: ";
+               cin >> choice;
+
+               switch (*choice.begin())
                {
                        case '1':
                                FOREACH_MOD(I_OnRunTestSuite, OnRunTestSuite());
@@ -50,6 +79,12 @@ TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
                        case '4':
                                cout << (DoThreadTests() ? "\nSUCCESS!\n" : "\nFAILURE\n");
                        break;
+                       case 'X':
+                               return;
+                       break;
+                       default:
+                               cout << "Invalid option\n";
+                       break;
                }
                cout << endl;
        }
@@ -57,6 +92,35 @@ TestSuite::TestSuite(InspIRCd* Instance) : ServerInstance(Instance)
 
 bool TestSuite::DoThreadTests()
 {
+       std::string anything;
+       cout << "Creating new ThreadEngine class...\n";
+       try
+       {
+               ThreadEngineFactory* tef = new ThreadEngineFactory();
+               ThreadEngine* te = tef->Create(ServerInstance);
+               delete tef;
+       }
+       catch (...)
+       {
+               cout << "Creation failed, test failure.\n";
+               return false;
+       }
+       cout << "Creation success!\n";
+
+       cout << "Creating new thread of type TestSuiteThread\n";
+
+       TestSuiteThread* tst = new TestSuiteThread();
+
+       te->Create(tst);
+
+       cout >> "Press enter to end test.";
+       cin >> anything;
+
+       /* Auto frees thread */
+       delete tst;
+
+       delete te;
+
        return true;
 }