Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
apolyakov committed Dec 12, 2024
1 parent 371ad65 commit 1aec0ab
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 6 additions & 5 deletions runtime-light/state/image-state.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ struct ImageState final : private vk::not_copyable {
php_error("can't get uname, error '%d'", err);
}
uname_info_s = string{uname_info.sysname};
uname_info_s.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_n = string{uname_info.nodename};
uname_info_n.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_r = string{uname_info.release};
uname_info_r.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_v = string{uname_info.version};
uname_info_v.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_m = string{uname_info.machine};
uname_info_m.set_reference_counter_to(ExtraRefCnt::for_global_const);
// +4 for whitespaces
uname_info_a.reserve_at_least(uname_info_s.size() + uname_info_n.size() + uname_info_r.size() + uname_info_v.size() + uname_info_m.size() + 4);
uname_info_a.append(uname_info_s);
Expand All @@ -61,6 +56,12 @@ struct ImageState final : private vk::not_copyable {
uname_info_a.append(uname_info_v);
uname_info_a.push_back(' ');
uname_info_a.append(uname_info_m);
// prevent race condition on reference counter
uname_info_s.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_n.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_r.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_v.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_m.set_reference_counter_to(ExtraRefCnt::for_global_const);
uname_info_a.set_reference_counter_to(ExtraRefCnt::for_global_const);
}

Expand Down
3 changes: 1 addition & 2 deletions runtime-light/stdlib/system/system-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ inline string f$php_uname(const string &mode = string{1, 'a'}) noexcept {
return image_st.uname_info_v;
case 'm':
return image_st.uname_info_m;
default: {
default:
return image_st.uname_info_a;
}
}
}

0 comments on commit 1aec0ab

Please sign in to comment.