Skip to content

Commit ce07468

Browse files
author
Christian Hergert
committed
counters: fix build, cleanup atexit.
The atexit stuff should probably go into mongoc_cleanup().
1 parent b2644d1 commit ce07468

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/mongoc/mongoc-counters.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ typedef struct
6464

6565
BSON_STATIC_ASSERT(sizeof(mongoc_counters_t) == 64);
6666

67+
static void *gCounterFallback = NULL;
68+
6769

6870
#define COUNTER(ident, Category, Name, Description) \
6971
mongoc_counter_t __mongoc_counter_##ident;
@@ -122,25 +124,23 @@ mongoc_counters_calc_size (void)
122124
*
123125
* Removes the shared memory segment for the current processes counters.
124126
*/
125-
#ifdef BSON_OS_UNIX
126127
static void
127128
mongoc_counters_destroy (void)
128129
{
129-
char name [32];
130-
int pid;
131-
132-
pid = getpid ();
133-
bson_snprintf (name, sizeof name, "/mongoc-%u", pid);
134-
shm_unlink (name);
135-
}
136-
#else
137-
static void * mongoc_counters_memory = NULL;
138-
static void
139-
mongoc_counters_destroy (void)
140-
{
141-
bson_free(mongoc_counters_memory);
142-
}
130+
if (gCounterFallback) {
131+
bson_free (gCounterFallback);
132+
gCounterFallback = NULL;
133+
#ifndef _WIN32
134+
} else {
135+
char name [32];
136+
int pid;
137+
138+
pid = getpid ();
139+
bson_snprintf (name, sizeof name, "/mongoc-%u", pid);
140+
shm_unlink (name);
143141
#endif
142+
}
143+
}
144144

145145

146146
/**
@@ -200,9 +200,10 @@ mongoc_counters_alloc (size_t size)
200200
use_malloc:
201201
#endif
202202

203-
mongoc_counters_memory = bson_malloc0(size);
203+
gCounterFallback = bson_malloc0(size);
204204
atexit(mongoc_counters_destroy);
205-
return mongoc_counters_memory;
205+
206+
return gCounterFallback;
206207
}
207208

208209

0 commit comments

Comments
 (0)