diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-10 12:58:24 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2010-09-10 12:58:24 +0200 |
commit | 49148af30f42baf101e32581c48acdf4540b6442 (patch) | |
tree | 0e1a3d5a0524abc2ca985a3cb984a1c198ffaff7 /common | |
parent | ed24158b4d247dff58162c97f04cbc4011579600 (diff) |
Allow the test to specify max number of connections
Use this in common/threads.
Diffstat (limited to 'common')
-rw-r--r-- | common/threads/driver.cxx | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/common/threads/driver.cxx b/common/threads/driver.cxx index e996dae..539db5f 100644 --- a/common/threads/driver.cxx +++ b/common/threads/driver.cxx @@ -8,6 +8,7 @@ #include <vector> #include <memory> // std::auto_ptr +#include <cstddef> // std::size_t #include <cassert> #include <iostream> @@ -109,35 +110,54 @@ struct task unsigned long n_; }; - -int -main (int argc, char* argv[]) +void +test (int argc, char* argv[], size_t max_connections) { - try + auto_ptr<database> db (create_database (argc, argv, max_connections)); + + vector<details::shared_ptr<details::thread> > threads; + vector<details::shared_ptr<task> > tasks; + + for (unsigned long i (0); i < thread_count; ++i) { - auto_ptr<database> db (create_database (argc, argv)); + details::shared_ptr<task> t (new (details::shared) task (*db, i)); + tasks.push_back (t); - vector<details::shared_ptr<details::thread> > threads; - vector<details::shared_ptr<task> > tasks; + threads.push_back ( + details::shared_ptr<details::thread> ( + new (details::shared) details::thread (&task::execute, t.get ()))); + } - for (unsigned long i (0); i < thread_count; ++i) - { - details::shared_ptr<task> t (new (details::shared) task (*db, i)); - tasks.push_back (t); + for (unsigned long i (0); i < thread_count; ++i) + threads[i]->join (); - threads.push_back ( - details::shared_ptr<details::thread> ( - new (details::shared) details::thread (&task::execute, t.get ()))); - } + { + typedef odb::result<object> result; + + transaction t (db->begin_transaction ()); + result r (db->query<object> ()); + r.cache (); - for (unsigned long i (0); i < thread_count; ++i) - threads[i]->join (); + for (result::iterator i (r.begin ()); i != r.end (); ++i) + db->erase<object> (i->id_); + + t.commit (); + } +} + +int +main (int argc, char* argv[]) +{ + try + { + test (argc, argv, 0); + test (argc, argv, thread_count - 1); + test (argc, argv, thread_count / 2); + test (argc, argv, thread_count / 4); } catch (const odb::exception& e) { cerr << e.what () << endl; return 1; } - - // pthread_exit (0); } |