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:
Andrew Gaul 2024-10-20 16:06:05 +09:00 committed by GitHub
parent 4b6e53223b
commit 8c5ac5c2d9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 15 additions and 20 deletions

View File

@ -96,7 +96,7 @@ constexpr char S3fsCurl::S3FS_SSL_PRIVKEY_PASSWORD[];
std::mutex S3fsCurl::curl_handles_lock;
S3fsCurl::callback_locks_t S3fsCurl::callback_locks;
bool S3fsCurl::is_initglobal_done = false;
CurlHandlerPool* S3fsCurl::sCurlPool = nullptr;
std::unique_ptr<CurlHandlerPool> S3fsCurl::sCurlPool;
int S3fsCurl::sCurlPoolSize = 32;
CURLSH* S3fsCurl::hCurlShare = nullptr;
bool S3fsCurl::is_cert_check = true; // default
@ -163,7 +163,7 @@ bool S3fsCurl::InitS3fsCurl()
// sCurlPoolSize must be over parallel(or multireq) count.
//
sCurlPoolSize = std::max({sCurlPoolSize, GetMaxParallelCount(), GetMaxMultiRequest()});
sCurlPool = new CurlHandlerPool(sCurlPoolSize);
sCurlPool.reset(new CurlHandlerPool(sCurlPoolSize));
if (!sCurlPool->Init()) {
return false;
}
@ -180,8 +180,7 @@ bool S3fsCurl::DestroyS3fsCurl()
if(!sCurlPool->Destroy()){
result = false;
}
delete sCurlPool;
sCurlPool = nullptr;
sCurlPool.reset();
if(!S3fsCurl::DestroyShareCurl()){
result = false;
}

View File

@ -131,7 +131,7 @@ class S3fsCurl
std::mutex ssl_session;
} callback_locks;
static bool is_initglobal_done;
static CurlHandlerPool* sCurlPool;
static std::unique_ptr<CurlHandlerPool> sCurlPool;
static int sCurlPoolSize;
static CURLSH* hCurlShare;
static bool is_cert_check;

View File

@ -82,7 +82,7 @@ struct CRYPTO_dynlock_value
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)
@ -138,7 +138,7 @@ bool s3fs_init_crypt_mutex()
return false;
}
}
s3fs_crypt_mutex = new std::mutex[CRYPTO_num_locks()];
s3fs_crypt_mutex.reset(new std::mutex[CRYPTO_num_locks()]);
// static lock
CRYPTO_set_locking_callback(s3fs_crypt_mutex_lock);
CRYPTO_set_id_callback(s3fs_crypt_get_threadid);
@ -163,8 +163,7 @@ bool s3fs_destroy_crypt_mutex()
CRYPTO_set_locking_callback(nullptr);
CRYPTO_cleanup_all_ex_data();
delete[] s3fs_crypt_mutex;
s3fs_crypt_mutex = nullptr;
s3fs_crypt_mutex.reset();
return true;
}

View File

@ -30,7 +30,7 @@
//------------------------------------------------
// ThreadPoolMan class variables
//------------------------------------------------
ThreadPoolMan* ThreadPoolMan::singleton = nullptr;
std::unique_ptr<ThreadPoolMan> ThreadPoolMan::singleton;
//------------------------------------------------
// ThreadPoolMan class methods
@ -38,19 +38,16 @@ ThreadPoolMan* ThreadPoolMan::singleton = nullptr;
bool ThreadPoolMan::Initialize(int count)
{
if(ThreadPoolMan::singleton){
S3FS_PRN_WARN("Already singleton for Thread Manager is existed, then re-create it.");
ThreadPoolMan::Destroy();
S3FS_PRN_CRIT("Already singleton for Thread Manager exists.");
abort();
}
ThreadPoolMan::singleton = new ThreadPoolMan(count);
ThreadPoolMan::singleton.reset(new ThreadPoolMan(count));
return true;
}
void ThreadPoolMan::Destroy()
{
if(ThreadPoolMan::singleton){
delete ThreadPoolMan::singleton;
ThreadPoolMan::singleton = nullptr;
}
ThreadPoolMan::singleton.reset();
}
bool ThreadPoolMan::Instruct(const thpoolman_param& param)
@ -119,7 +116,7 @@ ThreadPoolMan::ThreadPoolMan(int count) : is_exit(false), thpoolman_sem(0)
abort();
}
if(ThreadPoolMan::singleton){
S3FS_PRN_CRIT("Already singleton for Thread Manager is existed.");
S3FS_PRN_CRIT("Already singleton for Thread Manager exists.");
abort();
}

View File

@ -61,7 +61,7 @@ typedef std::list<thpoolman_param> thpoolman_params_t;
class ThreadPoolMan
{
private:
static ThreadPoolMan* singleton;
static std::unique_ptr<ThreadPoolMan> singleton;
std::atomic<bool> is_exit;
Semaphore thpoolman_sem;
@ -74,7 +74,6 @@ class ThreadPoolMan
static void Worker(ThreadPoolMan* psingleton, std::promise<int> promise);
explicit ThreadPoolMan(int count = 1);
~ThreadPoolMan();
bool IsExit() const;
void SetExitFlag(bool exit_flag);
@ -84,6 +83,7 @@ class ThreadPoolMan
void SetInstruction(const thpoolman_param& pparam);
public:
~ThreadPoolMan();
ThreadPoolMan(const ThreadPoolMan&) = delete;
ThreadPoolMan(ThreadPoolMan&&) = delete;
ThreadPoolMan& operator=(const ThreadPoolMan&) = delete;