77#include " sqlite.h"
88#include " util/helpers.h"
99#include " util/testing.h"
10- #include " util/threading.h"
1110
1211#include < algorithm>
1312#include < list>
@@ -59,8 +58,6 @@ struct Pimpl<Database>::Implementation {
5958 // Helper to lookup scheduled query.
6059 std::optional<std::list<ScheduledQuery>::iterator> lookupQuery (query::ID);
6160
62- SynchronizedBase* _synchronized =
63- nullptr ; // database's synchronizer, so that we can grab it during callback execution
6461 const Configuration* _configuration = nullptr ; // configuration object, as passed into constructor
6562 Scheduler* _scheduler = nullptr ; // scheduler as passed into constructor
6663 std::unique_ptr<SQLite> _sqlite; // SQLite backend for performing queries
@@ -127,9 +124,7 @@ void Database::Implementation::expire() {
127124 continue ;
128125
129126 if ( (*i)->query .callback_done )
130- _synchronized->unlockWhile ([&, id = id, regular_shutdown = regular_shutdown]() {
131- (*(*i)->query .callback_done )(id, ! regular_shutdown);
132- });
127+ (*(*i)->query .callback_done )(id, ! regular_shutdown);
133128 }
134129
135130 for ( const auto & [id, regular_shutdown] : _cancelled_queries ) {
@@ -231,15 +226,12 @@ static auto newRows(std::vector<std::vector<Value>> old, std::vector<std::vector
231226}
232227
233228Interval Database::Implementation::timerCallback (timer::ID id) {
234- SynchronizedBase::Synchronize _ (_synchronized);
235-
236229 auto i = lookupQuery (id);
237230 if ( ! i || (*i)->query .cancelled )
238231 // already gone, or will be cleaned up shortly
239232 return 0s;
240233
241- auto sql_result = _synchronized->unlockWhile (
242- [&]() { return _sqlite->runStatement (*(*i)->prepared_query , (*i)->previous_execution ); });
234+ auto sql_result = _sqlite->runStatement (*(*i)->prepared_query , (*i)->previous_execution );
243235
244236 // re-lookup because we released the lock
245237 i = lookupQuery (id);
@@ -282,14 +274,12 @@ Interval Database::Implementation::timerCallback(timer::ID id) {
282274#endif
283275
284276 if ( (*i)->query .callback_result ) {
285- _synchronized->unlockWhile ([&]() {
286- auto query_result = query::Result{.columns = sql_result->columns ,
287- .rows = std::move (rows),
288- .cookie = (*i)->query .cookie ,
289- .initial_result = ! (*i)->previous_result .has_value ()};
277+ auto query_result = query::Result{.columns = sql_result->columns ,
278+ .rows = std::move (rows),
279+ .cookie = (*i)->query .cookie ,
280+ .initial_result = ! (*i)->previous_result .has_value ()};
290281
291- (*(*i)->query .callback_result )(id, query_result);
292- });
282+ (*(*i)->query .callback_result )(id, query_result);
293283
294284 // repeat search in case map was modified by callback
295285 i = lookupQuery (id);
@@ -328,7 +318,6 @@ Table* Database::Implementation::table(const std::string& name) {
328318
329319Database::Database (Configuration* configuration, Scheduler* scheduler) {
330320 ZEEK_AGENT_DEBUG (" database" , " creating instance" );
331- pimpl ()->_synchronized = this ;
332321 pimpl ()->_configuration = configuration;
333322 pimpl ()->_scheduler = scheduler;
334323 pimpl ()->_sqlite = std::make_unique<SQLite>();
@@ -349,15 +338,9 @@ Time Database::currentTime() const {
349338 return pimpl ()->_scheduler ->currentTime ();
350339}
351340
352- size_t Database::numberQueries () const {
353- Synchronize _ (this );
354- return pimpl ()->_queries .size ();
355- }
341+ size_t Database::numberQueries () const { return pimpl ()->_queries .size (); }
356342
357- Table* Database::table (const std::string& name) {
358- Synchronize _ (this );
359- return pimpl ()->table (name);
360- }
343+ Table* Database::table (const std::string& name) { return pimpl ()->table (name); }
361344
362345std::vector<const Table*> Database::tables () {
363346 std::vector<const Table*> out;
@@ -371,7 +354,6 @@ std::vector<const Table*> Database::tables() {
371354
372355Result<std::optional<query::ID>> Database::query (const Query& q) {
373356 ZEEK_AGENT_DEBUG (" database" , " new query: {} " , q.sql_stmt );
374- Synchronize _ (this );
375357
376358 auto id = pimpl ()->query (q);
377359 if ( id ) {
@@ -388,26 +370,21 @@ Result<std::optional<query::ID>> Database::query(const Query& q) {
388370
389371void Database::cancel (query::ID id) {
390372 ZEEK_AGENT_DEBUG (" database" , " canceling query {}" , id);
391- Synchronize _ (this );
392373 return pimpl ()->cancel (id, false );
393374}
394375
395376void Database::poll () {
396377 ZEEK_AGENT_DEBUG (" database" , " polling database" );
397- Synchronize _ (this );
398378 pimpl ()->poll ();
399379 pimpl ()->expire ();
400380}
401381
402382void Database::expire () {
403383 ZEEK_AGENT_DEBUG (" database" , " expiring database state" );
404- Synchronize _ (this );
405384 pimpl ()->expire ();
406385}
407386
408387void Database::addTable (Table* t) {
409- Synchronize _ (this );
410-
411388 t->setDatabase (this );
412389
413390 if ( configuration ().options ().use_mock_data )
0 commit comments