Skip to content

Commit dbe941e

Browse files
committed
cleanup: os_thread_create -> std::thread
1 parent da34288 commit dbe941e

File tree

10 files changed

+37
-182
lines changed

10 files changed

+37
-182
lines changed

extra/mariabackup/backup_copy.cc

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ struct datadir_thread_ctxt_t {
129129
uint n_thread;
130130
uint *count;
131131
pthread_mutex_t* count_mutex;
132-
os_thread_id_t id;
133132
bool ret;
134133
};
135134

@@ -947,7 +946,7 @@ backup_file_printf(const char *filename, const char *fmt, ...)
947946

948947
static
949948
bool
950-
run_data_threads(datadir_iter_t *it, os_thread_func_t func, uint n)
949+
run_data_threads(datadir_iter_t *it, void (*func)(datadir_thread_ctxt_t *ctxt), uint n)
951950
{
952951
datadir_thread_ctxt_t *data_threads;
953952
uint i, count;
@@ -965,7 +964,7 @@ run_data_threads(datadir_iter_t *it, os_thread_func_t func, uint n)
965964
data_threads[i].n_thread = i + 1;
966965
data_threads[i].count = &count;
967966
data_threads[i].count_mutex = &count_mutex;
968-
data_threads[i].id = os_thread_create(func, data_threads + i);
967+
std::thread(func, data_threads + i).detach();
969968
}
970969

971970
/* Wait for threads to exit */
@@ -2036,13 +2035,10 @@ decrypt_decompress_file(const char *filepath, uint thread_n)
20362035
return(true);
20372036
}
20382037

2039-
static
2040-
os_thread_ret_t STDCALL
2041-
decrypt_decompress_thread_func(void *arg)
2038+
static void decrypt_decompress_thread_func(datadir_thread_ctxt_t *ctxt)
20422039
{
20432040
bool ret = true;
20442041
datadir_node_t node;
2045-
datadir_thread_ctxt_t *ctxt = (datadir_thread_ctxt_t *)(arg);
20462042

20472043
datadir_node_init(&node);
20482044

@@ -2072,9 +2068,6 @@ decrypt_decompress_thread_func(void *arg)
20722068
pthread_mutex_unlock(ctxt->count_mutex);
20732069

20742070
ctxt->ret = ret;
2075-
2076-
os_thread_exit();
2077-
OS_THREAD_DUMMY_RETURN;
20782071
}
20792072

20802073
bool

extra/mariabackup/backup_mysql.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -799,7 +799,7 @@ wait_for_no_updates(MYSQL *connection, uint timeout, uint threshold)
799799
return(false);
800800
}
801801

802-
static os_thread_ret_t DECLARE_THREAD(kill_query_thread)(void*)
802+
static void kill_query_thread()
803803
{
804804
mysql_mutex_lock(&kill_query_thread_mutex);
805805

@@ -835,9 +835,6 @@ static os_thread_ret_t DECLARE_THREAD(kill_query_thread)(void*)
835835
kill_query_thread_running= false;
836836
mysql_cond_signal(&kill_query_thread_stopped);
837837
mysql_mutex_unlock(&kill_query_thread_mutex);
838-
839-
os_thread_exit();
840-
OS_THREAD_DUMMY_RETURN;
841838
}
842839

843840

@@ -849,7 +846,7 @@ static void start_query_killer()
849846
mysql_mutex_init(0, &kill_query_thread_mutex, nullptr);
850847
mysql_cond_init(0, &kill_query_thread_stop, nullptr);
851848
mysql_cond_init(0, &kill_query_thread_stopped, nullptr);
852-
os_thread_create(kill_query_thread);
849+
std::thread(kill_query_thread).detach();
853850
}
854851

855852
static void stop_query_killer()

extra/mariabackup/xtrabackup.cc

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,6 @@ typedef struct {
898898
uint num;
899899
uint *count;
900900
pthread_mutex_t* count_mutex;
901-
os_thread_id_t id;
902901
CorruptedPages *corrupted_pages;
903902
} data_thread_ctxt_t;
904903

@@ -3013,7 +3012,7 @@ void backup_wait_for_lsn(lsn_t lsn) {
30133012

30143013
extern lsn_t server_lsn_after_lock;
30153014

3016-
static os_thread_ret_t DECLARE_THREAD(log_copying_thread)(void*)
3015+
static void log_copying_thread()
30173016
{
30183017
my_thread_init();
30193018
mysql_mutex_lock(&log_sys.mutex);
@@ -3027,8 +3026,6 @@ static os_thread_ret_t DECLARE_THREAD(log_copying_thread)(void*)
30273026
log_copying_running= false;
30283027
mysql_mutex_unlock(&log_sys.mutex);
30293028
my_thread_end();
3030-
os_thread_exit();
3031-
return 0;
30323029
}
30333030

30343031
static bool have_io_watching_thread;
@@ -3096,15 +3093,9 @@ void dbug_mariabackup_event(const char *event,const char *key)
30963093
}
30973094
#endif // DBUG_OFF
30983095

3099-
/**************************************************************************
3100-
Datafiles copying thread.*/
3101-
static
3102-
os_thread_ret_t
3103-
DECLARE_THREAD(data_copy_thread_func)(
3104-
/*==================*/
3105-
void *arg) /* thread context */
3096+
/** Datafiles copying thread.*/
3097+
static void data_copy_thread_func(data_thread_ctxt_t *ctxt) /* thread context */
31063098
{
3107-
data_thread_ctxt_t *ctxt = (data_thread_ctxt_t *) arg;
31083099
uint num = ctxt->num;
31093100
fil_node_t* node;
31103101
ut_ad(ctxt->corrupted_pages);
@@ -3136,8 +3127,6 @@ DECLARE_THREAD(data_copy_thread_func)(
31363127
pthread_mutex_unlock(ctxt->count_mutex);
31373128

31383129
my_thread_end();
3139-
os_thread_exit();
3140-
OS_THREAD_DUMMY_RETURN;
31413130
}
31423131

31433132
/************************************************************************
@@ -4424,7 +4413,7 @@ static bool xtrabackup_backup_func()
44244413
DBUG_MARIABACKUP_EVENT("before_innodb_log_copy_thread_started",0);
44254414

44264415
mysql_cond_init(0, &log_copying_stop, nullptr);
4427-
os_thread_create(log_copying_thread);
4416+
std::thread(log_copying_thread).detach();
44284417

44294418
/* FLUSH CHANGED_PAGE_BITMAPS call */
44304419
if (!flush_changed_page_bitmaps()) {
@@ -4466,8 +4455,7 @@ static bool xtrabackup_backup_func()
44664455
data_threads[i].count = &count;
44674456
data_threads[i].count_mutex = &count_mutex;
44684457
data_threads[i].corrupted_pages = &corrupted_pages;
4469-
data_threads[i].id = os_thread_create(data_copy_thread_func,
4470-
data_threads + i);
4458+
std::thread(data_copy_thread_func, data_threads + i).detach();
44714459
}
44724460

44734461
/* Wait for threads to exit */

storage/innobase/buf/buf0flu.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,11 +2025,9 @@ static ulint page_cleaner_flush_pages_recommendation(ulint last_pages_in,
20252025
return(n_pages);
20262026
}
20272027

2028-
/******************************************************************//**
2029-
page_cleaner thread tasked with flushing dirty pages from the buffer
2030-
pools. As of now we'll have only one coordinator.
2031-
@return a dummy parameter */
2032-
static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
2028+
/** page_cleaner thread tasked with flushing dirty pages from the buffer
2029+
pools. As of now we'll have only one coordinator. */
2030+
static void buf_flush_page_cleaner()
20332031
{
20342032
my_thread_init();
20352033
#ifdef UNIV_PFS_THREAD
@@ -2253,11 +2251,10 @@ static os_thread_ret_t DECLARE_THREAD(buf_flush_page_cleaner)(void*)
22532251
mysql_mutex_unlock(&buf_pool.flush_list_mutex);
22542252

22552253
my_thread_end();
2256-
/* We count the number of threads in os_thread_exit(). A created
2257-
thread should always use that to exit and not use return() to exit. */
2258-
os_thread_exit();
22592254

2260-
OS_THREAD_DUMMY_RETURN;
2255+
#ifdef UNIV_PFS_THREAD
2256+
pfs_delete_thread();
2257+
#endif
22612258
}
22622259

22632260
/** Initialize page_cleaner. */
@@ -2269,7 +2266,7 @@ ATTRIBUTE_COLD void buf_flush_page_cleaner_init()
22692266
srv_operation == SRV_OPERATION_RESTORE_EXPORT);
22702267
buf_flush_sync_lsn= 0;
22712268
buf_page_cleaner_is_active= true;
2272-
os_thread_create(buf_flush_page_cleaner);
2269+
std::thread(buf_flush_page_cleaner).detach();
22732270
}
22742271

22752272
/** @return the number of dirty pages in the buffer pool */

storage/innobase/fil/fil0crypt.cc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,10 +2062,9 @@ static void fil_crypt_complete_rotate_space(rotate_thread_t* state)
20622062
mysql_mutex_unlock(&crypt_data->mutex);
20632063
}
20642064

2065-
/*********************************************************************//**
2066-
A thread which monitors global key state and rotates tablespaces accordingly
2067-
@return a dummy parameter */
2068-
static os_thread_ret_t DECLARE_THREAD(fil_crypt_thread)(void*)
2065+
/** A thread which monitors global key state and rotates tablespaces
2066+
accordingly */
2067+
static void fil_crypt_thread()
20692068
{
20702069
mysql_mutex_lock(&fil_crypt_threads_mutex);
20712070
rotate_thread_t thr(srv_n_fil_crypt_threads_started++);
@@ -2144,12 +2143,9 @@ static os_thread_ret_t DECLARE_THREAD(fil_crypt_thread)(void*)
21442143
pthread_cond_signal(&fil_crypt_cond); /* signal that we stopped */
21452144
mysql_mutex_unlock(&fil_crypt_threads_mutex);
21462145

2147-
/* We count the number of threads in os_thread_exit(). A created
2148-
thread should always use that to exit and not use return() to exit. */
2149-
2150-
os_thread_exit();
2151-
2152-
OS_THREAD_DUMMY_RETURN;
2146+
#ifdef UNIV_PFS_THREAD
2147+
pfs_delete_thread();
2148+
#endif
21532149
}
21542150

21552151
/*********************************************************************
@@ -2172,10 +2168,12 @@ fil_crypt_set_thread_cnt(
21722168
uint add = new_cnt - srv_n_fil_crypt_threads;
21732169
srv_n_fil_crypt_threads = new_cnt;
21742170
for (uint i = 0; i < add; i++) {
2171+
std::thread thd(fil_crypt_thread);
21752172
ib::info() << "Creating #"
21762173
<< i+1 << " encryption thread id "
2177-
<< os_thread_create(fil_crypt_thread)
2174+
<< thd.get_id()
21782175
<< " total threads " << new_cnt << ".";
2176+
thd.detach();
21792177
}
21802178
} else if (new_cnt < srv_n_fil_crypt_threads) {
21812179
srv_n_fil_crypt_threads = new_cnt;

storage/innobase/include/os0thread.h

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
33
Copyright (c) 1995, 2016, 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
@@ -28,48 +28,15 @@ Created 9/8/1995 Heikki Tuuri
2828
#pragma once
2929
#include "univ.i"
3030

31-
/* Possible fixed priorities for threads */
32-
#define OS_THREAD_PRIORITY_NONE 100
33-
#define OS_THREAD_PRIORITY_BACKGROUND 1
34-
#define OS_THREAD_PRIORITY_NORMAL 2
35-
#define OS_THREAD_PRIORITY_ABOVE_NORMAL 3
36-
3731
#ifdef _WIN32
38-
typedef DWORD os_thread_t;
3932
typedef DWORD os_thread_id_t; /*!< In Windows the thread id
4033
is an unsigned long int */
41-
extern "C" {
42-
typedef LPTHREAD_START_ROUTINE os_thread_func_t;
43-
}
44-
45-
/** Macro for specifying a Windows thread start function. */
46-
#define DECLARE_THREAD(func) WINAPI func
4734
#else
4835

49-
typedef pthread_t os_thread_t;
5036
typedef pthread_t os_thread_id_t; /*!< In Unix we use the thread
5137
handle itself as the id of
5238
the thread */
53-
extern "C" { typedef void* (*os_thread_func_t)(void*); }
54-
55-
/** Macro for specifying a POSIX thread start function. */
56-
#define DECLARE_THREAD(func) func
5739
#endif /* _WIN32 */
5840

59-
/* Define a function pointer type to use in a typecast */
60-
typedef void* (*os_posix_f_t) (void*);
61-
6241
#define os_thread_eq(a,b) IF_WIN(a == b, pthread_equal(a, b))
6342
#define os_thread_get_curr_id() IF_WIN(GetCurrentThreadId(), pthread_self())
64-
65-
/****************************************************************//**
66-
Creates a new thread of execution. The execution starts from
67-
the function given.
68-
NOTE: We count the number of threads in os_thread_exit(). A created
69-
thread should always use that to exit so thatthe thread count will be
70-
decremented.
71-
We do not return an error code because if there is one, we crash here. */
72-
os_thread_t os_thread_create(os_thread_func_t func, void *arg= nullptr);
73-
74-
/** Detach and terminate the current thread. */
75-
ATTRIBUTE_NORETURN void os_thread_exit();

storage/innobase/include/trx0roll.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ Rollback or clean up any incomplete transactions which were
5050
encountered in crash recovery. If the transaction already was
5151
committed, then we clean up a possible insert undo log. If the
5252
transaction was not yet committed, then we roll it back.
53-
Note: this is done in a background thread.
54-
@return a dummy parameter */
55-
extern "C"
56-
os_thread_ret_t
57-
DECLARE_THREAD(trx_rollback_all_recovered)(void*);
53+
Note: this is done in a background thread. */
54+
void trx_rollback_all_recovered(void*);
5855
/*********************************************************************//**
5956
Creates a rollback command node struct.
6057
@return own: rollback node struct */

storage/innobase/os/os0thread.cc

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -26,74 +26,3 @@ Created 9/8/1995 Heikki Tuuri
2626

2727
#include "univ.i"
2828
#include "srv0srv.h"
29-
30-
/****************************************************************//**
31-
Creates a new thread of execution. The execution starts from
32-
the function given.
33-
NOTE: We count the number of threads in os_thread_exit(). A created
34-
thread should always use that to exit so thatthe thread count will be
35-
decremented.
36-
We do not return an error code because if there is one, we crash here. */
37-
os_thread_t os_thread_create(os_thread_func_t func, void *arg)
38-
{
39-
os_thread_id_t new_thread_id;
40-
41-
#ifdef _WIN32
42-
HANDLE handle;
43-
44-
handle = CreateThread(NULL, /* no security attributes */
45-
0, /* default size stack */
46-
func,
47-
arg,
48-
0, /* thread runs immediately */
49-
&new_thread_id);
50-
51-
if (!handle) {
52-
/* If we cannot start a new thread, life has no meaning. */
53-
ib::fatal() << "CreateThread returned " << GetLastError();
54-
}
55-
56-
CloseHandle(handle);
57-
58-
return((os_thread_t)new_thread_id);
59-
#else /* _WIN32 else */
60-
61-
pthread_attr_t attr;
62-
63-
int ret = pthread_attr_init(&attr);
64-
if (UNIV_UNLIKELY(ret)) {
65-
fprintf(stderr,
66-
"InnoDB: Error: pthread_attr_init() returned %d\n",
67-
ret);
68-
abort();
69-
}
70-
71-
ret = pthread_create(&new_thread_id, &attr, func, arg);
72-
73-
ut_a(ret == 0);
74-
75-
pthread_attr_destroy(&attr);
76-
77-
#endif /* not _WIN32 */
78-
79-
return((os_thread_t)new_thread_id);
80-
}
81-
82-
/** Detach and terminate the current thread. */
83-
ATTRIBUTE_NORETURN void os_thread_exit()
84-
{
85-
#ifdef UNIV_DEBUG_THREAD_CREATION
86-
ib::info() << "Thread exits, id " << os_thread_get_curr_id();
87-
#endif
88-
89-
#ifdef UNIV_PFS_THREAD
90-
pfs_delete_thread();
91-
#endif
92-
93-
#ifdef _WIN32
94-
ExitThread(0);
95-
#else
96-
pthread_detach(pthread_self());
97-
pthread_exit(NULL);
98-
#endif
99-
}

0 commit comments

Comments
 (0)