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
Show 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
...
@@ -148,7 +148,7 @@ struct srv_stats_t
ulint_ctr_1_t
n_lock_wait_count
;
ulint_ctr_1_t
n_lock_wait_count
;
/** Number of threads currently waiting on database locks */
/** 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. */
/** Number of rows read. */
ulint_ctr_64_t
n_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)
...
@@ -1186,50 +1186,43 @@ static inline void my_atomic_storelint(ulint *A, ulint B)
#endif
#endif
}
}
/** Simple counter aligned to CACHE_LINE_SIZE
/** Simple non-atomic counter aligned to CACHE_LINE_SIZE
@tparam Type the integer type of the counter
@tparam Type the integer type of the counter */
@tparam atomic whether to use atomic memory access */
template
<
typename
Type
>
template
<
typename
Type
=
ulint
,
bool
atomic
=
false
>
struct
MY_ALIGNED
(
CPU_LEVEL1_DCACHE_LINESIZE
)
simple_counter
struct
MY_ALIGNED
(
CPU_LEVEL1_DCACHE_LINESIZE
)
simple_counter
{
{
/** Increment the counter */
/** Increment the counter */
Type
inc
()
{
return
add
(
1
);
}
Type
inc
()
{
return
add
(
1
);
}
/** Decrement the counter */
/** Decrement the counter */
Type
dec
()
{
return
sub
(
1
);
}
Type
dec
()
{
return
add
(
Type
(
~
0
)
);
}
/** Add to the counter
/** Add to the counter
@param[in] i amount to be added
@param[in] i amount to be added
@return the value of the counter after adding */
@return the value of the counter after adding */
Type
add
(
Type
i
)
Type
add
(
Type
i
)
{
return
m_counter
+=
i
;
}
{
compile_time_assert
(
!
atomic
||
sizeof
(
Type
)
==
sizeof
(
lint
));
/** @return the value of the counter */
if
(
atomic
)
{
operator
Type
()
const
{
return
m_counter
;
}
#ifdef _MSC_VER
// Suppress type conversion/ possible loss of data warning
private
:
#pragma warning (push)
/** The counter */
#pragma warning (disable : 4244)
Type
m_counter
;
#endif
}
;
return
Type
(
my_atomic_addlint
(
reinterpret_cast
<
ulint
*>
(
&
m_counter
),
i
));
/** Simple atomic counter aligned to CACHE_LINE_SIZE
#ifdef _MSC_VER
@tparam Type lint or ulint */
#pragma warning (pop)
template
<
typename
Type
=
ulint
>
#endif
struct
MY_ALIGNED
(
CPU_LEVEL1_DCACHE_LINESIZE
)
simple_atomic_counter
}
else
{
{
return
m_counter
+=
i
;
/** Increment the counter */
}
Type
inc
()
{
return
add
(
1
);
}
}
/** Decrement the counter */
/** Subtract from the counter
Type
dec
()
{
return
add
(
Type
(
~
0
));
}
@param[in] i amount to be subtracted
/** Add to the counter
@param[in] i amount to be added
@return the value of the counter after adding */
@return the value of the counter after adding */
Type
sub
(
Type
i
)
Type
add
(
Type
i
)
{
return
my_atomic_addlint
(
&
m_counter
,
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
;
}
}
/** @return the value of the counter (non-atomic access)! */
/** @return the value of the counter (non-atomic access)! */
operator
Type
()
const
{
return
m_counter
;
}
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