Skip to content

Commit 62e4aaa

Browse files
committed
cleanup: os_thread_sleep() -> std::this_thread::sleep_for()
std version has an advantage of a more convenient units implementation from std::chrono. Now it's no need to multipy/divide to bring anything to micro seconds.
1 parent 40fd42f commit 62e4aaa

32 files changed

+113
-122
lines changed

cmake/os/WindowsCache.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ SET(HAVE_BZLIB2_DECOMPRESS CACHE INTERNAL "")
317317
SET(HAVE_BZLIB2_H CACHE INTERNAL "")
318318
SET(HAVE_SNAPPY_H CACHE INTERNAL "")
319319
SET(HAVE_SCHED_GETCPU CACHE INTERNAL "")
320-
SET(HAVE_NANOSLEEP CACHE INTERNAL "")
321320
SET(HAVE_PTHREAD_THREADID_NP CACHE INTERNAL "")
322321
SET(HAVE_SYS_GETTID CACHE INTERNAL "")
323322
SET(HAVE_INTEGER_PTHREAD_SELF CACHE INTERNAL "")

extra/mariabackup/backup_copy.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ run_data_threads(datadir_iter_t *it, os_thread_func_t func, uint n)
970970

971971
/* Wait for threads to exit */
972972
while (1) {
973-
os_thread_sleep(100000);
973+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
974974
pthread_mutex_lock(&count_mutex);
975975
if (count == 0) {
976976
pthread_mutex_unlock(&count_mutex);

extra/mariabackup/backup_mysql.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,7 @@ wait_for_no_updates(MYSQL *connection, uint timeout, uint threshold)
791791
if (!have_queries_to_wait_for(connection, threshold)) {
792792
return(true);
793793
}
794-
os_thread_sleep(1000000);
794+
std::this_thread::sleep_for(std::chrono::seconds(1));
795795
}
796796

797797
msg("Unable to obtain lock. Please try again later.");
@@ -963,8 +963,9 @@ unlock_all(MYSQL *connection)
963963
if (opt_debug_sleep_before_unlock) {
964964
msg("Debug sleep for %u seconds",
965965
opt_debug_sleep_before_unlock);
966-
os_thread_sleep(opt_debug_sleep_before_unlock * 1000);
967-
}
966+
std::this_thread::sleep_for(
967+
std::chrono::milliseconds(opt_debug_sleep_before_unlock));
968+
}
968969

969970
msg("Executing BACKUP STAGE END");
970971
xb_mysql_query(connection, "BACKUP STAGE END", false);
@@ -1042,7 +1043,7 @@ wait_for_safe_slave(MYSQL *connection)
10421043
"remaining)...", sleep_time, n_attempts);
10431044

10441045
xb_mysql_query(connection, "START SLAVE SQL_THREAD", false);
1045-
os_thread_sleep(sleep_time * 1000000);
1046+
std::this_thread::sleep_for(std::chrono::seconds(sleep_time));
10461047
xb_mysql_query(connection, "STOP SLAVE SQL_THREAD", false);
10471048

10481049
open_temp_tables = get_open_temp_tables(connection);

extra/mariabackup/fil_cur.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,8 @@ xb_fil_cur_result_t xb_fil_cur_read(xb_fil_cur_t* cursor,
457457
msg(cursor->thread_n, "Database page corruption detected at page "
458458
UINT32PF ", retrying...",
459459
page_no);
460-
os_thread_sleep(100000);
460+
std::this_thread::sleep_for(
461+
std::chrono::milliseconds(100));
461462
goto read_retry;
462463
}
463464
}

extra/mariabackup/xtrabackup.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,8 @@ static dberr_t xb_assign_undo_space_start()
35613561
/* TRX_SYS page can't be compressed or encrypted. */
35623562
if (buf_page_is_corrupted(false, page, fsp_flags)) {
35633563
if (n_retries--) {
3564-
os_thread_sleep(1000);
3564+
std::this_thread::sleep_for(
3565+
std::chrono::milliseconds(1));
35653566
goto retry;
35663567
} else {
35673568
msg("mariabackup: TRX_SYS page corrupted.\n");
@@ -4085,7 +4086,7 @@ static void stop_backup_threads(bool running)
40854086
{
40864087
putc('.', stderr);
40874088
fflush(stderr);
4088-
os_thread_sleep(200000); /*0.2 sec*/
4089+
std::this_thread::sleep_for(std::chrono::milliseconds(200));
40894090
}
40904091
putc('\n', stderr);
40914092
mysql_cond_destroy(&log_copying_stop);
@@ -4471,7 +4472,7 @@ static bool xtrabackup_backup_func()
44714472

44724473
/* Wait for threads to exit */
44734474
while (1) {
4474-
os_thread_sleep(1000000);
4475+
std::this_thread::sleep_for(std::chrono::seconds(1));
44754476
pthread_mutex_lock(&count_mutex);
44764477
bool stop = count == 0;
44774478
pthread_mutex_unlock(&count_mutex);

storage/innobase/buf/buf0buf.cc

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ void page_hash_latch::write_lock_wait()
310310
while (!write_lock_poll());
311311
}
312312

313-
/** Value in microseconds */
314-
constexpr int WAIT_FOR_READ= 100;
313+
constexpr std::chrono::microseconds WAIT_FOR_READ(100);
315314
constexpr int WAIT_FOR_WRITE= 100;
316315
/** Number of attempts made to read in a page in the buffer pool */
317316
constexpr ulint BUF_PAGE_READ_MAX_RETRIES= 100;
@@ -1810,7 +1809,8 @@ inline void buf_pool_t::resize()
18101809
if (should_retry_withdraw) {
18111810
ib::info() << "Will retry to withdraw " << retry_interval
18121811
<< " seconds later.";
1813-
os_thread_sleep(retry_interval * 1000000);
1812+
std::this_thread::sleep_for(
1813+
std::chrono::seconds(retry_interval));
18141814

18151815
if (retry_interval > 5) {
18161816
retry_interval = 10;
@@ -1831,7 +1831,9 @@ inline void buf_pool_t::resize()
18311831
should_wait = false;
18321832
DBUG_EXECUTE_IF(
18331833
"ib_buf_pool_resize_wait_before_resize",
1834-
should_wait = true; os_thread_sleep(10000););
1834+
should_wait = true;
1835+
std::this_thread::sleep_for(
1836+
std::chrono::milliseconds(10)););
18351837
}
18361838
}
18371839
#endif /* !DBUG_OFF */
@@ -2375,7 +2377,7 @@ buf_page_t* buf_page_get_zip(const page_id_t page_id, ulint zip_size)
23752377
if (must_read)
23762378
/* Let us wait until the read operation completes */
23772379
while (bpage->io_fix() == BUF_IO_READ)
2378-
os_thread_sleep(WAIT_FOR_READ);
2380+
std::this_thread::sleep_for(WAIT_FOR_READ);
23792381

23802382
return bpage;
23812383
}
@@ -2763,7 +2765,8 @@ buf_page_get_low(
27632765
Avoid returning reference to this page.
27642766
Instead wait for the flush action to complete. */
27652767
fix_block->unfix();
2766-
os_thread_sleep(WAIT_FOR_WRITE);
2768+
std::this_thread::sleep_for(
2769+
std::chrono::microseconds(WAIT_FOR_WRITE));
27672770
goto loop;
27682771
}
27692772

@@ -2814,7 +2817,7 @@ buf_page_get_low(
28142817

28152818
/* The block is buffer-fixed or I/O-fixed.
28162819
Try again later. */
2817-
os_thread_sleep(WAIT_FOR_READ);
2820+
std::this_thread::sleep_for(WAIT_FOR_READ);
28182821

28192822
goto loop;
28202823
}

storage/innobase/buf/buf0dump.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2011, 2017, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2017, 2020, MariaDB Corporation.
4+
Copyright (c) 2017, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -472,7 +472,8 @@ buf_load_throttle_if_needed(
472472
ut_time_ms() that often may turn out to be too expensive. */
473473

474474
if (elapsed_time < 1000 /* 1 sec (1000 milli secs) */) {
475-
os_thread_sleep((1000 - elapsed_time) * 1000 /* micro secs */);
475+
std::this_thread::sleep_for(
476+
std::chrono::milliseconds(1000 - elapsed_time));
476477
}
477478

478479
*last_check_time = ut_time_ms();

storage/innobase/buf/buf0flu.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2219,7 +2219,7 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
22192219
#ifdef UNIV_DEBUG
22202220
while (innodb_page_cleaner_disabled_debug && !buf_flush_sync_lsn &&
22212221
srv_shutdown_state == SRV_SHUTDOWN_NONE)
2222-
os_thread_sleep(100000);
2222+
std::this_thread::sleep_for(std::chrono::milliseconds(100));
22232223
#endif /* UNIV_DEBUG */
22242224

22252225
#ifndef DBUG_OFF

storage/innobase/buf/buf0rea.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2015, 2020, MariaDB Corporation.
4+
Copyright (c) 2015, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -748,7 +748,8 @@ void buf_read_recv_pages(ulint space_id, const uint32_t* page_nos, ulint n)
748748
}
749749

750750
for (ulint count = 0; buf_pool.n_pend_reads >= limit; ) {
751-
os_thread_sleep(10000);
751+
std::this_thread::sleep_for(
752+
std::chrono::milliseconds(10));
752753

753754
if (!(++count % 1000)) {
754755

storage/innobase/dict/dict0stats.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 2009, 2019, Oracle and/or its affiliates. All Rights Reserved.
4-
Copyright (c) 2015, 2020, MariaDB Corporation.
4+
Copyright (c) 2015, 2021, MariaDB Corporation.
55
66
This program is free software; you can redistribute it and/or modify it under
77
the terms of the GNU General Public License as published by the Free Software
@@ -37,6 +37,7 @@ Created Jan 06, 2010 Vasil Dimov
3737
#include <algorithm>
3838
#include <map>
3939
#include <vector>
40+
#include <thread>
4041

4142
/* Sampling algorithm description @{
4243
@@ -3775,7 +3776,8 @@ dict_stats_rename_table(
37753776

37763777
if (ret != DB_SUCCESS) {
37773778
dict_sys_unlock();
3778-
os_thread_sleep(200000 /* 0.2 sec */);
3779+
std::this_thread::sleep_for(
3780+
std::chrono::milliseconds(200));
37793781
dict_sys_lock();
37803782
}
37813783
} while ((ret == DB_DEADLOCK
@@ -3828,7 +3830,8 @@ dict_stats_rename_table(
38283830

38293831
if (ret != DB_SUCCESS) {
38303832
dict_sys_unlock();
3831-
os_thread_sleep(200000 /* 0.2 sec */);
3833+
std::this_thread::sleep_for(
3834+
std::chrono::milliseconds(200));
38323835
dict_sys_lock();
38333836
}
38343837
} while ((ret == DB_DEADLOCK

0 commit comments

Comments
 (0)