@@ -517,6 +517,10 @@ public:
517
517
// / Checks whether the local instance has been initialized.
518
518
bool local_is_initialized () const noexcept ;
519
519
520
+ // / Performs the same check as `local_is_initialized`, but throws an exception
521
+ // / if the local instance is not initialized.
522
+ void check_local () const ;
523
+
520
524
private:
521
525
template <typename ... Args>
522
526
shared_ptr<Service> create_local_service (Args&&... args) {
@@ -526,19 +530,13 @@ private:
526
530
}
527
531
528
532
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;
533
+ check_local ();
534
+ return _instances[this_shard_id ()].service ;
534
535
}
535
536
536
537
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;
538
+ check_local ();
539
+ return _instances[this_shard_id ()].service ;
542
540
}
543
541
};
544
542
@@ -916,6 +914,13 @@ bool sharded<Service>::local_is_initialized() const noexcept {
916
914
_instances[this_shard_id ()].service ;
917
915
}
918
916
917
+ template <typename Service>
918
+ void sharded<Service>::check_local() const {
919
+ if (!local_is_initialized ()) {
920
+ throw no_sharded_instance_exception (pretty_type_name (typeid (Service)));
921
+ }
922
+ }
923
+
919
924
SEASTAR_MODULE_EXPORT_BEGIN
920
925
// / \addtogroup smp-module
921
926
// / @{
0 commit comments