@@ -143,10 +143,10 @@ static void register_callback(EngineIface* eh,
143143static void create_listen_sockets ();
144144
145145/* stats */
146- static void stats_init (void );
146+ static void stats_init ();
147147
148148/* defaults */
149- static void settings_init (void );
149+ static void settings_init ();
150150
151151/* * exported globals **/
152152struct stats stats;
@@ -170,9 +170,9 @@ static engine_event_handler_array_t engine_event_handlers;
170170 * terminated.
171171 */
172172char reset_stats_time[80 ];
173- static void set_stats_reset_time (void )
173+ static void set_stats_reset_time ()
174174{
175- time_t now = time (NULL );
175+ time_t now = time (nullptr );
176176#ifdef WIN32
177177 ctime_s (reset_stats_time, sizeof (reset_stats_time), &now);
178178#else
@@ -185,7 +185,7 @@ static void set_stats_reset_time(void)
185185}
186186
187187void disassociate_bucket (Connection& connection) {
188- Bucket& b = all_buckets. at ( connection.getBucketIndex () );
188+ Bucket& b = connection.getBucket ( );
189189 std::lock_guard<std::mutex> guard (b.mutex );
190190 b.clients --;
191191
@@ -362,8 +362,8 @@ static void register_callback(EngineIface* eh,
362362
363363static void free_callbacks () {
364364 // free per-bucket callbacks.
365- for (size_t idx = 0 ; idx < all_buckets. size (); ++idx ) {
366- for (auto & type_vec : all_buckets[idx] .engine_event_handlers ) {
365+ for (auto & bucket : all_buckets) {
366+ for (auto & type_vec : bucket .engine_event_handlers ) {
367367 type_vec.clear ();
368368 }
369369 }
@@ -374,7 +374,7 @@ static void free_callbacks() {
374374 }
375375}
376376
377- static void stats_init (void ) {
377+ static void stats_init () {
378378 set_stats_reset_time ();
379379 stats.conn_structs .reset ();
380380 stats.total_conns .reset ();
@@ -401,9 +401,14 @@ void stats_reset(Cookie& cookie) {
401401}
402402
403403static size_t get_number_of_worker_threads () {
404- size_t ret;
404+ size_t ret = 0 ;
405405 char *override = getenv (" MEMCACHED_NUM_CPUS" );
406- if (override == NULL ) {
406+ if (override ) {
407+ try {
408+ ret = std::stoull (override );
409+ } catch (...) {
410+ }
411+ } else {
407412 // No override specified; determine worker thread count based
408413 // on the CPU count:
409414 // <5 cores: create 4 workers.
@@ -416,12 +421,12 @@ static size_t get_number_of_worker_threads() {
416421 if (ret < 4 ) {
417422 ret = 4 ;
418423 }
419- } else {
420- ret = std::stoull (override );
421- if (ret == 0 ) {
422- ret = 4 ;
423- }
424424 }
425+
426+ if (ret == 0 ) {
427+ ret = 4 ;
428+ }
429+
425430 return ret;
426431}
427432
@@ -443,7 +448,7 @@ static void verbosity_changed_listener(const std::string&, Settings &s) {
443448 logger->set_level (settings.getLogLevel ());
444449 }
445450
446- perform_callbacks (ON_LOG_LEVEL, NULL , NULL );
451+ perform_callbacks (ON_LOG_LEVEL, nullptr , nullptr );
447452}
448453
449454static void scramsha_fallback_salt_changed_listener (const std::string&,
@@ -491,7 +496,7 @@ static std::string configure_numa_policy() {
491496 // Attempt to set the default NUMA memory policy to interleaved,
492497 // unless overridden by our env var.
493498 const char * mem_policy_env = getenv (" MEMCACHED_NUMA_MEM_POLICY" );
494- if (mem_policy_env != NULL && strcmp (" disable" , mem_policy_env) == 0 ) {
499+ if (mem_policy_env && strcmp (" disable" , mem_policy_env) == 0 ) {
495500 return std::string (" NOT setting memory allocation policy - disabled "
496501 " via MEMCACHED_NUMA_MEM_POLICY='" ) + mem_policy_env + " '" ;
497502 } else {
@@ -507,7 +512,7 @@ static std::string configure_numa_policy() {
507512}
508513#endif // HAVE_LIBNUMA
509514
510- static void settings_init (void ) {
515+ static void settings_init () {
511516 // Set up the listener functions
512517 settings.addChangeListener (" breakpad" ,
513518 breakpad_changed_listener);
@@ -553,7 +558,7 @@ static void settings_init(void) {
553558
554559 char *tmp = getenv (" MEMCACHED_TOP_KEYS" );
555560 settings.setTopkeysSize (20 );
556- if (tmp != NULL ) {
561+ if (tmp) {
557562 int count;
558563 if (safe_strtol (tmp, count)) {
559564 settings.setTopkeysSize (count);
@@ -594,12 +599,12 @@ static void settings_init(void) {
594599 * This is also the place to initialize any additional files needed by
595600 * Memcached.
596601 */
597- static void update_settings_from_config (void )
602+ static void update_settings_from_config ()
598603{
599604 std::string root (DESTINATION_ROOT);
600605
601606 if (!settings.getRoot ().empty ()) {
602- root = settings.getRoot (). c_str () ;
607+ root = settings.getRoot ();
603608 }
604609
605610 if (settings.getErrorMapsDir ().empty ()) {
@@ -623,17 +628,17 @@ static void update_settings_from_config(void)
623628
624629struct {
625630 std::mutex mutex;
626- bool disabled;
627- ssize_t count;
628- uint64_t num_disable;
631+ bool disabled = false ;
632+ ssize_t count = 0 ;
633+ uint64_t num_disable = 0 ;
629634} listen_state;
630635
631- bool is_listen_disabled (void ) {
636+ bool is_listen_disabled () {
632637 std::lock_guard<std::mutex> guard (listen_state.mutex );
633638 return listen_state.disabled ;
634639}
635640
636- uint64_t get_listen_disabled_num (void ) {
641+ uint64_t get_listen_disabled_num () {
637642 std::lock_guard<std::mutex> guard (listen_state.mutex );
638643 return listen_state.num_disable ;
639644}
@@ -798,7 +803,7 @@ void event_handler(evutil_socket_t fd, short which, void *arg) {
798803 * connecting to one of the server sockets. It runs in the context of the
799804 * listen thread
800805 */
801- void listen_event_handler (evutil_socket_t , short which , void *arg) {
806+ void listen_event_handler (evutil_socket_t , short , void *arg) {
802807 auto & c = *reinterpret_cast <ServerSocket*>(arg);
803808
804809 if (memcached_shutdown) {
@@ -1087,7 +1092,7 @@ static bool server_socket(const NetworkInterface& interf) {
10871092 union {
10881093 struct sockaddr_in in;
10891094 struct sockaddr_in6 in6;
1090- } my_sockaddr;
1095+ } my_sockaddr{} ;
10911096 socklen_t len = sizeof (my_sockaddr);
10921097 if (getsockname (sfd, (struct sockaddr *)&my_sockaddr, &len)==0 ) {
10931098 if (next->ai_addr ->sa_family == AF_INET) {
@@ -1235,13 +1240,13 @@ static struct event* sigterm_event;
12351240
12361241static bool install_signal_handlers () {
12371242 // SIGTERM - Used to shut down memcached cleanly
1238- sigterm_event = evsignal_new (main_base, SIGTERM, sigterm_handler, NULL );
1239- if (sigterm_event == NULL ) {
1243+ sigterm_event = evsignal_new (main_base, SIGTERM, sigterm_handler, nullptr );
1244+ if (! sigterm_event) {
12401245 LOG_WARNING (" Failed to allocate SIGTERM handler" );
12411246 return false ;
12421247 }
12431248
1244- if (event_add (sigterm_event, NULL ) < 0 ) {
1249+ if (event_add (sigterm_event, nullptr ) < 0 ) {
12451250 LOG_WARNING (" Failed to install SIGTERM handler" );
12461251 return false ;
12471252 }
@@ -1254,7 +1259,7 @@ static void release_signal_handlers() {
12541259}
12551260#endif
12561261
1257- const char * get_server_version (void ) {
1262+ const char * get_server_version () {
12581263 if (strlen (PRODUCT_VERSION) == 0 ) {
12591264 return " unknown" ;
12601265 } else {
@@ -1265,7 +1270,7 @@ const char* get_server_version(void) {
12651270static std::condition_variable shutdown_cv;
12661271static std::mutex shutdown_cv_mutex;
12671272static bool memcached_can_shutdown = false ;
1268- void shutdown_server (void ) {
1273+ void shutdown_server () {
12691274
12701275 std::unique_lock<std::mutex> lk (shutdown_cv_mutex);
12711276 if (!memcached_can_shutdown) {
@@ -1278,7 +1283,7 @@ void shutdown_server(void) {
12781283 event_base_loopbreak (main_base);
12791284}
12801285
1281- void enable_shutdown (void ) {
1286+ void enable_shutdown () {
12821287 std::unique_lock<std::mutex> lk (shutdown_cv_mutex);
12831288 memcached_can_shutdown = true ;
12841289 shutdown_cv.notify_all ();
@@ -1592,7 +1597,7 @@ struct ServerCookieApi : public ServerCookieIface {
15921597
15931598class ServerApi : public SERVER_HANDLE_V1 {
15941599public:
1595- ServerApi () {
1600+ ServerApi () : server_handle_v1_t () {
15961601 hooks_api.add_new_hook = AllocHooks::add_new_hook;
15971602 hooks_api.remove_new_hook = AllocHooks::remove_new_hook;
15981603 hooks_api.add_delete_hook = AllocHooks::add_delete_hook;
@@ -1618,7 +1623,7 @@ class ServerApi : public SERVER_HANDLE_V1 {
16181623 ServerCookieApi server_cookie_api;
16191624 ServerLogApi server_log_api;
16201625 ServerCallbackApi callback_api;
1621- ServerAllocatorIface hooks_api;
1626+ ServerAllocatorIface hooks_api{} ;
16221627 ServerDocumentApi document_api;
16231628};
16241629
@@ -1994,7 +1999,7 @@ void DestroyBucketThread::run() {
19941999 task->makeRunnable ();
19952000}
19962001
1997- static void initialize_buckets (void ) {
2002+ static void initialize_buckets () {
19982003 size_t numthread = settings.getNumWorkerThreads () + 1 ;
19992004 for (auto &b : all_buckets) {
20002005 b.stats .resize (numthread);
@@ -2010,7 +2015,7 @@ static void initialize_buckets(void) {
20102015 nobucket.state = BucketState::Ready;
20112016}
20122017
2013- static void cleanup_buckets (void ) {
2018+ static void cleanup_buckets () {
20142019 for (auto &bucket : all_buckets) {
20152020 bool waiting;
20162021
@@ -2057,7 +2062,7 @@ void delete_all_buckets() {
20572062 */
20582063 class DestroyBucketTask : public Task {
20592064 public:
2060- DestroyBucketTask (const std::string& name_)
2065+ explicit DestroyBucketTask (const std::string& name_)
20612066 : thread(name_, false , nullptr , this )
20622067 {
20632068 // empty
@@ -2102,7 +2107,7 @@ void delete_all_buckets() {
21022107 }
21032108 all_bucket_lock.unlock ();
21042109
2105- if (task. get () != nullptr ) {
2110+ if (task) {
21062111 auto & dbt = dynamic_cast <DestroyBucketTask&>(*task);
21072112 LOG_INFO (" Waiting for delete of {} to complete" , name);
21082113 dbt.thread .waitForState (Couchbase::ThreadState::Zombie);
@@ -2111,7 +2116,7 @@ void delete_all_buckets() {
21112116 } while (!done);
21122117}
21132118
2114- static void set_max_filehandles (void ) {
2119+ static void set_max_filehandles () {
21152120 const uint64_t maxfiles = settings.getMaxconns () +
21162121 (3 * (settings.getNumWorkerThreads () + 2 )) +
21172122 1024 ;
@@ -2169,11 +2174,8 @@ static void initialize_sasl() {
21692174 using namespace cb ::sasl;
21702175 logging::set_log_callback (sasl_log_callback);
21712176 server::initialize ();
2172- if (mechanism::plain::authenticate (" default" , " " ) == Error::OK) {
2173- set_default_bucket_enabled (true );
2174- } else {
2175- set_default_bucket_enabled (false );
2176- }
2177+ set_default_bucket_enabled (
2178+ mechanism::plain::authenticate (" default" , " " ) == Error::OK);
21772179
21782180 if (getenv (" MEMCACHED_UNIT_TESTS" ) != nullptr ) {
21792181 // Speed up the unit tests ;)
@@ -2295,27 +2297,27 @@ extern "C" int memcached_main(int argc, char **argv) {
22952297 initialize_audit ();
22962298
22972299 /* inform interested parties of initial verbosity level */
2298- perform_callbacks (ON_LOG_LEVEL, NULL , NULL );
2300+ perform_callbacks (ON_LOG_LEVEL, nullptr , nullptr );
22992301
23002302 set_max_filehandles ();
23012303
23022304 /* Aggregate the maximum number of connections */
23032305 settings.calculateMaxconns ();
23042306
2305- if (getenv (" MEMCACHED_CRASH_TEST" ) == NULL ) {
2307+ if (getenv (" MEMCACHED_CRASH_TEST" )) {
2308+ // The crash tests wants the system to generate a crash.
2309+ // I tried to rethrow the exception instead of logging
2310+ // the error, but for some reason the python test script
2311+ // didn't like that..
2312+ initialize_engine_map ();
2313+ } else {
23062314 try {
23072315 initialize_engine_map ();
23082316 } catch (const std::exception& error) {
23092317 FATAL_ERROR (EXIT_FAILURE,
23102318 " Unable to initialize engine map: {}" ,
23112319 error.what ());
23122320 }
2313- } else {
2314- // The crash tests wants the system to generate a crash.
2315- // I tried to rethrow the exception instead of logging
2316- // the error, but for some reason the python test script
2317- // didn't like that..
2318- initialize_engine_map ();
23192321 }
23202322
23212323 /* Initialize bucket engine */
0 commit comments