aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralyashko <alyashko@yandex-team.ru>2022-02-10 16:51:51 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:51:51 +0300
commitdb4d932e6a8f3e45ec65bf7d1e336de1391ecdb5 (patch)
tree00d45b87ea22b46394b4c7d2e39bb5bd851b5800
parentfffc5498228bac1ad41ed40b9b7f5cb453796ba8 (diff)
downloadydb-db4d932e6a8f3e45ec65bf7d1e336de1391ecdb5.tar.gz
Restoring authorship annotation for <alyashko@yandex-team.ru>. Commit 1 of 2.
-rw-r--r--util/system/tls.h172
1 files changed, 86 insertions, 86 deletions
diff --git a/util/system/tls.h b/util/system/tls.h
index 3c4f56dbeb..4fcc176572 100644
--- a/util/system/tls.h
+++ b/util/system/tls.h
@@ -19,109 +19,109 @@
#define Y_DISABLE_THRKEY_OPTIMIZATION
#endif
-/**
+/**
@def Y_THREAD(TType)
-
- A thread-local wrapper for a given class. Suitable for POD and classes with a constructor with a single argument.
-
- The wrapper can be treated as the original class in many cases, as it has the same signature for the constructor and an implicit cast to the origianl class.
-
- Has methods :
- - implicit caster to TType
- - TType& Get()
- - TType* GetPtr()
-
- Time complexity: getting a variable takes O(number of threads where the variable has been constructed)
-
- Memory usage: O(number of threads where the variable has been constructed)
-
- Best practices:
- - storing singletons won't result in heavy memory overheads
- - storing pointers allows complex constructors as well as lazy constructions
- - storing static variables won't result in heavy memory overheads
-
- Possibly bad practices:
- - field in a class with numerous instances and numerous threads will result in slow working and memory overheads
-
- Example:
- @code
- //the field declaration in header
+
+ A thread-local wrapper for a given class. Suitable for POD and classes with a constructor with a single argument.
+
+ The wrapper can be treated as the original class in many cases, as it has the same signature for the constructor and an implicit cast to the origianl class.
+
+ Has methods :
+ - implicit caster to TType
+ - TType& Get()
+ - TType* GetPtr()
+
+ Time complexity: getting a variable takes O(number of threads where the variable has been constructed)
+
+ Memory usage: O(number of threads where the variable has been constructed)
+
+ Best practices:
+ - storing singletons won't result in heavy memory overheads
+ - storing pointers allows complex constructors as well as lazy constructions
+ - storing static variables won't result in heavy memory overheads
+
+ Possibly bad practices:
+ - field in a class with numerous instances and numerous threads will result in slow working and memory overheads
+
+ Example:
+ @code
+ //the field declaration in header
Y_THREAD(TBuffer) TmpBuffer;
- //...later somewhere in cpp...
- TmpBuffer.Clear();
- for (size_t i = 0; i < sz && TrieCursor[i].second.IsFork(); ++i) {
- TmpBuffer.Append(TrieCursor[i].second.Char);
- }
- @endcode
-
- Example:
- @code
- //the field decalrataion in header
+ //...later somewhere in cpp...
+ TmpBuffer.Clear();
+ for (size_t i = 0; i < sz && TrieCursor[i].second.IsFork(); ++i) {
+ TmpBuffer.Append(TrieCursor[i].second.Char);
+ }
+ @endcode
+
+ Example:
+ @code
+ //the field decalrataion in header
Y_THREAD(TMyWriter*) ThreadLocalWriter;
- //...later somewhere in cpp...
- TMyWriter*& writerRef = ThreadLocalWriter.Get();
+ //...later somewhere in cpp...
+ TMyWriter*& writerRef = ThreadLocalWriter.Get();
if (writerRef == nullptr) {
THolder<TMyWriter> threadLocalWriter( new TMyWriter(
- *Session,
- MinLogError,
- MaxRps,
- LogFraction,
- WriteCounters,
- Log));
- writerRef = threadLocalWriter.Get();
- }
- @endcode
-
- Example:
- @code
- //in header
- namespace TMorph {
+ *Session,
+ MinLogError,
+ MaxRps,
+ LogFraction,
+ WriteCounters,
+ Log));
+ writerRef = threadLocalWriter.Get();
+ }
+ @endcode
+
+ Example:
+ @code
+ //in header
+ namespace TMorph {
Y_THREAD(ELanguage) ThreadLocalMainLanguage;
- }
- //in cpp
+ }
+ //in cpp
Y_THREAD(ELanguage) TMorph::ThreadLocalMainLanguage(LANG_RUS);
- @endcode
-
- Example:
- @code
+ @endcode
+
+ Example:
+ @code
Y_THREAD(TScoreCalcer*) ScoreCalcerPtr;
- static TScoreCalcer* GetScoreCalcer(yint maxElemCount) {
- if (ScoreCalcerPtr == 0) {
- ScoreCalcerPtr = new TScoreCalcer();
- ScoreCalcerPtr->Alloc(maxElemCount);
- }
- return ScoreCalcerPtr;
- }
- @endcode
-
- @param TType POD or a class with a constructor taking 1 argument
-**/
-
-/**
+ static TScoreCalcer* GetScoreCalcer(yint maxElemCount) {
+ if (ScoreCalcerPtr == 0) {
+ ScoreCalcerPtr = new TScoreCalcer();
+ ScoreCalcerPtr->Alloc(maxElemCount);
+ }
+ return ScoreCalcerPtr;
+ }
+ @endcode
+
+ @param TType POD or a class with a constructor taking 1 argument
+**/
+
+/**
@def Y_STATIC_THREAD(TType)
-
+
Equivalent to "static Y_THREAD(TType)"
-
+
@see Y_THREAD(TType)
-**/
-
-/**
+**/
+
+/**
@def Y_POD_THREAD(TType)
-
+
Same interface as Y_THREAD(TType), but TType must be a POD.
Implemented (based on the compiler) as Y_THREAD(TType) or as native tls.
-
+
@see Y_THREAD(TType)
-**/
-
-/**
- @def STATIC_POD_THREAD(TType)
-
+**/
+
+/**
+ @def STATIC_POD_THREAD(TType)
+
Equivalent to "static Y_POD_THREAD(TType)"
-
+
@see Y_POD_THREAD(TType)
-**/
-
+**/
+
#define Y_THREAD(T) ::NTls::TValue<T>
#define Y_STATIC_THREAD(T) static Y_THREAD(T)