mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 01:08:54 +00:00
Remove more raw pointers (#2556)
Make destructor public so std::unique_ptr can call it. Also restrict singleton creation to satisfy cppcheck.
This commit is contained in:
parent
4b6e53223b
commit
8c5ac5c2d9
@ -96,7 +96,7 @@ constexpr char S3fsCurl::S3FS_SSL_PRIVKEY_PASSWORD[];
|
|||||||
std::mutex S3fsCurl::curl_handles_lock;
|
std::mutex S3fsCurl::curl_handles_lock;
|
||||||
S3fsCurl::callback_locks_t S3fsCurl::callback_locks;
|
S3fsCurl::callback_locks_t S3fsCurl::callback_locks;
|
||||||
bool S3fsCurl::is_initglobal_done = false;
|
bool S3fsCurl::is_initglobal_done = false;
|
||||||
CurlHandlerPool* S3fsCurl::sCurlPool = nullptr;
|
std::unique_ptr<CurlHandlerPool> S3fsCurl::sCurlPool;
|
||||||
int S3fsCurl::sCurlPoolSize = 32;
|
int S3fsCurl::sCurlPoolSize = 32;
|
||||||
CURLSH* S3fsCurl::hCurlShare = nullptr;
|
CURLSH* S3fsCurl::hCurlShare = nullptr;
|
||||||
bool S3fsCurl::is_cert_check = true; // default
|
bool S3fsCurl::is_cert_check = true; // default
|
||||||
@ -163,7 +163,7 @@ bool S3fsCurl::InitS3fsCurl()
|
|||||||
// sCurlPoolSize must be over parallel(or multireq) count.
|
// sCurlPoolSize must be over parallel(or multireq) count.
|
||||||
//
|
//
|
||||||
sCurlPoolSize = std::max({sCurlPoolSize, GetMaxParallelCount(), GetMaxMultiRequest()});
|
sCurlPoolSize = std::max({sCurlPoolSize, GetMaxParallelCount(), GetMaxMultiRequest()});
|
||||||
sCurlPool = new CurlHandlerPool(sCurlPoolSize);
|
sCurlPool.reset(new CurlHandlerPool(sCurlPoolSize));
|
||||||
if (!sCurlPool->Init()) {
|
if (!sCurlPool->Init()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -180,8 +180,7 @@ bool S3fsCurl::DestroyS3fsCurl()
|
|||||||
if(!sCurlPool->Destroy()){
|
if(!sCurlPool->Destroy()){
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
delete sCurlPool;
|
sCurlPool.reset();
|
||||||
sCurlPool = nullptr;
|
|
||||||
if(!S3fsCurl::DestroyShareCurl()){
|
if(!S3fsCurl::DestroyShareCurl()){
|
||||||
result = false;
|
result = false;
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ class S3fsCurl
|
|||||||
std::mutex ssl_session;
|
std::mutex ssl_session;
|
||||||
} callback_locks;
|
} callback_locks;
|
||||||
static bool is_initglobal_done;
|
static bool is_initglobal_done;
|
||||||
static CurlHandlerPool* sCurlPool;
|
static std::unique_ptr<CurlHandlerPool> sCurlPool;
|
||||||
static int sCurlPoolSize;
|
static int sCurlPoolSize;
|
||||||
static CURLSH* hCurlShare;
|
static CURLSH* hCurlShare;
|
||||||
static bool is_cert_check;
|
static bool is_cert_check;
|
||||||
|
@ -82,7 +82,7 @@ struct CRYPTO_dynlock_value
|
|||||||
std::mutex dyn_mutex;
|
std::mutex dyn_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::mutex* s3fs_crypt_mutex = nullptr;
|
static std::unique_ptr<std::mutex[]> s3fs_crypt_mutex;
|
||||||
|
|
||||||
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line) __attribute__ ((unused)) NO_THREAD_SAFETY_ANALYSIS;
|
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line) __attribute__ ((unused)) NO_THREAD_SAFETY_ANALYSIS;
|
||||||
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line)
|
static void s3fs_crypt_mutex_lock(int mode, int pos, const char* file, int line)
|
||||||
@ -138,7 +138,7 @@ bool s3fs_init_crypt_mutex()
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s3fs_crypt_mutex = new std::mutex[CRYPTO_num_locks()];
|
s3fs_crypt_mutex.reset(new std::mutex[CRYPTO_num_locks()]);
|
||||||
// static lock
|
// static lock
|
||||||
CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);
|
CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);
|
||||||
CRYPTO_set_id_callback(s3fs_crypt_get_threadid);
|
CRYPTO_set_id_callback(s3fs_crypt_get_threadid);
|
||||||
@ -163,8 +163,7 @@ bool s3fs_destroy_crypt_mutex()
|
|||||||
CRYPTO_set_locking_callback(nullptr);
|
CRYPTO_set_locking_callback(nullptr);
|
||||||
|
|
||||||
CRYPTO_cleanup_all_ex_data();
|
CRYPTO_cleanup_all_ex_data();
|
||||||
delete[] s3fs_crypt_mutex;
|
s3fs_crypt_mutex.reset();
|
||||||
s3fs_crypt_mutex = nullptr;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
// ThreadPoolMan class variables
|
// ThreadPoolMan class variables
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
ThreadPoolMan* ThreadPoolMan::singleton = nullptr;
|
std::unique_ptr<ThreadPoolMan> ThreadPoolMan::singleton;
|
||||||
|
|
||||||
//------------------------------------------------
|
//------------------------------------------------
|
||||||
// ThreadPoolMan class methods
|
// ThreadPoolMan class methods
|
||||||
@ -38,19 +38,16 @@ ThreadPoolMan* ThreadPoolMan::singleton = nullptr;
|
|||||||
bool ThreadPoolMan::Initialize(int count)
|
bool ThreadPoolMan::Initialize(int count)
|
||||||
{
|
{
|
||||||
if(ThreadPoolMan::singleton){
|
if(ThreadPoolMan::singleton){
|
||||||
S3FS_PRN_WARN("Already singleton for Thread Manager is existed, then re-create it.");
|
S3FS_PRN_CRIT("Already singleton for Thread Manager exists.");
|
||||||
ThreadPoolMan::Destroy();
|
abort();
|
||||||
}
|
}
|
||||||
ThreadPoolMan::singleton = new ThreadPoolMan(count);
|
ThreadPoolMan::singleton.reset(new ThreadPoolMan(count));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ThreadPoolMan::Destroy()
|
void ThreadPoolMan::Destroy()
|
||||||
{
|
{
|
||||||
if(ThreadPoolMan::singleton){
|
ThreadPoolMan::singleton.reset();
|
||||||
delete ThreadPoolMan::singleton;
|
|
||||||
ThreadPoolMan::singleton = nullptr;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ThreadPoolMan::Instruct(const thpoolman_param& param)
|
bool ThreadPoolMan::Instruct(const thpoolman_param& param)
|
||||||
@ -119,7 +116,7 @@ ThreadPoolMan::ThreadPoolMan(int count) : is_exit(false), thpoolman_sem(0)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
if(ThreadPoolMan::singleton){
|
if(ThreadPoolMan::singleton){
|
||||||
S3FS_PRN_CRIT("Already singleton for Thread Manager is existed.");
|
S3FS_PRN_CRIT("Already singleton for Thread Manager exists.");
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ typedef std::list<thpoolman_param> thpoolman_params_t;
|
|||||||
class ThreadPoolMan
|
class ThreadPoolMan
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static ThreadPoolMan* singleton;
|
static std::unique_ptr<ThreadPoolMan> singleton;
|
||||||
|
|
||||||
std::atomic<bool> is_exit;
|
std::atomic<bool> is_exit;
|
||||||
Semaphore thpoolman_sem;
|
Semaphore thpoolman_sem;
|
||||||
@ -74,7 +74,6 @@ class ThreadPoolMan
|
|||||||
static void Worker(ThreadPoolMan* psingleton, std::promise<int> promise);
|
static void Worker(ThreadPoolMan* psingleton, std::promise<int> promise);
|
||||||
|
|
||||||
explicit ThreadPoolMan(int count = 1);
|
explicit ThreadPoolMan(int count = 1);
|
||||||
~ThreadPoolMan();
|
|
||||||
|
|
||||||
bool IsExit() const;
|
bool IsExit() const;
|
||||||
void SetExitFlag(bool exit_flag);
|
void SetExitFlag(bool exit_flag);
|
||||||
@ -84,6 +83,7 @@ class ThreadPoolMan
|
|||||||
void SetInstruction(const thpoolman_param& pparam);
|
void SetInstruction(const thpoolman_param& pparam);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~ThreadPoolMan();
|
||||||
ThreadPoolMan(const ThreadPoolMan&) = delete;
|
ThreadPoolMan(const ThreadPoolMan&) = delete;
|
||||||
ThreadPoolMan(ThreadPoolMan&&) = delete;
|
ThreadPoolMan(ThreadPoolMan&&) = delete;
|
||||||
ThreadPoolMan& operator=(const ThreadPoolMan&) = delete;
|
ThreadPoolMan& operator=(const ThreadPoolMan&) = delete;
|
||||||
|
Loading…
Reference in New Issue
Block a user