Skip to content
This repository was archived by the owner on Dec 6, 2024. It is now read-only.

Commit cc5e47f

Browse files
prepare 2.2.0 release (#25)
1 parent df6def5 commit cc5e47f

24 files changed

+254
-48
lines changed

.circleci/config.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ jobs:
2828
cmake -D REDIS_STORE=ON ..
2929
cmake --build .
3030
- run:
31-
name: Test
31+
name: Unit test with memcheck
3232
command: |
3333
cd build
34-
CTEST_OUTPUT_ON_FAILURE=1 make test
34+
ctest -T memcheck
3535
3636
build-test-linux-32bit:
3737
docker:
@@ -61,11 +61,11 @@ jobs:
6161
name: Test
6262
command: |
6363
cd build
64-
CTEST_OUTPUT_ON_FAILURE=1 make test
64+
make test
6565
6666
build-test-osx:
6767
macos:
68-
xcode: "9.0"
68+
xcode: "9.4.1"
6969
environment:
7070
CTEST_OUTPUT_ON_FAILURE: 1
7171
steps:
@@ -90,7 +90,7 @@ jobs:
9090
name: Test
9191
command: |
9292
cd build
93-
CTEST_OUTPUT_ON_FAILURE=1 make test
93+
make test
9494
9595
build-test-windows:
9696
executor:

.ldrelease/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ circleci:
88
env:
99
LD_LIBRARY_FILE_PREFIX: linux-gcc-64bit
1010
mac:
11-
xcode: "9.0"
11+
xcode: "9.4.1"
1212
env:
1313
LD_LIBRARY_FILE_PREFIX: osx-clang-64bit
1414
windows:

c-sdk-common/include/launchdarkly/logging.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,33 @@ typedef enum {
2121
/** @brief Internal: Used for the non macro portion */
2222
LD_EXPORT(void) LDi_log(const LDLogLevel level, const char *const format, ...);
2323

24-
/** @brief A provided logger that can be used as a convenient default */
24+
/**
25+
* @brief A provided logger that can be used as a convenient default.
26+
* @deprecated This is deprecated in favor of `LDBasicLoggerThreadSafe`.
27+
*/
2528
LD_EXPORT(void) LDBasicLogger(const LDLogLevel level, const char *const text);
2629

30+
/**
31+
* @brief Setup routine for `LDBasicLoggerThreadSafe`.
32+
* Call this before `LDBasicLoggerThreadSafe` is used.
33+
*/
34+
LD_EXPORT(void) LDBasicLoggerThreadSafeInitialize(void);
35+
36+
/**
37+
* @brief A provided logger that can be used as a convenient default.
38+
* Must call `LDBasicLoggerTSInitialize` before use. This should be used instead
39+
* of `LDBasicLogger`.
40+
*/
41+
LD_EXPORT(void) LDBasicLoggerThreadSafe(
42+
const LDLogLevel level, const char *const text);
43+
44+
/**
45+
* @brief Shutdown routine for `LDBasicLoggerThreadSafe`
46+
* Call this when `LDBasicLoggerThreadSafe` is no longer used, after all
47+
* LaunchDarkly resources are destroyed.
48+
*/
49+
LD_EXPORT(void) LDBasicLoggerThreadSafeShutdown(void);
50+
2751
/**
2852
* @brief Set the logger, and the log level to use. This routine should only be
2953
* used before any other LD routine. After any other routine has been used

c-sdk-common/src/concurrency.c

Lines changed: 115 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,49 @@ LDi_mutex_init_imp(ld_mutex_t *const mutex)
147147
return status == 0;
148148
}
149149

150+
static bool
151+
LDi_mutex_init_nl_imp(ld_mutex_t *const mutex)
152+
{
153+
int status;
154+
155+
#ifndef _WIN32
156+
pthread_mutexattr_t attributes;
157+
int kind;
158+
#endif
159+
160+
#ifdef _WIN32
161+
InitializeCriticalSection(mutex);
162+
163+
status = 0;
164+
#else
165+
if ((status = pthread_mutexattr_init(&attributes)) != 0) {
166+
goto done;
167+
}
168+
169+
#ifdef LAUNCHDARKLY_CONCURRENCY_UNSAFE
170+
kind = PTHREAD_MUTEX_NORMAL;
171+
#else
172+
kind = PTHREAD_MUTEX_ERRORCHECK;
173+
#endif
174+
175+
if ((status = pthread_mutexattr_settype(&attributes, kind)) != 0) {
176+
goto done;
177+
}
178+
179+
if ((status = pthread_mutex_init(mutex, &attributes)) != 0) {
180+
goto done;
181+
}
182+
183+
/* this should never fail */
184+
if ((status = pthread_mutexattr_destroy(&attributes)) != 0) {
185+
goto done;
186+
}
187+
#endif
188+
189+
done:
190+
return status == 0;
191+
}
192+
150193
static bool
151194
LDi_mutex_destroy_imp(ld_mutex_t *const mutex)
152195
{
@@ -180,6 +223,22 @@ LDi_mutex_destroy_imp(ld_mutex_t *const mutex)
180223
return status == 0;
181224
}
182225

226+
static bool
227+
LDi_mutex_destroy_nl_imp(ld_mutex_t *const mutex)
228+
{
229+
int status;
230+
231+
#ifdef _WIN32
232+
DeleteCriticalSection(mutex);
233+
234+
status = 0;
235+
#else
236+
status = pthread_mutex_destroy(mutex);
237+
#endif
238+
239+
return status == 0;
240+
}
241+
183242
static bool
184243
LDi_mutex_lock_imp(ld_mutex_t *const mutex)
185244
{
@@ -213,6 +272,22 @@ LDi_mutex_lock_imp(ld_mutex_t *const mutex)
213272
return status == 0;
214273
}
215274

275+
static bool
276+
LDi_mutex_lock_nl_imp(ld_mutex_t *const mutex)
277+
{
278+
int status;
279+
280+
#ifdef _WIN32
281+
EnterCriticalSection(mutex);
282+
283+
status = 0;
284+
#else
285+
status = pthread_mutex_lock(mutex);
286+
#endif
287+
288+
return status == 0;
289+
}
290+
216291
static bool
217292
LDi_mutex_unlock_imp(ld_mutex_t *const mutex)
218293
{
@@ -246,6 +321,22 @@ LDi_mutex_unlock_imp(ld_mutex_t *const mutex)
246321
return status == 0;
247322
}
248323

324+
static bool
325+
LDi_mutex_unlock_nl_imp(ld_mutex_t *const mutex)
326+
{
327+
int status;
328+
329+
#ifdef _WIN32
330+
LeaveCriticalSection(mutex);
331+
332+
status = 0;
333+
#else
334+
status = pthread_mutex_unlock(mutex);
335+
#endif
336+
337+
return status == 0;
338+
}
339+
249340
static bool
250341
LDi_rwlock_init_imp(ld_rwlock_t *const lock)
251342
{
@@ -631,22 +722,27 @@ LDi_cond_init_imp(ld_cond_t *const cond)
631722
return status == 0;
632723
}
633724

634-
ld_mutex_unary_t LDi_mutex_init = LDi_mutex_init_imp;
635-
ld_mutex_unary_t LDi_mutex_destroy = LDi_mutex_destroy_imp;
636-
ld_mutex_unary_t LDi_mutex_lock = LDi_mutex_lock_imp;
637-
ld_mutex_unary_t LDi_mutex_unlock = LDi_mutex_unlock_imp;
638-
639-
ld_thread_join_t LDi_thread_join = LDi_thread_join_imp;
640-
ld_thread_create_t LDi_thread_create = LDi_thread_create_imp;
641-
642-
ld_rwlock_unary_t LDi_rwlock_init = LDi_rwlock_init_imp;
643-
ld_rwlock_unary_t LDi_rwlock_destroy = LDi_rwlock_destroy_imp;
644-
ld_rwlock_unary_t LDi_rwlock_rdlock = LDi_rwlock_rdlock_imp;
645-
ld_rwlock_unary_t LDi_rwlock_wrlock = LDi_rwlock_wrlock_imp;
646-
ld_rwlock_unary_t LDi_rwlock_rdunlock = LDi_rwlock_rdunlock_imp;
647-
ld_rwlock_unary_t LDi_rwlock_wrunlock = LDi_rwlock_wrunlock_imp;
648-
649-
ld_cond_unary_t LDi_cond_init = LDi_cond_init_imp;
650-
ld_cond_wait_t LDi_cond_wait = LDi_cond_wait_imp;
651-
ld_cond_unary_t LDi_cond_signal = LDi_cond_signal_imp;
652-
ld_cond_unary_t LDi_cond_destroy = LDi_cond_destroy_imp;
725+
ld_mutex_unary_t LDi_mutex_init = LDi_mutex_init_imp;
726+
ld_mutex_unary_t LDi_mutex_destroy = LDi_mutex_destroy_imp;
727+
ld_mutex_unary_t LDi_mutex_lock = LDi_mutex_lock_imp;
728+
ld_mutex_unary_t LDi_mutex_unlock = LDi_mutex_unlock_imp;
729+
730+
ld_mutex_unary_t LDi_mutex_nl_init = LDi_mutex_init_nl_imp;
731+
ld_mutex_unary_t LDi_mutex_nl_destroy = LDi_mutex_destroy_nl_imp;
732+
ld_mutex_unary_t LDi_mutex_nl_lock = LDi_mutex_lock_nl_imp;
733+
ld_mutex_unary_t LDi_mutex_nl_unlock = LDi_mutex_unlock_nl_imp;
734+
735+
ld_thread_join_t LDi_thread_join = LDi_thread_join_imp;
736+
ld_thread_create_t LDi_thread_create = LDi_thread_create_imp;
737+
738+
ld_rwlock_unary_t LDi_rwlock_init = LDi_rwlock_init_imp;
739+
ld_rwlock_unary_t LDi_rwlock_destroy = LDi_rwlock_destroy_imp;
740+
ld_rwlock_unary_t LDi_rwlock_rdlock = LDi_rwlock_rdlock_imp;
741+
ld_rwlock_unary_t LDi_rwlock_wrlock = LDi_rwlock_wrlock_imp;
742+
ld_rwlock_unary_t LDi_rwlock_rdunlock = LDi_rwlock_rdunlock_imp;
743+
ld_rwlock_unary_t LDi_rwlock_wrunlock = LDi_rwlock_wrunlock_imp;
744+
745+
ld_cond_unary_t LDi_cond_init = LDi_cond_init_imp;
746+
ld_cond_wait_t LDi_cond_wait = LDi_cond_wait_imp;
747+
ld_cond_unary_t LDi_cond_signal = LDi_cond_signal_imp;
748+
ld_cond_unary_t LDi_cond_destroy = LDi_cond_destroy_imp;

c-sdk-common/src/concurrency.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ extern ld_mutex_unary_t LDi_mutex_destroy;
5757
extern ld_mutex_unary_t LDi_mutex_lock;
5858
extern ld_mutex_unary_t LDi_mutex_unlock;
5959

60+
extern ld_mutex_unary_t LDi_mutex_nl_init;
61+
extern ld_mutex_unary_t LDi_mutex_nl_destroy;
62+
extern ld_mutex_unary_t LDi_mutex_nl_lock;
63+
extern ld_mutex_unary_t LDi_mutex_nl_unlock;
64+
6065
extern ld_thread_join_t LDi_thread_join;
6166
extern ld_thread_create_t LDi_thread_create;
6267

c-sdk-common/src/logging.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
#include <launchdarkly/logging.h>
55

66
#include "assertion.h"
7+
#include "concurrency.h"
78

89
static LDLogLevel sdkloggerlevel = LD_LOG_INFO;
910
static void (*sdklogger)(const LDLogLevel level, const char *const text) = NULL;
11+
static ld_mutex_t basicLoggerLock;
1012

1113
const char *
1214
LDLogLevelToString(const LDLogLevel level)
@@ -30,6 +32,30 @@ LDBasicLogger(const LDLogLevel level, const char *const text)
3032
printf("[%s] %s\n", LDLogLevelToString(level), text);
3133
}
3234

35+
void
36+
LDBasicLoggerThreadSafeInitialize(void)
37+
{
38+
LDi_mutex_nl_init(&basicLoggerLock);
39+
}
40+
41+
void
42+
LDBasicLoggerThreadSafe(const LDLogLevel level, const char *const text)
43+
{
44+
if (!LDi_mutex_nl_lock(&basicLoggerLock)) {
45+
return;
46+
}
47+
48+
printf("[%s] %s\n", LDLogLevelToString(level), text);
49+
50+
LDi_mutex_nl_unlock(&basicLoggerLock);
51+
}
52+
53+
void
54+
LDBasicLoggerThreadSafeShutdown(void)
55+
{
56+
LDi_mutex_nl_destroy(&basicLoggerLock);
57+
}
58+
3359
void
3460
LDConfigureGlobalLogger(const LDLogLevel level,
3561
void (*logger)(const LDLogLevel level, const char *const text))
@@ -44,9 +70,7 @@ LDi_log(const LDLogLevel level, const char *const format, ...)
4470
char buffer[4096];
4571
va_list va;
4672

47-
LD_ASSERT(format);
48-
49-
if (!sdklogger || level > sdkloggerlevel) {
73+
if (!format || !sdklogger || level > sdkloggerlevel) {
5074
return;
5175
}
5276

src/store.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ LDJSONRCNew(struct LDJSON *const json)
226226
LDi_mutex_init(&result->lock);
227227

228228
result->value = json;
229+
230+
/* the locking here is only to satisfy helgrind */
231+
LDi_mutex_lock(&result->lock);
229232
result->count = 1;
233+
LDi_mutex_unlock(&result->lock);
230234

231235
return result;
232236
}

tests/test-allflags.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,13 @@ testAllFlags()
6060
int
6161
main()
6262
{
63-
LDConfigureGlobalLogger(LD_LOG_TRACE, LDBasicLogger);
63+
LDBasicLoggerThreadSafeInitialize();
64+
LDConfigureGlobalLogger(LD_LOG_TRACE, LDBasicLoggerThreadSafe);
6465
LDGlobalInit();
6566

6667
testAllFlags();
6768

69+
LDBasicLoggerThreadSafeShutdown();
70+
6871
return 0;
6972
}

tests/test-eval.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1016,7 +1016,8 @@ testLDi_bucketUserByKey()
10161016
int
10171017
main()
10181018
{
1019-
LDConfigureGlobalLogger(LD_LOG_TRACE, LDBasicLogger);
1019+
LDBasicLoggerThreadSafeInitialize();
1020+
LDConfigureGlobalLogger(LD_LOG_TRACE, LDBasicLoggerThreadSafe);
10201021
LDGlobalInit();
10211022

10221023
returnsOffVariationIfFlagIsOff();
@@ -1040,5 +1041,7 @@ main()
10401041

10411042
testLDi_bucketUserByKey();
10421043

1044+
LDBasicLoggerThreadSafeShutdown();
1045+
10431046
return 0;
10441047
}

tests/test-event-processor.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,8 @@ testExperimentationRuleNonDetailed()
484484
int
485485
main()
486486
{
487-
LDConfigureGlobalLogger(LD_LOG_TRACE, LDBasicLogger);
487+
LDBasicLoggerThreadSafeInitialize();
488+
LDConfigureGlobalLogger(LD_LOG_TRACE, LDBasicLoggerThreadSafe);
488489
LDGlobalInit();
489490

490491
testConstructAndFree();
@@ -498,5 +499,7 @@ main()
498499
testExperimentationFallthroughNonDetailed();
499500
testExperimentationRuleNonDetailed();
500501

502+
LDBasicLoggerThreadSafeShutdown();
503+
501504
return 0;
502505
};

0 commit comments

Comments
 (0)