1 /**
2  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
3  * use this file except in compliance with the License. You may obtain a copy of
4  * the License at
5  *
6  *   http://www.apache.org/licenses/LICENSE-2.0
7  *
8  * Unless required by applicable law or agreed to in writing, software
9  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11  * License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 #include "couch_ejson_compare.h"
16 
17 #ifdef WIN32
18 #define INLINE_MODIFIER
19 #else
20 #define INLINE_MODIFIER __inline
21 #endif
22 
23 #include <platform/cbassert.h>
24 
reserve_coll(couch_ejson_ctx_t *ctx)25 INLINE_MODIFIER void reserve_coll(couch_ejson_ctx_t *ctx)
26 {
27     if (ctx->coll == NULL) {
28         enif_mutex_lock(ctx->globalCtx->collMutex);
29         cb_assert(ctx->globalCtx->collStackTop < ctx->globalCtx->numCollators);
30         ctx->coll = ctx->globalCtx->collators[ctx->globalCtx->collStackTop];
31         ctx->globalCtx->collStackTop += 1;
32         enif_mutex_unlock(ctx->globalCtx->collMutex);
33     }
34 }
35 
release_coll(couch_ejson_ctx_t *ctx)36 INLINE_MODIFIER void release_coll(couch_ejson_ctx_t *ctx)
37 {
38     if (ctx->coll != NULL) {
39         enif_mutex_lock(ctx->globalCtx->collMutex);
40         ctx->globalCtx->collStackTop -= 1;
41         cb_assert(ctx->globalCtx->collStackTop >= 0);
42         enif_mutex_unlock(ctx->globalCtx->collMutex);
43     }
44 }
45 
46