Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-28 08:27:07

0001 // Licensed to the Apache Software Foundation (ASF) under one
0002 // or more contributor license agreements.  See the NOTICE file
0003 // distributed with this work for additional information
0004 // regarding copyright ownership.  The ASF licenses this file
0005 // to you under the Apache License, Version 2.0 (the
0006 // "License"); you may not use this file except in compliance
0007 // with the License.  You may obtain a copy of the License at
0008 //
0009 //   http://www.apache.org/licenses/LICENSE-2.0
0010 //
0011 // Unless required by applicable law or agreed to in writing,
0012 // software distributed under the License is distributed on an
0013 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0014 // KIND, either express or implied.  See the License for the
0015 // specific language governing permissions and limitations
0016 // under the License.
0017 
0018 #ifndef ARROW_COUNTING_SEMAPHORE_H
0019 #define ARROW_COUNTING_SEMAPHORE_H
0020 
0021 #include <memory>
0022 
0023 #include "arrow/status.h"
0024 
0025 namespace arrow {
0026 namespace util {
0027 
0028 /// \brief Simple mutex-based counting semaphore with timeout
0029 class ARROW_EXPORT CountingSemaphore {
0030  public:
0031   /// \brief Create an instance with initial_avail starting permits
0032   ///
0033   /// \param[in] initial_avail The semaphore will start with this many permits available
0034   /// \param[in] timeout_seconds A timeout to be applied to all operations.  Operations
0035   ///            will return Status::Invalid if this timeout elapses
0036   explicit CountingSemaphore(uint32_t initial_avail = 0, double timeout_seconds = 10);
0037   ~CountingSemaphore();
0038   /// \brief Block until num_permits permits are available
0039   Status Acquire(uint32_t num_permits);
0040   /// \brief Make num_permits permits available
0041   Status Release(uint32_t num_permits);
0042   /// \brief Wait until num_waiters are waiting on permits
0043   ///
0044   /// This method is non-standard but useful in unit tests to ensure sequencing
0045   Status WaitForWaiters(uint32_t num_waiters);
0046   /// \brief Immediately time out any waiters
0047   ///
0048   /// This method will return Status::OK only if there were no waiters to time out.
0049   /// Once closed any operation on this instance will return an invalid status.
0050   Status Close();
0051 
0052  private:
0053   class Impl;
0054   std::unique_ptr<Impl> impl_;
0055 };
0056 
0057 }  // namespace util
0058 }  // namespace arrow
0059 
0060 #endif  // ARROW_COUNTING_SEMAPHORE_H