OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-cogutil commits / 811604e

async_buffer interface to use forwarding reference
811604e0f03d42ffb32dcae97158e73f52449831
by Linas Vepstas <linasvepstas@gmail.com> · 2025-12-07T17:23:29.000Z

Changed files (1) +8 -7

opencog/util/async_buffer.h +8 -7
……@@ -150,7 +150,7 @@ class async_buffer
150150 void stop_writer_threads();
151151 void write_loop();
152152
153 void do_insert(const Element&);
153 void do_insert(Element&&);
154154 void drain();
155155
156156 public:
……@@ -159,7 +159,8 @@ class async_buffer
159159
160160 async_buffer(Writer*, void (Writer::*)(const Element&), int nthreads=4);
161161 ~async_buffer();
162 void insert(const Element&);
162 void insert(const Element& elt) { insert(Element(elt)); }
163 void insert(Element&&);
163164 void flush();
164165 void barrier(void);
165166 template<typename Factory>
……@@ -526,10 +527,10 @@ void async_buffer<Writer, Element>::write_loop()
526527
527528/// Insert, no matter what. Private, unsafe for external use.
528529template<typename Writer, typename Element>
529void async_buffer<Writer, Element>::do_insert(const Element& elt)
530void async_buffer<Writer, Element>::do_insert(Element&& elt)
530531{
531532 _pending ++;
532 bool inserted = _store_set.insert(elt);
533 bool inserted = _store_set.insert(std::move(elt));
533534 _item_count++;
534535 if (not inserted)
535536 {
……@@ -545,7 +546,7 @@ void async_buffer<Writer, Element>::do_insert(const Element& elt)
545546 * mostly drained...
546547 */
547548template<typename Writer, typename Element>
548void async_buffer<Writer, Element>::insert(const Element& elt)
549void async_buffer<Writer, Element>::insert(Element&& elt)
549550{
550551 // Sanity checks.
551552 if (_stopping_writers)
……@@ -574,7 +575,7 @@ void async_buffer<Writer, Element>::insert(const Element& elt)
574575 {
575576 if (th.get_id() == tid)
576577 {
577 do_insert(elt);
578 do_insert(std::move(elt));
578579 return;
579580 }
580581 }
……@@ -585,7 +586,7 @@ void async_buffer<Writer, Element>::insert(const Element& elt)
585586 // do need to use a lock for that.
586587 {
587588 std::unique_lock<std::mutex> lock(_enqueue_mutex);
588 do_insert(elt);
589 do_insert(std::move(elt));
589590 }
590591
591592 // If the writer threads are falling behind, mitigate.