Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Alchemy Viewer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Silent mode is enabled
All outbound communications are blocked.
Learn more
.
Show more breadcrumbs
Alchemy Viewer
Alchemy Viewer
Commits
ae1aa461
Commit
ae1aa461
authored
12 years ago
by
Graham Madarasz (Graham)
Browse files
Options
Downloads
Patches
Plain Diff
Attempt at a faster ThreadSafeRefCount class
parent
93eaccae
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
indra/llcommon/llapr.h
+7
-1
7 additions, 1 deletion
indra/llcommon/llapr.h
indra/llcommon/llthread.cpp
+0
-8
0 additions, 8 deletions
indra/llcommon/llthread.cpp
indra/llcommon/llthread.h
+18
-22
18 additions, 22 deletions
indra/llcommon/llthread.h
with
25 additions
and
31 deletions
indra/llcommon/llapr.h
+
7
−
1
View file @
ae1aa461
...
...
@@ -164,14 +164,20 @@ template <typename Type> class LLAtomic32
~
LLAtomic32
<
Type
>
()
{};
operator
const
Type
()
{
apr_uint32_t
data
=
apr_atomic_read32
(
&
mData
);
return
Type
(
data
);
}
Type
CurrentValue
()
const
{
apr_uint32_t
data
=
apr_atomic_read32
(
const_cast
<
volatile
apr_uint32_t
*
>
(
&
mData
));
return
Type
(
data
);
}
Type
operator
=
(
const
Type
&
x
)
{
apr_atomic_set32
(
&
mData
,
apr_uint32_t
(
x
));
return
Type
(
mData
);
}
void
operator
-=
(
Type
x
)
{
apr_atomic_sub32
(
&
mData
,
apr_uint32_t
(
x
));
}
void
operator
+=
(
Type
x
)
{
apr_atomic_add32
(
&
mData
,
apr_uint32_t
(
x
));
}
Type
operator
++
(
int
)
{
return
apr_atomic_inc32
(
&
mData
);
}
// Type++
Type
operator
--
(
int
)
{
return
apr_atomic_dec32
(
&
mData
);
}
// approximately --Type (0 if final is 0, non-zero otherwise)
Type
operator
++
()
{
return
apr_atomic_inc32
(
&
mData
);
}
// Type++
Type
operator
--
()
{
return
apr_atomic_dec32
(
&
mData
);
}
// approximately --Type (0 if final is 0, non-zero otherwise)
private
:
apr_uint32_t
mData
;
volatile
apr_uint32_t
mData
;
};
typedef
LLAtomic32
<
U32
>
LLAtomicU32
;
...
...
This diff is collapsed.
Click to expand it.
indra/llcommon/llthread.cpp
+
0
−
8
View file @
ae1aa461
...
...
@@ -495,15 +495,7 @@ LLThreadSafeRefCount::LLThreadSafeRefCount() :
LLThreadSafeRefCount
::
LLThreadSafeRefCount
(
const
LLThreadSafeRefCount
&
src
)
{
if
(
sMutex
)
{
sMutex
->
lock
();
}
mRef
=
0
;
if
(
sMutex
)
{
sMutex
->
unlock
();
}
}
LLThreadSafeRefCount
::~
LLThreadSafeRefCount
()
...
...
This diff is collapsed.
Click to expand it.
indra/llcommon/llthread.h
+
18
−
22
View file @
ae1aa461
...
...
@@ -241,47 +241,43 @@ class LL_COMMON_API LLThreadSafeRefCount
LLThreadSafeRefCount
(
const
LLThreadSafeRefCount
&
);
LLThreadSafeRefCount
&
operator
=
(
const
LLThreadSafeRefCount
&
ref
)
{
if
(
sMutex
)
{
sMutex
->
lock
();
}
mRef
=
0
;
if
(
sMutex
)
{
sMutex
->
unlock
();
}
return
*
this
;
}
void
ref
()
{
if
(
sMutex
)
sMutex
->
lock
();
mRef
++
;
if
(
sMutex
)
sMutex
->
unlock
();
}
S32
unref
()
{
llassert
(
mRef
>=
1
);
if
(
sMutex
)
sMutex
->
lock
();
S32
res
=
--
mRef
;
if
(
sMutex
)
sMutex
->
unlock
();
if
(
0
==
res
)
llassert
(
mRef
>=
1
);
bool
time_to_die
=
(
mRef
==
1
);
if
(
time_to_die
)
{
delete
this
;
if
(
sMutex
)
sMutex
->
lock
();
// Looks redundant, but is very much not
// We need to check again once we've acquired the lock
// so that two threads who get into the if in parallel
// don't both attempt to the delete.
//
if
(
mRef
==
1
)
delete
this
;
mRef
--
;
if
(
sMutex
)
sMutex
->
unlock
();
return
0
;
}
return
res
;
}
return
--
mRef
;
}
S32
getNumRefs
()
const
{
return
mRef
;
const
S32
currentVal
=
mRef
.
CurrentValue
();
return
currentVal
;
}
private
:
S32
mRef
;
LLAtomic32
<
S32
>
mRef
;
};
//============================================================================
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment