AVPKit
AtomicInteger.h
1 /*******************************************************************************
2  * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved.
3  *
4  * This file is part of AVPKit.
5  *
6  * AVPKit is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * AVPKit is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with AVPKit. If not, see <http://www.gnu.org/licenses/>.
18  *******************************************************************************/
19 
20 #ifndef ATOMICINTEGER_H_
21 #define ATOMICINTEGER_H_
22 
23 #include <com/avpkit/ferry/JNIHelper.h>
24 
25 namespace com { namespace avpkit { namespace ferry {
45 class VS_API_FERRY AtomicInteger
46  {
47  public:
48  AtomicInteger();
49  AtomicInteger(int32_t);
50  ~AtomicInteger();
51 
52  int32_t get();
53  void set(int32_t);
54 
55  int32_t getAndSet(int32_t);
56  int32_t getAndIncrement();
57  int32_t getAndDecrement();
58  int32_t getAndAdd(int32_t);
59  int32_t incrementAndGet();
60  int32_t decrementAndGet();
61  int32_t addAndGet(int32_t);
62 
70  bool compareAndSet(int32_t expected, int32_t update);
71 
76  bool isAtomic();
77 
78  friend class JNIHelper;
79 
80  private:
81  static bool init();
82 
83  int32_t mNonAtomicValue;
84  jobject mAtomicValue;
85  static void initializeClass(JavaVM*, void*);
86  void initializeObject();
87  static jclass mClass;
88  static jmethodID mConstructorMethod;
89  static jmethodID mGetMethod;
90  static jmethodID mSetMethod;
91  static jmethodID mGetAndSetMethod;
92  static jmethodID mGetAndIncrementMethod;
93  static jmethodID mGetAndDecrementMethod;
94  static jmethodID mGetAndAddMethod;
95  static jmethodID mIncrementAndGetMethod;
96  static jmethodID mDecrementAndGetMethod;
97  static jmethodID mAddAndGetMethod;
98  static jmethodID mCompareAndSetMethod;
99 
100  static bool mInitialized;
101  };
102 }}}
103 #endif // ! ATOMICINTEGER_H_
104 
The JNIHelper object contains a series of methods designed to assist functions when running inside a ...
Definition: JNIHelper.h:37
WARNING: Do not use logging in this class, and do not set any static file variables to values other t...