Hazelcast C++ Client
ISemaphore.h
1 /*
2  * Copyright (c) 2008-2018, Hazelcast, Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef HAZELCAST_ISEMAPHORE
17 #define HAZELCAST_ISEMAPHORE
18 
19 #include <string>
20 #include <stdint.h>
21 #include <stdexcept>
22 #include "hazelcast/client/proxy/ProxyImpl.h"
23 #include "hazelcast/client/exception/IException.h"
24 
25 namespace hazelcast {
26  namespace client {
57  class HAZELCAST_API ISemaphore : public proxy::ProxyImpl {
58  friend class impl::HazelcastClientInstanceImpl;
59 
60  public:
61 
67  bool init(int permits);
68 
95  void acquire();
96 
127  void acquire(int permits);
128 
129 
138  int availablePermits();
139 
140 
146  int drainPermits();
147 
156  void reducePermits(int reduction);
157 
166  void increasePermits(int32_t increase);
167 
178  void release();
179 
191  void release(int permits);
192 
204  bool tryAcquire();
205 
219  bool tryAcquire(int permits);
220 
262  bool tryAcquire(long timeoutInMillis);
263 
303  bool tryAcquire(int permits, long timeoutInMillis);
304 
305  private:
306 
307  ISemaphore(const std::string &instanceName, spi::ClientContext *context);
308 
309  void checkNegative(int32_t permits) const;
310 
311  int partitionId;
312  };
313  }
314 }
315 
316 #endif /* HAZELCAST_ISEMAPHORE */
Definition: MapEntryView.h:32
ISemaphore is a backed-up distributed alternative to the java.util.concurrent.Semaphore.
Definition: ISemaphore.h:57