#include <algorithm>
#include "safe-ctype.h"
#include "gdbsupport/selftest.h"
+#include <chrono>
/* See cooked-index.h. */
return range (lower, upper);
}
+/* See cooked-index.h. */
+
+void
+cooked_index_shard::wait (bool allow_quit) const
+{
+ if (allow_quit)
+ {
+ std::chrono::milliseconds duration { 15 };
+ while (m_future.wait_for (duration) == gdb::future_status::timeout)
+ QUIT;
+ }
+ else
+ m_future.wait ();
+}
+
cooked_index::cooked_index (vec_type &&vec)
: m_vector (std::move (vec))
{
void finalize ();
/* Wait for this index's finalization to be complete. */
- void wait () const
- {
- m_future.wait ();
- }
+ void wait (bool allow_quit = true) const;
friend class cooked_index;
end up writing to freed memory. Waiting for finalization to
complete avoids this problem; and the cost seems ignorable
because creating and immediately destroying the debug info is a
- relatively rare thing to do. */
- wait ();
+ relatively rare thing to do. Do not allow quitting from this
+ wait. */
+ for (auto &item : m_vector)
+ item->wait (false);
}
/* A range over a vector of subranges. */
#include <queue>
#include <vector>
#include <functional>
+#include <chrono>
#if CXX_STD_THREAD
#include <thread>
#include <mutex>
template<typename T>
using future = std::future<T>;
+/* ... and the standard future_status. */
+using future_status = std::future_status;
+
#else /* CXX_STD_THREAD */
+/* A compatibility enum for std::future_status. This is just the
+ subset needed by gdb. */
+enum class future_status
+{
+ ready,
+ timeout,
+};
+
/* A compatibility wrapper for std::future. Once <thread> and
<future> are available in all GCC builds -- should that ever happen
-- this can be removed. GCC does not implement threading for
void wait () const { }
+ template<class Rep, class Period>
+ future_status wait_for (const std::chrono::duration<Rep,Period> &duration)
+ const
+ {
+ return future_status::ready;
+ }
+
T get () { return std::move (m_value); }
private:
{
public:
void wait () const { }
+
+ template<class Rep, class Period>
+ future_status wait_for (const std::chrono::duration<Rep,Period> &duration)
+ const
+ {
+ return future_status::ready;
+ }
+
void get () { }
};