1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 package org.rocksdb;
6 
7 /**
8  * Determines the type of synchronisation primitive used
9  * in native code.
10  */
11 public enum ReusedSynchronisationType {
12   /**
13    * Standard mutex.
14    */
15   MUTEX((byte)0x0),
16 
17   /**
18    * Use adaptive mutex, which spins in the user space before resorting
19    * to kernel. This could reduce context switch when the mutex is not
20    * heavily contended. However, if the mutex is hot, we could end up
21    * wasting spin time.
22    */
23   ADAPTIVE_MUTEX((byte)0x1),
24 
25   /**
26    * There is a reused buffer per-thread.
27    */
28   THREAD_LOCAL((byte)0x2);
29 
30   private final byte value;
31 
ReusedSynchronisationType(final byte value)32   ReusedSynchronisationType(final byte value) {
33     this.value = value;
34   }
35 
36   /**
37    * Returns the byte value of the enumerations value
38    *
39    * @return byte representation
40    */
getValue()41   public byte getValue() {
42     return value;
43   }
44 
45   /**
46    * Get ReusedSynchronisationType by byte value.
47    *
48    * @param value byte representation of ReusedSynchronisationType.
49    *
50    * @return {@link org.rocksdb.ReusedSynchronisationType} instance.
51    * @throws java.lang.IllegalArgumentException if an invalid
52    *     value is provided.
53    */
getReusedSynchronisationType( final byte value)54   public static ReusedSynchronisationType getReusedSynchronisationType(
55       final byte value) {
56     for (final ReusedSynchronisationType reusedSynchronisationType
57         : ReusedSynchronisationType.values()) {
58       if (reusedSynchronisationType.getValue() == value) {
59         return reusedSynchronisationType;
60       }
61     }
62     throw new IllegalArgumentException(
63         "Illegal value provided for ReusedSynchronisationType.");
64   }
65 }
66