-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New locker mechanism and small data race fixes #1166
base: master
Are you sure you want to change the base?
Changes from all commits
d55abbe
b87c4c8
c482dc7
7478704
63f6551
725f1a0
650367c
6c6e268
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
#pragma once | ||
|
||
#include <atomic> | ||
#include <type_traits> | ||
|
||
namespace vk { | ||
|
||
|
@@ -32,4 +33,29 @@ class copyable_atomic : std::atomic<T> { | |
// Add other operators if it is required | ||
}; | ||
|
||
template<class T, class U = std::enable_if_t<std::is_integral_v<T>>> | ||
struct copyable_atomic_integral : std::atomic<T> { | ||
using std::atomic<T>::atomic; | ||
using std::atomic<T>::operator=; | ||
using std::atomic<T>::store; | ||
using std::atomic<T>::load; | ||
using std::atomic<T>::exchange; | ||
using std::atomic<T>::operator T; | ||
using std::atomic<T>::compare_exchange_strong; | ||
using std::atomic<T>::compare_exchange_weak; | ||
|
||
// integral operations | ||
using std::atomic<T>::fetch_add; | ||
using std::atomic<T>::fetch_sub; | ||
|
||
copyable_atomic_integral(const copyable_atomic_integral &other) : | ||
std::atomic<T>(other.load()) { | ||
} | ||
|
||
copyable_atomic_integral& operator=(copyable_atomic_integral other) { | ||
*this = other.load(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like risky. Does it potentially lead to recursive invocation of assign operator? I suppose, will be better to rewrite
Correct me, if I'm wrong. |
||
return *this; | ||
} | ||
}; | ||
|
||
} // namespace vk |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
/*** Core ***/ | ||
//Consists mostly of functions that require synchronization | ||
|
||
#include <atomic> | ||
#include <string> | ||
#include <vector> | ||
|
||
|
@@ -61,7 +62,7 @@ class CompilerCore { | |
std::vector<std::string> kphp_runtime_opts; | ||
std::vector<std::string> exclude_namespaces; | ||
bool is_untyped_rpc_tl_used{false}; | ||
bool is_functions_txt_parsed{false}; | ||
std::atomic_bool is_functions_txt_parsed{false}; | ||
function_palette::Palette function_palette; | ||
|
||
inline bool try_require_file(SrcFilePtr file); | ||
|
@@ -177,11 +178,11 @@ class CompilerCore { | |
} | ||
|
||
void set_functions_txt_parsed() { | ||
is_functions_txt_parsed = true; | ||
is_functions_txt_parsed.store(true, std::memory_order_seq_cst); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we use certain memory order option? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used for synchronization, where are some |
||
} | ||
|
||
bool get_functions_txt_parsed() const { | ||
return is_functions_txt_parsed; | ||
return is_functions_txt_parsed.load(std::memory_order_seq_cst); | ||
} | ||
|
||
bool is_output_mode_server() const { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, will be better to pass by reference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it is intentional. It handles self assignment problem properly: currently in 56 line will be used constructor number 2. In case of your suggestions there will be problem with self assignment because of another order of function (constructor in this case) overloading.