@@ -516,7 +516,6 @@ public:
516516
517517 // / Checks whether the local instance has been initialized.
518518 bool local_is_initialized () const noexcept ;
519-
520519private:
521520 template <typename ... Args>
522521 shared_ptr<Service> create_local_service (Args&&... args) {
@@ -525,20 +524,18 @@ private:
525524 return s;
526525 }
527526
527+ // / Performs the same check as `local_is_initialized`, but throws an exception
528+ // / if the local instance is not initialized.
529+ void check_local () const ;
530+
528531 shared_ptr<Service> get_local_service () {
529- auto inst = _instances[this_shard_id ()].service ;
530- if (!inst) {
531- throw no_sharded_instance_exception (pretty_type_name (typeid (Service)));
532- }
533- return inst;
532+ check_local ();
533+ return _instances[this_shard_id ()].service ;
534534 }
535535
536536 shared_ptr<const Service> get_local_service () const {
537- auto inst = _instances[this_shard_id ()].service ;
538- if (!inst) {
539- throw no_sharded_instance_exception (pretty_type_name (typeid (Service)));
540- }
541- return inst;
537+ check_local ();
538+ return _instances[this_shard_id ()].service ;
542539 }
543540};
544541
@@ -916,6 +913,13 @@ bool sharded<Service>::local_is_initialized() const noexcept {
916913 _instances[this_shard_id ()].service ;
917914}
918915
916+ template <typename Service>
917+ void sharded<Service>::check_local() const {
918+ if (!local_is_initialized ()) {
919+ throw no_sharded_instance_exception (pretty_type_name (typeid (Service)));
920+ }
921+ }
922+
919923SEASTAR_MODULE_EXPORT_BEGIN
920924// / \addtogroup smp-module
921925// / @{
0 commit comments