store: expose the mutex so we can lock query-results
The QueryResults must not outlive the lock (when in a MT context), so expose for clients (mu-server) to handle it.
This commit is contained in:
@ -662,14 +662,18 @@ Store::for_each_term(const std::string& field, Store::ForEachTermFunc func) cons
|
|||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::mutex&
|
||||||
|
Store::lock() const
|
||||||
|
{
|
||||||
|
return priv_->lock_;
|
||||||
|
}
|
||||||
|
|
||||||
Option<QueryResults>
|
Option<QueryResults>
|
||||||
Store::run_query(const std::string& expr, MuMsgFieldId sortfieldid,
|
Store::run_query(const std::string& expr, MuMsgFieldId sortfieldid,
|
||||||
QueryFlags flags, size_t maxnum) const
|
QueryFlags flags, size_t maxnum) const
|
||||||
{
|
{
|
||||||
return xapian_try([&] {
|
return xapian_try([&] {
|
||||||
std::lock_guard guard{priv_->lock_};
|
|
||||||
Query q{*this};
|
Query q{*this};
|
||||||
|
|
||||||
return q.run(expr, sortfieldid, flags, maxnum);
|
return q.run(expr, sortfieldid, flags, maxnum);
|
||||||
},
|
},
|
||||||
Nothing);
|
Nothing);
|
||||||
|
|||||||
@ -143,6 +143,9 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Run a query; see the `mu-query` man page for the syntax.
|
* Run a query; see the `mu-query` man page for the syntax.
|
||||||
*
|
*
|
||||||
|
* Multi-threaded callers must aquire the lock and keep it
|
||||||
|
* at least as long as the return value.
|
||||||
|
*
|
||||||
* @param expr the search expression
|
* @param expr the search expression
|
||||||
* @param sortfieldid the sortfield-id. If the field is NONE, sort by DATE
|
* @param sortfieldid the sortfield-id. If the field is NONE, sort by DATE
|
||||||
* @param flags query flags
|
* @param flags query flags
|
||||||
@ -150,6 +153,7 @@ public:
|
|||||||
*
|
*
|
||||||
* @return the query-results, or Nothing in case of error.
|
* @return the query-results, or Nothing in case of error.
|
||||||
*/
|
*/
|
||||||
|
std::mutex& lock() const;
|
||||||
Option<QueryResults> run_query(const std::string& expr = "",
|
Option<QueryResults> run_query(const std::string& expr = "",
|
||||||
MuMsgFieldId sortfieldid = MU_MSG_FIELD_ID_NONE,
|
MuMsgFieldId sortfieldid = MU_MSG_FIELD_ID_NONE,
|
||||||
QueryFlags flags = QueryFlags::None,
|
QueryFlags flags = QueryFlags::None,
|
||||||
|
|||||||
Reference in New Issue
Block a user