Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
62751cea
Kaydet (Commit)
62751cea
authored
May 30, 2011
tarafından
Caolán McNamara
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
add a StaticWithArg to make its use easier
üst
7a69e30f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
+118
-0
instance.hxx
sal/inc/rtl/instance.hxx
+118
-0
No files found.
sal/inc/rtl/instance.hxx
Dosyayı görüntüle @
62751cea
...
...
@@ -323,6 +323,31 @@ public:
return
p
;
}
static
inline
Inst
*
create
(
InstCtor
aInstCtor
,
GuardCtor
aGuardCtor
,
const
Data
&
rData
)
{
#if defined _MSC_VER
static
Inst
*
m_pInstance
=
0
;
#endif // _MSC_VER
Inst
*
p
=
m_pInstance
;
if
(
!
p
)
{
Guard
aGuard
(
aGuardCtor
());
p
=
m_pInstance
;
if
(
!
p
)
{
p
=
aInstCtor
(
rData
);
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER
();
m_pInstance
=
p
;
}
}
else
{
OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER
();
}
return
p
;
}
private
:
#if !defined _MSC_VER
static
Inst
*
m_pInstance
;
...
...
@@ -402,6 +427,99 @@ private:
};
#endif
/** Helper base class for a late-initialized (default-constructed)
static variable, implementing the double-checked locking pattern correctly.
@derive
Derive from this class (common practice), e.g.
<pre>
struct MyStatic : public rtl::Static<MyType, MyStatic> {};
...
MyType & rStatic = MyStatic::get();
...
</pre>
@tplparam T
variable's type
@tplparam Unique
Implementation trick to make the inner static holder unique,
using the outer class
(the one that derives from this base class)
*/
#if (__GNUC__ >= 4)
template
<
typename
T
,
typename
Data
,
typename
Unique
>
class
StaticWithArg
{
public
:
/** Gets the static. Mutual exclusion is implied by a functional
-fthreadsafe-statics
@return
static variable
*/
static
T
&
get
(
const
Data
&
rData
)
{
static
T
instance
(
rData
);
return
instance
;
}
/** Gets the static. Mutual exclusion is implied by a functional
-fthreadsafe-statics
@return
static variable
*/
static
T
&
get
(
Data
&
rData
)
{
static
T
instance
(
rData
);
return
instance
;
}
};
#else
template
<
typename
T
,
typename
Data
,
typename
Unique
>
class
StaticWithArg
{
public
:
/** Gets the static. Mutual exclusion is performed using the
osl global mutex.
@return
static variable
*/
static
T
&
get
(
const
Data
&
rData
)
{
return
*
rtl_Instance
<
T
,
StaticInstanceWithArg
,
::
osl
::
MutexGuard
,
::
osl
::
GetGlobalMutex
,
Data
>::
create
(
StaticInstanceWithArg
(),
::
osl
::
GetGlobalMutex
(),
rData
);
}
/** Gets the static. Mutual exclusion is performed using the
osl global mutex.
@return
static variable
*/
static
T
&
get
(
Data
&
rData
)
{
return
*
rtl_Instance
<
T
,
StaticInstanceWithArg
,
::
osl
::
MutexGuard
,
::
osl
::
GetGlobalMutex
,
Data
>::
create
(
StaticInstanceWithArg
(),
::
osl
::
GetGlobalMutex
(),
rData
);
}
private
:
struct
StaticInstanceWithArg
{
T
*
operator
()
(
const
Data
&
rData
)
{
static
T
instance
(
rData
);
return
&
instance
;
}
T
*
operator
()
(
Data
&
rData
)
{
static
T
instance
(
rData
);
return
&
instance
;
}
};
};
#endif
/** Helper class for a late-initialized static aggregate, e.g. an array,
implementing the double-checked locking pattern correctly.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment