Skip to content
Browse files

added crucial thread safe job code in job_thread_test.

  • Loading branch information...
1 parent fa5630e commit 0c87f7f03c0344ea21c2e8868d301998fed496d6 Daniel (dmilith) Dettlaff committed Sep 2, 2008
Showing with 76 additions and 12 deletions.
  1. +2 −4 job.cpp
  2. +2 −3 soul.cpp
  3. +7 −0 tests/Sconstruct
  4. +1 −1 tests/core/core.h
  5. +1 −1 tests/jobs/job_test_0.cpp
  6. +59 −0 tests/jobs/job_thread_test.cpp
  7. +4 −3 version.h
View
6 job.cpp
@@ -22,8 +22,6 @@ Job::~Job() {
void
Job::create_job( Cobject& object0_, Cobject& object1_, ETypeOfJob action_ ) {
- //shared_ptr<Cobject> actor0( object0_ );
- //shared_ptr<Cobject> actor1( object1_ );
actor0 = (const Csoul&)object0_;
actor1 = (const Csoul&)object1_;
set_action( action_ );
@@ -47,7 +45,7 @@ Job::set_action( ETypeOfJob type_ ) {
void
Job::run() {
-
+#define DEBUG
// matter on job type, do something with data
switch ( type ) {
case action_IDLE:
@@ -67,7 +65,7 @@ Job::run() {
break;
case action_ATTACK:
#ifdef DEBUG
- std::cout << "A:" << action_DEFEND << flush;
+ std::cout << "A:" << action_ATTACK << flush;
#endif
break;
View
5 soul.cpp
@@ -10,10 +10,9 @@
#include "soul.h"
Csoul::Csoul() {
- mana = 10;
+ mana = 10; //default value
mind_strength = 0;
-// soul_exist = 0; //domyslnie postac jest bezduszna -czyli npc/potwor
- alignment = neutral; //neutralny
+ alignment = neutral;
}
View
7 tests/Sconstruct
@@ -105,3 +105,10 @@ release14.Program('test_job_0' , 'jobs/job_test_0.cpp',
'item', 'map', 'place', 'soul', 'theritory',
'world', 'purecore'],
LIBPATH=[ '.', '../', '/usr/local/lib', '/usr/lib' ])
+
+release15 = Environment( CXX = 'g++ -O0 -ggdb -W' )
+release15.Program('test_job_thread_0' , 'jobs/job_thread_test.cpp',
+ LIBS=[ 'boost_thread', 'hl-sha', 'purecore', 'job', 'character', 'coordinates',
+ 'item', 'map', 'place', 'soul', 'theritory',
+ 'world', 'purecore'],
+ LIBPATH=[ '.', '../', '/usr/local/lib', '/usr/lib' ])
View
2 tests/core/core.h
@@ -37,7 +37,7 @@ namespace core {
- typedef struct COBJECT_DATA { // to save/ load structure data
+ struct COBJECT_DATA { // to save/ load structure data
char id[40 + 1]; // additional \0 !
Ccoordinates position;
int8_t priority;
View
2 tests/jobs/job_test_0.cpp
@@ -33,7 +33,7 @@ int main() {
Cobject myjob;
myjob = job->get_actor( 0 );
-
+
delete job;
//delete x;
//delete y;
View
59 tests/jobs/job_thread_test.cpp
@@ -0,0 +1,59 @@
+
+#include <iostream>
+#include <cassert>
+#include <fstream>
+#include <boost/shared_ptr.hpp>
+#include <boost/thread/thread.hpp>
+
+#include "../../hashlib/hl_tools.h"
+#include "../../coordinates.h"
+#include "../../version.h"
+#include "../../config.h"
+#include "../../job.h"
+#include "../../soul.h"
+
+
+using namespace std;
+using namespace core;
+
+
+extern void create_job( Cobject* object0, Cobject* object1 );
+
+
+#define DEBUG
+#define VERBOSE
+
+
+void
+run() {
+ boost::mutex mutex;
+ Csoul *x = new Csoul();
+ Csoul *y = new Csoul();
+
+ x->set_mana( 56700000 );
+ y->set_mana( 12300000 );
+ Job *job = new Job();
+ job->create_job( *x, *y, action_ATTACK );
+
+ cout << endl << job->get_actor( 0 ).get_mana() << flush << endl;
+ assert( (uint64_t)job->get_actor( 0 ).get_mana() == (uint64_t)56700000 );
+ assert( (uint64_t)job->get_actor( 1 ).get_mana() == (uint64_t)12300000 );
+
+ boost::mutex::scoped_lock lock( mutex );
+ job->run();
+
+ delete job;
+}
+
+
+int
+main( int argc, char* argv[] ) {
+ boost::thread_group threads;
+ for (int i = 0; i < 1000000; ++i)
+ threads.create_thread(&run);
+ cout << "Running threads." << endl;
+ threads.join_all();
+ return 0;
+}
+
+
View
7 version.h
@@ -1,8 +1,9 @@
#ifndef _VERSION_H_
#define _VERSION_H_
-// delirium (game master client)
-static const std::string CREALIS_CORE_VERSION = "0.0.7.git";
-static const std::string SYSTEM_CLASS_VERSION = "0.2.8.git";
+using namespace std;
+
+static const string CREALIS_CORE_VERSION = "0.0.8.git";
+static const string SYSTEM_CLASS_VERSION = "0.2.9.git";
#endif //_VERSION_H_

0 comments on commit 0c87f7f

Please sign in to comment.
Something went wrong with that request. Please try again.