Skip to content

Commit 4a317cc

Browse files
Fix Win32 Warnings (#892)
* Use a fixed-width type for the 64bit atomic emulation spinlock * Fix return-type warnings in thread functions * Incompatible pointer type for create_server_stream in cluster sspi Fixes CDRIVER-4221
1 parent ded9ae5 commit 4a317cc

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

src/common/common-thread-private.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ typedef struct {
107107
#define BSON_THREAD_FUN(_function_name, _arg_name) \
108108
unsigned(__stdcall _function_name) (void *(_arg_name))
109109
#define BSON_THREAD_FUN_TYPE(_function_name) \
110-
unsigned(__stdcall * _function_name) (void *)
111-
#define BSON_THREAD_RETURN return
110+
unsigned (__stdcall * _function_name) (void *)
111+
#define BSON_THREAD_RETURN return 0
112112
#endif
113113

114114
/* Functions that require definitions get the common prefix (_mongoc for

src/libbson/src/bson/bson-atomic.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ bson_memory_barrier (void)
5151
* 32-bit x86 does not support 64-bit atomic integer operations.
5252
* We emulate that here using a spin lock and regular arithmetic operations
5353
*/
54-
static int g64bitAtomicLock = 0;
54+
static int8_t g64bitAtomicLock = 0;
5555

5656
static void
5757
_lock_64bit_atomic ()
5858
{
5959
int i;
60-
if (bson_atomic_int_compare_exchange_weak (
60+
if (bson_atomic_int8_compare_exchange_weak (
6161
&g64bitAtomicLock, 0, 1, bson_memory_order_acquire) == 0) {
6262
/* Successfully took the spinlock */
6363
return;
6464
}
6565
/* Failed. Try taking ten more times, then begin sleeping. */
6666
for (i = 0; i < 10; ++i) {
67-
if (bson_atomic_int_compare_exchange_weak (
67+
if (bson_atomic_int8_compare_exchange_weak (
6868
&g64bitAtomicLock, 0, 1, bson_memory_order_acquire) == 0) {
6969
/* Succeeded in taking the lock */
7070
return;
7171
}
7272
}
7373
/* Still don't have the lock. Spin and yield */
74-
while (bson_atomic_int_compare_exchange_weak (
74+
while (bson_atomic_int8_compare_exchange_weak (
7575
&g64bitAtomicLock, 0, 1, bson_memory_order_acquire) != 0) {
7676
bson_thrd_yield ();
7777
}
@@ -80,7 +80,7 @@ _lock_64bit_atomic ()
8080
static void
8181
_unlock_64bit_atomic ()
8282
{
83-
int64_t rv = bson_atomic_int_exchange (
83+
int64_t rv = bson_atomic_int8_exchange (
8484
&g64bitAtomicLock, 0, bson_memory_order_release);
8585
BSON_ASSERT (rv == 1 && "Released atomic lock while not holding it");
8686
}

src/libmongoc/src/mongoc/mongoc-cluster-sspi.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ _mongoc_cluster_auth_node_sspi (mongoc_cluster_t *cluster,
161161
int step;
162162
mongoc_server_stream_t *server_stream;
163163
bool ret = false;
164+
mc_shared_tpld td = MC_SHARED_TPLD_NULL;
164165

165166
state = _mongoc_cluster_sspi_new (cluster->uri, stream, sd->host.host);
166167

@@ -222,8 +223,8 @@ _mongoc_cluster_auth_node_sspi (mongoc_cluster_t *cluster,
222223
}
223224
}
224225

225-
server_stream = _mongoc_cluster_create_server_stream (
226-
cluster->client->topology, sd, stream);
226+
mc_tpld_renew_ref (&td, cluster->client->topology);
227+
server_stream = _mongoc_cluster_create_server_stream (td.ptr, sd, stream);
227228

228229
if (!mongoc_cmd_parts_assemble (&parts, server_stream, error)) {
229230
mongoc_server_stream_cleanup (server_stream);
@@ -275,6 +276,7 @@ _mongoc_cluster_auth_node_sspi (mongoc_cluster_t *cluster,
275276

276277
ret = true;
277278
failure:
279+
mc_tpld_drop_ref (&td);
278280
bson_free (buf);
279281
bson_free (state);
280282
return ret;

src/libmongoc/src/mongoc/mongoc-shared.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ static bson_once_t g_shared_ptr_mtx_init_once = BSON_ONCE_INIT;
3838
static BSON_ONCE_FUN (_init_mtx)
3939
{
4040
bson_mutex_init (&g_shared_ptr_mtx);
41+
BSON_ONCE_RETURN;
4142
}
4243

4344
static void

0 commit comments

Comments
 (0)