Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
1292a01c
Commit
1292a01c
authored
Apr 28, 2018
by
Marko Mäkelä
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify simple_counter
Introduce a separate simple_atomic_counter
parent
8861d442
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
35 deletions
+28
-35
storage/innobase/include/srv0srv.h
storage/innobase/include/srv0srv.h
+1
-1
storage/innobase/include/sync0types.h
storage/innobase/include/sync0types.h
+27
-34
No files found.
storage/innobase/include/srv0srv.h
View file @
1292a01c
...
...
@@ -148,7 +148,7 @@ struct srv_stats_t
ulint_ctr_1_t
n_lock_wait_count
;
/** Number of threads currently waiting on database locks */
simple_
counter
<
ulint
,
true
>
n_lock_wait_current_count
;
simple_
atomic_counter
<>
n_lock_wait_current_count
;
/** Number of rows read. */
ulint_ctr_64_t
n_rows_read
;
...
...
storage/innobase/include/sync0types.h
View file @
1292a01c
...
...
@@ -1186,50 +1186,43 @@ static inline void my_atomic_storelint(ulint *A, ulint B)
#endif
}
/** Simple counter aligned to CACHE_LINE_SIZE
@tparam Type the integer type of the counter
@tparam atomic whether to use atomic memory access */
template
<
typename
Type
=
ulint
,
bool
atomic
=
false
>
/** Simple non-atomic counter aligned to CACHE_LINE_SIZE
@tparam Type the integer type of the counter */
template
<
typename
Type
>
struct
MY_ALIGNED
(
CPU_LEVEL1_DCACHE_LINESIZE
)
simple_counter
{
/** Increment the counter */
Type
inc
()
{
return
add
(
1
);
}
/** Decrement the counter */
Type
dec
()
{
return
sub
(
1
);
}
Type
dec
()
{
return
add
(
Type
(
~
0
)
);
}
/** Add to the counter
@param[in] i amount to be added
@return the value of the counter after adding */
Type
add
(
Type
i
)
{
compile_time_assert
(
!
atomic
||
sizeof
(
Type
)
==
sizeof
(
lint
));
if
(
atomic
)
{
#ifdef _MSC_VER
// Suppress type conversion/ possible loss of data warning
#pragma warning (push)
#pragma warning (disable : 4244)
#endif
return
Type
(
my_atomic_addlint
(
reinterpret_cast
<
ulint
*>
(
&
m_counter
),
i
));
#ifdef _MSC_VER
#pragma warning (pop)
#endif
}
else
{
return
m_counter
+=
i
;
}
}
/** Subtract from the counter
@param[in] i amount to be subtracted
Type
add
(
Type
i
)
{
return
m_counter
+=
i
;
}
/** @return the value of the counter */
operator
Type
()
const
{
return
m_counter
;
}
private
:
/** The counter */
Type
m_counter
;
}
;
/** Simple atomic counter aligned to CACHE_LINE_SIZE
@tparam Type lint or ulint */
template
<
typename
Type
=
ulint
>
struct
MY_ALIGNED
(
CPU_LEVEL1_DCACHE_LINESIZE
)
simple_atomic_counter
{
/** Increment the counter */
Type
inc
()
{
return
add
(
1
);
}
/** Decrement the counter */
Type
dec
()
{
return
add
(
Type
(
~
0
));
}
/** Add to the counter
@param[in] i amount to be added
@return the value of the counter after adding */
Type
sub
(
Type
i
)
{
compile_time_assert
(
!
atomic
||
sizeof
(
Type
)
==
sizeof
(
lint
));
if
(
atomic
)
{
return
Type
(
my_atomic_addlint
(
&
m_counter
,
-
lint
(
i
)));
}
else
{
return
m_counter
-=
i
;
}
}
Type
add
(
Type
i
)
{
return
my_atomic_addlint
(
&
m_counter
,
i
);
}
/** @return the value of the counter (non-atomic access)! */
operator
Type
()
const
{
return
m_counter
;
}
...
...
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