couchbase 3.1.1-universal-darwin-20 → 3.2.0-universal-darwin-20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/ext/CMakeLists.txt +3 -1
  4. data/ext/build_version.hxx.in +1 -1
  5. data/ext/cmake/Testing.cmake +1 -0
  6. data/ext/cmake/ThirdPartyDependencies.cmake +6 -0
  7. data/ext/cmake/VersionInfo.cmake +3 -0
  8. data/ext/couchbase/bucket.hxx +47 -28
  9. data/ext/couchbase/cbsasl/client.h +1 -1
  10. data/ext/couchbase/cbsasl/context.cc +1 -1
  11. data/ext/couchbase/cbsasl/context.h +3 -3
  12. data/ext/couchbase/cbsasl/mechanism.cc +5 -8
  13. data/ext/couchbase/cbsasl/mechanism.h +1 -4
  14. data/ext/couchbase/cbsasl/plain/plain.cc +1 -1
  15. data/ext/couchbase/cbsasl/scram-sha/scram-sha.cc +30 -36
  16. data/ext/couchbase/cluster.hxx +40 -22
  17. data/ext/couchbase/cluster_options.hxx +7 -1
  18. data/ext/couchbase/configuration.hxx +37 -16
  19. data/ext/couchbase/couchbase.cxx +1145 -291
  20. data/ext/couchbase/error_map.hxx +1 -1
  21. data/ext/couchbase/errors.hxx +25 -17
  22. data/ext/couchbase/io/dns_client.hxx +3 -3
  23. data/ext/couchbase/io/dns_codec.hxx +4 -5
  24. data/ext/couchbase/io/dns_config.hxx +5 -6
  25. data/ext/couchbase/io/dns_message.hxx +3 -3
  26. data/ext/couchbase/io/http_command.hxx +70 -35
  27. data/ext/couchbase/io/http_session.hxx +4 -3
  28. data/ext/couchbase/io/http_session_manager.hxx +28 -19
  29. data/ext/couchbase/io/mcbp_command.hxx +51 -19
  30. data/ext/couchbase/io/mcbp_context.hxx +1 -1
  31. data/ext/couchbase/io/mcbp_parser.hxx +4 -4
  32. data/ext/couchbase/io/mcbp_session.hxx +91 -101
  33. data/ext/couchbase/io/query_cache.hxx +2 -2
  34. data/ext/couchbase/io/retry_orchestrator.hxx +2 -4
  35. data/ext/couchbase/io/retry_reason.hxx +2 -2
  36. data/ext/couchbase/io/retry_strategy.hxx +1 -6
  37. data/ext/couchbase/io/streams.hxx +7 -7
  38. data/ext/couchbase/metrics/logging_meter.hxx +228 -0
  39. data/ext/couchbase/metrics/logging_meter_options.hxx +28 -0
  40. data/ext/couchbase/metrics/meter.hxx +49 -0
  41. data/ext/couchbase/metrics/noop_meter.hxx +43 -0
  42. data/ext/couchbase/operations.hxx +4 -0
  43. data/ext/couchbase/operations/analytics_dataset_create.hxx +16 -12
  44. data/ext/couchbase/operations/analytics_dataset_drop.hxx +11 -11
  45. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +6 -6
  46. data/ext/couchbase/operations/analytics_dataverse_create.hxx +10 -11
  47. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +10 -11
  48. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +9 -11
  49. data/ext/couchbase/operations/analytics_index_create.hxx +14 -13
  50. data/ext/couchbase/operations/analytics_index_drop.hxx +18 -12
  51. data/ext/couchbase/operations/analytics_index_get_all.hxx +8 -6
  52. data/ext/couchbase/operations/analytics_link.hxx +39 -0
  53. data/ext/couchbase/operations/analytics_link_azure_blob_external.hxx +145 -0
  54. data/ext/couchbase/operations/analytics_link_connect.hxx +14 -12
  55. data/ext/couchbase/operations/analytics_link_couchbase_remote.hxx +220 -0
  56. data/ext/couchbase/operations/analytics_link_create.hxx +128 -0
  57. data/ext/couchbase/operations/analytics_link_disconnect.hxx +11 -12
  58. data/ext/couchbase/operations/analytics_link_drop.hxx +130 -0
  59. data/ext/couchbase/operations/analytics_link_get_all.hxx +160 -0
  60. data/ext/couchbase/operations/analytics_link_replace.hxx +128 -0
  61. data/ext/couchbase/operations/analytics_link_s3_external.hxx +122 -0
  62. data/ext/couchbase/operations/bucket_create.hxx +8 -8
  63. data/ext/couchbase/operations/bucket_drop.hxx +5 -5
  64. data/ext/couchbase/operations/bucket_flush.hxx +5 -5
  65. data/ext/couchbase/operations/bucket_get.hxx +7 -7
  66. data/ext/couchbase/operations/bucket_get_all.hxx +7 -5
  67. data/ext/couchbase/operations/bucket_settings.hxx +40 -49
  68. data/ext/couchbase/operations/bucket_update.hxx +8 -8
  69. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +7 -7
  70. data/ext/couchbase/operations/collection_create.hxx +11 -11
  71. data/ext/couchbase/operations/collection_drop.hxx +12 -10
  72. data/ext/couchbase/operations/collections_manifest_get.hxx +3 -3
  73. data/ext/couchbase/operations/design_document.hxx +2 -2
  74. data/ext/couchbase/operations/document_analytics.hxx +29 -36
  75. data/ext/couchbase/operations/document_append.hxx +3 -3
  76. data/ext/couchbase/operations/document_decrement.hxx +3 -3
  77. data/ext/couchbase/operations/document_exists.hxx +2 -2
  78. data/ext/couchbase/operations/document_get.hxx +3 -3
  79. data/ext/couchbase/operations/document_get_and_lock.hxx +5 -3
  80. data/ext/couchbase/operations/document_get_and_touch.hxx +5 -3
  81. data/ext/couchbase/operations/document_get_projected.hxx +10 -11
  82. data/ext/couchbase/operations/document_increment.hxx +3 -3
  83. data/ext/couchbase/operations/document_insert.hxx +3 -3
  84. data/ext/couchbase/operations/document_lookup_in.hxx +12 -18
  85. data/ext/couchbase/operations/document_mutate_in.hxx +13 -18
  86. data/ext/couchbase/operations/document_prepend.hxx +3 -3
  87. data/ext/couchbase/operations/document_query.hxx +39 -41
  88. data/ext/couchbase/operations/document_remove.hxx +3 -3
  89. data/ext/couchbase/operations/document_replace.hxx +3 -3
  90. data/ext/couchbase/operations/document_search.hxx +56 -61
  91. data/ext/couchbase/operations/document_touch.hxx +3 -3
  92. data/ext/couchbase/operations/document_unlock.hxx +3 -3
  93. data/ext/couchbase/operations/document_upsert.hxx +3 -3
  94. data/ext/couchbase/operations/document_view.hxx +23 -23
  95. data/ext/couchbase/operations/group_drop.hxx +5 -5
  96. data/ext/couchbase/operations/group_get.hxx +7 -7
  97. data/ext/couchbase/operations/group_get_all.hxx +6 -6
  98. data/ext/couchbase/operations/group_upsert.hxx +11 -11
  99. data/ext/couchbase/operations/http_noop.hxx +6 -6
  100. data/ext/couchbase/operations/mcbp_noop.hxx +3 -3
  101. data/ext/couchbase/operations/query_index_build_deferred.hxx +6 -6
  102. data/ext/couchbase/operations/query_index_create.hxx +10 -8
  103. data/ext/couchbase/operations/query_index_drop.hxx +8 -8
  104. data/ext/couchbase/operations/query_index_get_all.hxx +43 -39
  105. data/ext/couchbase/operations/rbac.hxx +40 -63
  106. data/ext/couchbase/operations/role_get_all.hxx +6 -6
  107. data/ext/couchbase/operations/scope_create.hxx +10 -10
  108. data/ext/couchbase/operations/scope_drop.hxx +9 -9
  109. data/ext/couchbase/operations/scope_get_all.hxx +8 -8
  110. data/ext/couchbase/operations/search_get_stats.hxx +5 -3
  111. data/ext/couchbase/operations/search_index.hxx +6 -15
  112. data/ext/couchbase/operations/search_index_analyze_document.hxx +11 -11
  113. data/ext/couchbase/operations/search_index_control_ingest.hxx +9 -9
  114. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +9 -9
  115. data/ext/couchbase/operations/search_index_control_query.hxx +9 -9
  116. data/ext/couchbase/operations/search_index_drop.hxx +11 -9
  117. data/ext/couchbase/operations/search_index_get.hxx +11 -9
  118. data/ext/couchbase/operations/search_index_get_all.hxx +11 -11
  119. data/ext/couchbase/operations/search_index_get_documents_count.hxx +10 -10
  120. data/ext/couchbase/operations/search_index_get_stats.hxx +10 -8
  121. data/ext/couchbase/operations/search_index_upsert.hxx +12 -10
  122. data/ext/couchbase/operations/user_drop.hxx +5 -5
  123. data/ext/couchbase/operations/user_get.hxx +7 -7
  124. data/ext/couchbase/operations/user_get_all.hxx +6 -6
  125. data/ext/couchbase/operations/user_upsert.hxx +9 -9
  126. data/ext/couchbase/operations/view_index_drop.hxx +10 -10
  127. data/ext/couchbase/operations/view_index_get.hxx +13 -15
  128. data/ext/couchbase/operations/view_index_get_all.hxx +17 -20
  129. data/ext/couchbase/operations/view_index_upsert.hxx +9 -7
  130. data/ext/couchbase/origin.hxx +14 -10
  131. data/ext/couchbase/platform/backtrace.c +1 -1
  132. data/ext/couchbase/platform/base64.cc +5 -5
  133. data/ext/couchbase/platform/base64.h +2 -5
  134. data/ext/couchbase/protocol/client_opcode.hxx +7 -4
  135. data/ext/couchbase/protocol/client_request.hxx +2 -2
  136. data/ext/couchbase/protocol/client_response.hxx +41 -16
  137. data/ext/couchbase/protocol/cmd_append.hxx +17 -16
  138. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +4 -4
  139. data/ext/couchbase/protocol/cmd_decrement.hxx +10 -11
  140. data/ext/couchbase/protocol/cmd_exists.hxx +12 -15
  141. data/ext/couchbase/protocol/cmd_get.hxx +11 -14
  142. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +10 -12
  143. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +10 -12
  144. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +13 -18
  145. data/ext/couchbase/protocol/cmd_get_collection_id.hxx +12 -15
  146. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +12 -16
  147. data/ext/couchbase/protocol/cmd_get_error_map.hxx +14 -17
  148. data/ext/couchbase/protocol/cmd_hello.hxx +8 -10
  149. data/ext/couchbase/protocol/cmd_increment.hxx +9 -10
  150. data/ext/couchbase/protocol/cmd_insert.hxx +9 -9
  151. data/ext/couchbase/protocol/cmd_lookup_in.hxx +12 -13
  152. data/ext/couchbase/protocol/cmd_mutate_in.hxx +11 -11
  153. data/ext/couchbase/protocol/cmd_noop.hxx +16 -20
  154. data/ext/couchbase/protocol/cmd_prepend.hxx +9 -10
  155. data/ext/couchbase/protocol/cmd_remove.hxx +10 -13
  156. data/ext/couchbase/protocol/cmd_replace.hxx +7 -7
  157. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +8 -10
  158. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +10 -15
  159. data/ext/couchbase/protocol/cmd_sasl_step.hxx +10 -12
  160. data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -18
  161. data/ext/couchbase/protocol/cmd_touch.hxx +8 -11
  162. data/ext/couchbase/protocol/cmd_unlock.hxx +10 -14
  163. data/ext/couchbase/protocol/cmd_upsert.hxx +8 -8
  164. data/ext/couchbase/protocol/datatype.hxx +3 -3
  165. data/ext/couchbase/protocol/durability_level.hxx +2 -2
  166. data/ext/couchbase/protocol/frame_info_id.hxx +4 -4
  167. data/ext/couchbase/protocol/hello_feature.hxx +2 -2
  168. data/ext/couchbase/protocol/magic.hxx +2 -2
  169. data/ext/couchbase/protocol/server_opcode.hxx +2 -2
  170. data/ext/couchbase/protocol/server_request.hxx +1 -1
  171. data/ext/couchbase/protocol/status.hxx +4 -7
  172. data/ext/couchbase/protocol/unsigned_leb128.h +5 -20
  173. data/ext/couchbase/service_type.hxx +4 -4
  174. data/ext/couchbase/tracing/constants.hxx +261 -0
  175. data/ext/couchbase/tracing/noop_tracer.hxx +50 -0
  176. data/ext/couchbase/tracing/request_tracer.hxx +77 -0
  177. data/ext/couchbase/tracing/threshold_logging_options.hxx +64 -0
  178. data/ext/couchbase/tracing/threshold_logging_tracer.hxx +366 -0
  179. data/ext/couchbase/utils/byteswap.hxx +1 -1
  180. data/ext/couchbase/utils/connection_string.hxx +21 -1
  181. data/ext/couchbase/utils/name_codec.hxx +41 -0
  182. data/ext/couchbase/utils/url_codec.hxx +236 -0
  183. data/ext/couchbase/version.hxx +1 -1
  184. data/ext/test/CMakeLists.txt +1 -0
  185. data/ext/test/test_native_trivial_query.cxx +60 -0
  186. data/ext/third_party/hdr_histogram_c/CMakeLists.txt +84 -0
  187. data/ext/third_party/hdr_histogram_c/COPYING.txt +121 -0
  188. data/ext/third_party/hdr_histogram_c/LICENSE.txt +41 -0
  189. data/ext/third_party/hdr_histogram_c/config.cmake.in +6 -0
  190. data/ext/third_party/hdr_histogram_c/src/CMakeLists.txt +83 -0
  191. data/ext/third_party/hdr_histogram_c/src/hdr_atomic.h +146 -0
  192. data/ext/third_party/hdr_histogram_c/src/hdr_encoding.c +322 -0
  193. data/ext/third_party/hdr_histogram_c/src/hdr_encoding.h +79 -0
  194. data/ext/third_party/hdr_histogram_c/src/hdr_endian.h +116 -0
  195. data/ext/third_party/hdr_histogram_c/src/hdr_histogram.c +1196 -0
  196. data/ext/third_party/hdr_histogram_c/src/hdr_histogram.h +516 -0
  197. data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.c +1290 -0
  198. data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log.h +236 -0
  199. data/ext/third_party/hdr_histogram_c/src/hdr_histogram_log_no_op.c +171 -0
  200. data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.c +227 -0
  201. data/ext/third_party/hdr_histogram_c/src/hdr_interval_recorder.h +109 -0
  202. data/ext/third_party/hdr_histogram_c/src/hdr_malloc.h +19 -0
  203. data/ext/third_party/hdr_histogram_c/src/hdr_tests.h +22 -0
  204. data/ext/third_party/hdr_histogram_c/src/hdr_thread.c +108 -0
  205. data/ext/third_party/hdr_histogram_c/src/hdr_thread.h +55 -0
  206. data/ext/third_party/hdr_histogram_c/src/hdr_time.c +98 -0
  207. data/ext/third_party/hdr_histogram_c/src/hdr_time.h +49 -0
  208. data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.c +143 -0
  209. data/ext/third_party/hdr_histogram_c/src/hdr_writer_reader_phaser.h +51 -0
  210. data/lib/couchbase/cluster.rb +1 -0
  211. data/lib/couchbase/errors.rb +3 -0
  212. data/lib/couchbase/libcouchbase.bundle +0 -0
  213. data/lib/couchbase/management/analytics_index_manager.rb +920 -226
  214. data/lib/couchbase/management/bucket_manager.rb +207 -69
  215. data/lib/couchbase/management/collection_manager.rb +173 -61
  216. data/lib/couchbase/management/query_index_manager.rb +357 -169
  217. data/lib/couchbase/options.rb +75 -3
  218. data/lib/couchbase/scope.rb +102 -0
  219. data/lib/couchbase/utils/time.rb +4 -0
  220. data/lib/couchbase/version.rb +6 -6
  221. metadata +48 -5
@@ -0,0 +1,109 @@
1
+ /**
2
+ * hdr_interval_recorder.h
3
+ * Written by Michael Barker and released to the public domain,
4
+ * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5
+ */
6
+
7
+ #ifndef HDR_INTERVAL_RECORDER_H
8
+ #define HDR_INTERVAL_RECORDER_H 1
9
+
10
+ #include "hdr_writer_reader_phaser.h"
11
+ #include "hdr_histogram.h"
12
+
13
+ HDR_ALIGN_PREFIX(8)
14
+ struct hdr_interval_recorder
15
+ {
16
+ struct hdr_histogram* active;
17
+ struct hdr_histogram* inactive;
18
+ struct hdr_writer_reader_phaser phaser;
19
+ }
20
+ HDR_ALIGN_SUFFIX(8);
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ int hdr_interval_recorder_init(struct hdr_interval_recorder* r);
27
+
28
+ int hdr_interval_recorder_init_all(
29
+ struct hdr_interval_recorder* r,
30
+ int64_t lowest_trackable_value,
31
+ int64_t highest_trackable_value,
32
+ int significant_figures);
33
+
34
+ void hdr_interval_recorder_destroy(struct hdr_interval_recorder* r);
35
+
36
+ int64_t hdr_interval_recorder_record_value(
37
+ struct hdr_interval_recorder* r,
38
+ int64_t value
39
+ );
40
+
41
+ int64_t hdr_interval_recorder_record_values(
42
+ struct hdr_interval_recorder* r,
43
+ int64_t value,
44
+ int64_t count
45
+ );
46
+
47
+ int64_t hdr_interval_recorder_record_corrected_value(
48
+ struct hdr_interval_recorder* r,
49
+ int64_t value,
50
+ int64_t expected_interval
51
+ );
52
+
53
+ int64_t hdr_interval_recorder_record_corrected_values(
54
+ struct hdr_interval_recorder* r,
55
+ int64_t value,
56
+ int64_t count,
57
+ int64_t expected_interval
58
+ );
59
+
60
+ int64_t hdr_interval_recorder_record_value_atomic(
61
+ struct hdr_interval_recorder* r,
62
+ int64_t value
63
+ );
64
+
65
+ int64_t hdr_interval_recorder_record_values_atomic(
66
+ struct hdr_interval_recorder* r,
67
+ int64_t value,
68
+ int64_t count
69
+ );
70
+
71
+ int64_t hdr_interval_recorder_record_corrected_value_atomic(
72
+ struct hdr_interval_recorder* r,
73
+ int64_t value,
74
+ int64_t expected_interval
75
+ );
76
+
77
+ int64_t hdr_interval_recorder_record_corrected_values_atomic(
78
+ struct hdr_interval_recorder* r,
79
+ int64_t value,
80
+ int64_t count,
81
+ int64_t expected_interval
82
+ );
83
+
84
+ /**
85
+ * The is generally the preferred approach for recylcing histograms through
86
+ * the recorder as it is safe when used from callers in multiple threads and
87
+ * the returned histogram won't automatically become active without being
88
+ * passed back into this method.
89
+ *
90
+ * @param r 'this' recorder
91
+ * @param histogram_to_recycle
92
+ * @return the histogram that was previous being recorded to.
93
+ */
94
+ struct hdr_histogram* hdr_interval_recorder_sample_and_recycle(
95
+ struct hdr_interval_recorder* r,
96
+ struct hdr_histogram* histogram_to_recycle);
97
+
98
+ /**
99
+ * @deprecated Prefer hdr_interval_recorder_sample_and_recycle
100
+ * @param r 'this' recorder
101
+ * @return the histogram that was previous being recorded to.
102
+ */
103
+ struct hdr_histogram* hdr_interval_recorder_sample(struct hdr_interval_recorder* r);
104
+
105
+ #ifdef __cplusplus
106
+ }
107
+ #endif
108
+
109
+ #endif
@@ -0,0 +1,19 @@
1
+ /**
2
+ * hdr_malloc.h
3
+ * Written by Filipe Oliveira and released to the public domain,
4
+ * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5
+ *
6
+ * Allocator selection.
7
+ *
8
+ * This file is used in order to change the HdrHistogram allocator at compile time.
9
+ * Just define the following defines to what you want to use. Also add
10
+ * the include of your alternate allocator if needed (not needed in order
11
+ * to use the default libc allocator). */
12
+
13
+ #ifndef HDR_MALLOC_H__
14
+ #define HDR_MALLOC_H__
15
+ #define hdr_malloc malloc
16
+ #define hdr_calloc calloc
17
+ #define hdr_realloc realloc
18
+ #define hdr_free free
19
+ #endif
@@ -0,0 +1,22 @@
1
+ #ifndef HDR_TESTS_H
2
+ #define HDR_TESTS_H
3
+
4
+ /* These are functions used in tests and are not intended for normal usage. */
5
+
6
+ #include "hdr_histogram.h"
7
+
8
+ #ifdef __cplusplus
9
+ extern "C" {
10
+ #endif
11
+
12
+ int32_t counts_index_for(const struct hdr_histogram* h, int64_t value);
13
+ int hdr_encode_compressed(struct hdr_histogram* h, uint8_t** compressed_histogram, size_t* compressed_len);
14
+ int hdr_decode_compressed(uint8_t* buffer, size_t length, struct hdr_histogram** histogram);
15
+ void hdr_base64_decode_block(const char* input, uint8_t* output);
16
+ void hdr_base64_encode_block(const uint8_t* input, char* output);
17
+
18
+ #ifdef __cplusplus
19
+ }
20
+ #endif
21
+
22
+ #endif
@@ -0,0 +1,108 @@
1
+ /**
2
+ * hdr_thread.c
3
+ * Written by Philip Orwig and released to the public domain,
4
+ * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5
+ */
6
+
7
+ #include <stdlib.h>
8
+ #include "hdr_thread.h"
9
+
10
+ #ifndef HDR_MALLOC_INCLUDE
11
+ #define HDR_MALLOC_INCLUDE "hdr_malloc.h"
12
+ #endif
13
+
14
+ #include HDR_MALLOC_INCLUDE
15
+
16
+ struct hdr_mutex* hdr_mutex_alloc(void)
17
+ {
18
+ return hdr_malloc(sizeof(hdr_mutex));
19
+ }
20
+
21
+ void hdr_mutex_free(struct hdr_mutex* mutex)
22
+ {
23
+ hdr_free(mutex);
24
+ }
25
+
26
+ #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
27
+
28
+ #if !defined(WIN32_LEAN_AND_MEAN)
29
+ #define WIN32_LEAN_AND_MEAN
30
+ #endif
31
+
32
+ #include <windows.h>
33
+ #include <WinSock2.h>
34
+
35
+ int hdr_mutex_init(struct hdr_mutex* mutex)
36
+ {
37
+ InitializeCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
38
+ return 0;
39
+ }
40
+
41
+ void hdr_mutex_destroy(struct hdr_mutex* mutex)
42
+ {
43
+ DeleteCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
44
+ }
45
+
46
+ void hdr_mutex_lock(struct hdr_mutex* mutex)
47
+ {
48
+ EnterCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
49
+ }
50
+
51
+ void hdr_mutex_unlock(struct hdr_mutex* mutex)
52
+ {
53
+ LeaveCriticalSection((CRITICAL_SECTION*)(mutex->_critical_section));
54
+ }
55
+
56
+ void hdr_yield()
57
+ {
58
+ Sleep(0);
59
+ }
60
+
61
+ int hdr_usleep(unsigned int useconds)
62
+ {
63
+ struct timeval tv;
64
+
65
+ tv.tv_sec = (long)useconds / 1000000;
66
+ tv.tv_usec = useconds % 1000000;
67
+ select(0, NULL, NULL, NULL, &tv);
68
+
69
+ return 0;
70
+ }
71
+
72
+
73
+ #else
74
+ #include <pthread.h>
75
+ #include <unistd.h>
76
+
77
+ int hdr_mutex_init(struct hdr_mutex* mutex)
78
+ {
79
+ return pthread_mutex_init(&mutex->_mutex, NULL);
80
+ }
81
+
82
+ void hdr_mutex_destroy(struct hdr_mutex* mutex)
83
+ {
84
+ pthread_mutex_destroy(&mutex->_mutex);
85
+ }
86
+
87
+ void hdr_mutex_lock(struct hdr_mutex* mutex)
88
+ {
89
+ pthread_mutex_lock(&mutex->_mutex);
90
+ }
91
+
92
+ void hdr_mutex_unlock(struct hdr_mutex* mutex)
93
+ {
94
+ pthread_mutex_unlock(&mutex->_mutex);
95
+ }
96
+
97
+ void hdr_yield()
98
+ {
99
+ sched_yield();
100
+ }
101
+
102
+ int hdr_usleep(unsigned int useconds)
103
+ {
104
+ return usleep(useconds);
105
+ }
106
+
107
+
108
+ #endif
@@ -0,0 +1,55 @@
1
+ /**
2
+ * hdr_thread.h
3
+ * Written by Philip Orwig and released to the public domain,
4
+ * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5
+ */
6
+
7
+ #ifndef HDR_THREAD_H__
8
+ #define HDR_THREAD_H__
9
+
10
+ #include <stdint.h>
11
+
12
+ #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
13
+
14
+
15
+ #define HDR_ALIGN_PREFIX(alignment) __declspec( align(alignment) )
16
+ #define HDR_ALIGN_SUFFIX(alignment)
17
+
18
+ typedef struct hdr_mutex
19
+ {
20
+ uint8_t _critical_section[40];
21
+ } hdr_mutex;
22
+
23
+ #else
24
+
25
+ #include <pthread.h>
26
+
27
+ #define HDR_ALIGN_PREFIX(alignment)
28
+ #define HDR_ALIGN_SUFFIX(alignment) __attribute__((aligned(alignment)))
29
+
30
+ typedef struct hdr_mutex
31
+ {
32
+ pthread_mutex_t _mutex;
33
+ } hdr_mutex;
34
+ #endif
35
+
36
+ #ifdef __cplusplus
37
+ extern "C" {
38
+ #endif
39
+
40
+ struct hdr_mutex* hdr_mutex_alloc(void);
41
+ void hdr_mutex_free(struct hdr_mutex*);
42
+
43
+ int hdr_mutex_init(struct hdr_mutex* mutex);
44
+ void hdr_mutex_destroy(struct hdr_mutex* mutex);
45
+
46
+ void hdr_mutex_lock(struct hdr_mutex* mutex);
47
+ void hdr_mutex_unlock(struct hdr_mutex* mutex);
48
+
49
+ void hdr_yield(void);
50
+ int hdr_usleep(unsigned int useconds);
51
+
52
+ #ifdef __cplusplus
53
+ }
54
+ #endif
55
+ #endif
@@ -0,0 +1,98 @@
1
+ /**
2
+ * hdr_time.h
3
+ * Written by Michael Barker and Philip Orwig and released to the public domain,
4
+ * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5
+ */
6
+
7
+ #include "hdr_time.h"
8
+
9
+ #if defined(_WIN32) || defined(_WIN64)
10
+
11
+ #if !defined(WIN32_LEAN_AND_MEAN)
12
+ #define WIN32_LEAN_AND_MEAN
13
+ #endif
14
+
15
+ #include <windows.h>
16
+
17
+ static int s_clockPeriodSet = 0;
18
+ static double s_clockPeriod = 1.0;
19
+
20
+ void hdr_gettime(hdr_timespec* t)
21
+ {
22
+ LARGE_INTEGER num;
23
+ /* if this is distasteful, we can add in an hdr_time_init() */
24
+ if (!s_clockPeriodSet)
25
+ {
26
+ QueryPerformanceFrequency(&num);
27
+ s_clockPeriod = 1.0 / (double) num.QuadPart;
28
+ s_clockPeriodSet = 1;
29
+ }
30
+
31
+ QueryPerformanceCounter(&num);
32
+ double seconds = num.QuadPart * s_clockPeriod;
33
+ double integral;
34
+ double remainder = modf(seconds, &integral);
35
+
36
+ t->tv_sec = (long) integral;
37
+ t->tv_nsec = (long) (remainder * 1000000000);
38
+ }
39
+
40
+ #elif defined(__APPLE__)
41
+
42
+ #include <mach/clock.h>
43
+ #include <mach/mach.h>
44
+
45
+
46
+ void hdr_gettime(hdr_timespec* ts)
47
+ {
48
+ clock_serv_t cclock;
49
+ mach_timespec_t mts;
50
+ host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
51
+ clock_get_time(cclock, &mts);
52
+ mach_port_deallocate(mach_task_self(), cclock);
53
+ ts->tv_sec = mts.tv_sec;
54
+ ts->tv_nsec = mts.tv_nsec;
55
+ }
56
+
57
+
58
+ void hdr_getnow(hdr_timespec* ts)
59
+ {
60
+ hdr_gettime(ts);
61
+ }
62
+
63
+ #elif defined(__linux__) || defined(__CYGWIN__) || defined(__OpenBSD__)
64
+
65
+
66
+ void hdr_gettime(hdr_timespec* t)
67
+ {
68
+ clock_gettime(CLOCK_MONOTONIC, (struct timespec*)t);
69
+ }
70
+
71
+ void hdr_getnow(hdr_timespec* t)
72
+ {
73
+ clock_gettime(CLOCK_REALTIME, (struct timespec*)t);
74
+ }
75
+
76
+ #else
77
+
78
+ #warning "Platform not supported\n"
79
+
80
+ #endif
81
+
82
+ double hdr_timespec_as_double(const hdr_timespec* t)
83
+ {
84
+ double d = t->tv_sec;
85
+ return d + (t->tv_nsec / 1000000000.0);
86
+ }
87
+
88
+ void hdr_timespec_from_double(hdr_timespec* t, double value)
89
+ {
90
+ int seconds = (int) value;
91
+ int milliseconds = (int) round((value - seconds) * 1000);
92
+
93
+ t->tv_sec = seconds;
94
+ t->tv_nsec = milliseconds * 1000000;
95
+ }
96
+
97
+
98
+
@@ -0,0 +1,49 @@
1
+ /**
2
+ * hdr_time.h
3
+ * Written by Michael Barker and released to the public domain,
4
+ * as explained at http://creativecommons.org/publicdomain/zero/1.0/
5
+ */
6
+
7
+ #ifndef HDR_TIME_H__
8
+ #define HDR_TIME_H__
9
+
10
+ #include <math.h>
11
+ #include <time.h>
12
+
13
+ #if defined(_WIN32) || defined(_WIN64) || defined(__CYGWIN__)
14
+
15
+ typedef struct hdr_timespec
16
+ {
17
+ long tv_sec;
18
+ long tv_nsec;
19
+ } hdr_timespec;
20
+
21
+ #else
22
+
23
+ typedef struct timespec hdr_timespec;
24
+
25
+ #endif
26
+
27
+ #ifdef __cplusplus
28
+ extern "C" {
29
+ #endif
30
+
31
+ #if defined(_MSC_VER)
32
+ void hdr_gettime(hdr_timespec* t);
33
+ #else
34
+ void hdr_gettime(hdr_timespec* t);
35
+ #endif
36
+
37
+ void hdr_getnow(hdr_timespec* t);
38
+
39
+ double hdr_timespec_as_double(const hdr_timespec* t);
40
+
41
+ /* Assumes only millisecond accuracy. */
42
+ void hdr_timespec_from_double(hdr_timespec* t, double value);
43
+
44
+ #ifdef __cplusplus
45
+ }
46
+ #endif
47
+
48
+ #endif
49
+