imay commented on a change in pull request #1798: Optimize the load performance 
for large file
URL: https://github.com/apache/incubator-doris/pull/1798#discussion_r327560654
 
 

 ##########
 File path: be/src/util/counter_cond_variable.hpp
 ##########
 @@ -0,0 +1,73 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#pragma once
+
+#include <condition_variable>
+#include <mutex>
+
+namespace doris {
+
+// used for submitter/worker/waiter pattern
+// submitter:
+//      one or more submitters submit tasks and call inc_count()
+// worker:
+//      one or more workers do the task and call dec_count() after finishing 
the task
+// waiter:
+//      one or more waiter call xxx_wait() to wait until all or at least one 
tasks are finished.
+class CounterCondVariable {
+    public:
+        explicit CounterCondVariable(int init = 0) : _count(init) {
+        }
+
+        // increase the counter
+        void inc(int inc = 1) {
+            std::unique_lock<std::mutex> lock(_lock);
+            _count += inc;
+        }
+
+        // decrease the counter, and notify all waiters
+        void dec(int dec = 1) {
+            std::unique_lock<std::mutex> lock(_lock);
+            _count -= dec;
+            _cv.notify_all();
+        }
+
+        // wait until count down to zero
+        void block_wait() {
+            std::unique_lock<std::mutex> lock(_lock);
+            _cv.wait(lock, [=] { return _count <= 0; });
+        }
+
+        // wait if count larger than 0
+        // and after being notified, return true if count down zo zero,
+        // or return false other wise.
+        bool check_wait() {
 
 Review comment:
   I think a dec_to_zero function is better than this interface in this case.
   And dec_to_zero is more general.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to