Skip to content

Commit

Permalink
fix: tools compile failed (OpenAtomFoundation#1483)
Browse files Browse the repository at this point in the history
* fix: tools compile failed

* replace NULL with nullptr
  • Loading branch information
4kangjc authored May 11, 2023
1 parent 0ae1952 commit 1f1a0fd
Show file tree
Hide file tree
Showing 31 changed files with 221 additions and 301 deletions.
8 changes: 4 additions & 4 deletions src/net/examples/bg_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static pstd::Mutex print_lock;

void task(void* arg) {
{
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " task : " << *((int*)arg) << std::endl;
}
sleep(1);
Expand All @@ -42,7 +42,7 @@ int main() {
int* pi = new int(i);
t.Schedule(task, (void*)pi);
t.QueueSize(&pqsize, &qsize);
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " current queue size:" << qsize << ", " << pqsize << std::endl;
}
std::cout << std::endl << std::endl;
Expand All @@ -58,7 +58,7 @@ int main() {
int* pi = new int(i);
t2.Schedule(task, (void*)pi);
t2.QueueSize(&pqsize, &qsize);
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " current queue size:" << qsize << ", " << pqsize << std::endl;
}
std::cout << std::endl << std::endl;
Expand Down Expand Up @@ -90,7 +90,7 @@ int main() {
int* pi = new int(i);
t.DelaySchedule(i * 1000, task, (void*)pi);
t.QueueSize(&pqsize, &qsize);
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " current queue size:" << qsize << ", " << pqsize << std::endl;
}
sleep(3);
Expand Down
8 changes: 4 additions & 4 deletions src/net/examples/thread_pool_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static pstd::Mutex print_lock;

void task(void* arg) {
{
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " task : " << *((int*)arg) << " time(micros) " << NowMicros() << " thread id: " << pthread_self()
<< std::endl;
}
Expand All @@ -46,7 +46,7 @@ int main() {
t.Schedule(task, (void*)pi);
t.cur_queue_size(&qsize);
t.cur_time_queue_size(&pqsize);
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " current queue size:" << qsize << ", " << pqsize << std::endl;
}

Expand All @@ -66,7 +66,7 @@ int main() {
t.DelaySchedule(i * 1000, task, (void*)pi);
t.cur_queue_size(&qsize);
t.cur_time_queue_size(&pqsize);
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << "Schedule task " << i << " time(micros) " << NowMicros() << " for " << i * 1000 * 1000 << " micros "
<< std::endl;
}
Expand All @@ -85,7 +85,7 @@ int main() {
t.DelaySchedule(i * 1000, task, (void*)pi);
t.cur_queue_size(&qsize);
t.cur_time_queue_size(&pqsize);
pstd::MutexLock l(&print_lock);
std::lock_guard l(print_lock);
std::cout << " current queue size:" << qsize << ", " << pqsize << std::endl;
}
sleep(3);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/redis_sets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ rocksdb::Status RedisSets::SPop(const Slice& key, std::vector<std::string>* memb
delete iter;

} else {
engine.seed(time(NULL));
engine.seed(time(nullptr));
int32_t cur_index = 0;
int32_t size = parsed_sets_meta_value.count();
int32_t target_index = -1;
Expand Down
4 changes: 2 additions & 2 deletions tools/aof_to_pika/src/aof_lock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ static void PthreadCall(const std::string& label, int result) {
}
}

Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, NULL)); }
Mutex::Mutex() { PthreadCall("init mutex", pthread_mutex_init(&mu_, nullptr)); }

Mutex::~Mutex() { PthreadCall("destroy mutex", pthread_mutex_destroy(&mu_)); }

void Mutex::Lock() { PthreadCall("lock", pthread_mutex_lock(&mu_)); }

void Mutex::Unlock() { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); }

CondVar::CondVar(Mutex* mu) : mu_(mu) { PthreadCall("init cv", pthread_cond_init(&cv_, NULL)); }
CondVar::CondVar(Mutex* mu) : mu_(mu) { PthreadCall("init cv", pthread_cond_init(&cv_, nullptr)); }

CondVar::~CondVar() { PthreadCall("destroy cv", pthread_cond_destroy(&cv_)); }

Expand Down
8 changes: 4 additions & 4 deletions tools/aof_to_pika/src/aof_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define EOFMSG "EOAOF"

static std::time_t begin_time;
static AOFSender* sender = NULL;
static AOFSender* sender = nullptr;

static void split_send(const std::string& line) {
static std::string send_buf_;
Expand Down Expand Up @@ -93,7 +93,7 @@ static int file_read(const std::string& path) {

static void* msg_process(void* p) {
sender->process();
pthread_exit(NULL);
pthread_exit(nullptr);
}

void intHandler(int sig) {
Expand Down Expand Up @@ -176,7 +176,7 @@ int main(int argc, char** argv) {
int ret = 0;
pthread_t send_thread;
// Send thread
ret = pthread_create(&send_thread, NULL, msg_process, NULL);
ret = pthread_create(&send_thread, nullptr, msg_process, nullptr);
if (0 != ret) {
LOG_ERR("Failed to create assist_watcher_thread!");
delete sender;
Expand All @@ -186,7 +186,7 @@ int main(int argc, char** argv) {
// Main thread
file_read(path);

pthread_join(send_thread, NULL);
pthread_join(send_thread, nullptr);
delete sender;
return 0;
}
4 changes: 2 additions & 2 deletions tools/aof_to_pika/src/aof_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ bool AOFSender::rconnect(const std::string& host, const std::string& port, const
return false;
}

for (p = servinfo; p != NULL; p = p->ai_next) {
for (p = servinfo; p != nullptr; p = p->ai_next) {
if ((s = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) continue;
// connect
if (connect(s, p->ai_addr, p->ai_addrlen) < 0) {
Expand Down Expand Up @@ -58,7 +58,7 @@ AOFSender::~AOFSender() {
buf_rcond_.SignalAll();
buf_wcond_.SignalAll();
buf_mutex_.Unlock();
if (conn_info_ != NULL) delete conn_info_;
if (conn_info_ != nullptr) delete conn_info_;
close(sockfd_);
}

Expand Down
48 changes: 24 additions & 24 deletions tools/benchmark_client/benchmark_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,37 +92,37 @@ std::vector<ThreadArg> thread_args;
void* ThreadMain(void* arg) {
ThreadArg* ta = reinterpret_cast<ThreadArg*>(arg);
redisContext* c;
redisReply* res = NULL;
redisReply* res = nullptr;
struct timeval timeout = {1, 500000}; // 1.5 seconds
c = redisConnectWithTimeout(hostname.data(), port, timeout);

if (c == NULL || c->err) {
if (c == nullptr || c->err) {
if (c) {
printf("Thread %lu, Connection error: %s\n", ta->tid, c->errstr);
redisFree(c);
} else {
printf("Thread %lu, Connection error: can't allocate redis context\n", ta->tid);
}
return NULL;
return nullptr;
}

if (!password.empty()) {
const char* auth_argv[2] = {"AUTH", password.data()};
size_t auth_argv_len[2] = {4, password.size()};
res = reinterpret_cast<redisReply*>(redisCommandArgv(c, 2, reinterpret_cast<const char**>(auth_argv),
reinterpret_cast<const size_t*>(auth_argv_len)));
if (res == NULL) {
if (res == nullptr) {
printf("Thread %lu Auth Failed, Get reply Error\n", ta->tid);
freeReplyObject(res);
redisFree(c);
return NULL;
return nullptr;
} else {
if (!strcasecmp(res->str, "OK")) {
} else {
printf("Thread %lu Auth Failed: %s, thread exit...\n", ta->idx, res->str);
freeReplyObject(res);
redisFree(c);
return NULL;
return nullptr;
}
}
freeReplyObject(res);
Expand All @@ -132,19 +132,19 @@ void* ThreadMain(void* arg) {
size_t select_argv_len[2] = {6, ta->table_name.size()};
res = reinterpret_cast<redisReply*>(redisCommandArgv(c, 2, reinterpret_cast<const char**>(select_argv),
reinterpret_cast<const size_t*>(select_argv_len)));
if (res == NULL) {
if (res == nullptr) {
printf("Thread %lu Select Table %s Failed, Get reply Error\n", ta->tid, ta->table_name.data());
freeReplyObject(res);
redisFree(c);
return NULL;
return nullptr;
} else {
if (!strcasecmp(res->str, "OK")) {
printf("Table %s Thread %lu Select DB Success, start to write data...\n", ta->table_name.data(), ta->idx);
} else {
printf("Table %s Thread %lu Select DB Failed: %s, thread exit...\n", ta->table_name.data(), ta->idx, res->str);
freeReplyObject(res);
redisFree(c);
return NULL;
return nullptr;
}
}
freeReplyObject(res);
Expand All @@ -155,26 +155,26 @@ void* ThreadMain(void* arg) {
std::string thread_info = "Table " + ta->table_name + ", Thread " + std::to_string(ta->idx);
printf("%s, %s, thread exit...\n", thread_info.c_str(), s.ToString().c_str());
redisFree(c);
return NULL;
return nullptr;
}
} else if (transmit_mode == kPipeline) {
Status s = RunSetCommandPipeline(c);
if (!s.ok()) {
std::string thread_info = "Table " + ta->table_name + ", Thread " + std::to_string(ta->idx);
printf("%s, %s, thread exit...\n", thread_info.c_str(), s.ToString().c_str());
redisFree(c);
return NULL;
return nullptr;
}
}

redisFree(c);
return NULL;
return nullptr;
}

Status RunSetCommandPipeline(redisContext* c) {
redisReply* res = NULL;
redisReply* res = nullptr;
for (size_t idx = 0; idx < number_of_request; (idx += pipeline_num)) {
const char* argv[3] = {"SET", NULL, NULL};
const char* argv[3] = {"SET", nullptr, nullptr};
size_t argv_len[3] = {3, 0, 0};
for (int32_t batch_idx = 0; batch_idx < pipeline_num; ++batch_idx) {
std::string key;
Expand Down Expand Up @@ -202,8 +202,8 @@ Status RunSetCommandPipeline(redisContext* c) {
if (redisGetReply(c, reinterpret_cast<void**>(&res)) == REDIS_ERR) {
return Status::Corruption("Redis Pipeline Get Reply Error");
} else {
if (res == NULL || strcasecmp(res->str, "OK")) {
std::string res_str = "Exec command error: " + (res != NULL ? std::string(res->str) : "");
if (res == nullptr || strcasecmp(res->str, "OK")) {
std::string res_str = "Exec command error: " + (res != nullptr ? std::string(res->str) : "");
freeReplyObject(res);
return Status::Corruption(res_str);
}
Expand All @@ -215,7 +215,7 @@ Status RunSetCommandPipeline(redisContext* c) {
}

Status RunSetCommand(redisContext* c) {
redisReply* res = NULL;
redisReply* res = nullptr;
for (size_t idx = 0; idx < number_of_request; ++idx) {
const char* set_argv[3];
size_t set_argvlen[3];
Expand All @@ -238,8 +238,8 @@ Status RunSetCommand(redisContext* c) {

res = reinterpret_cast<redisReply*>(
redisCommandArgv(c, 3, reinterpret_cast<const char**>(set_argv), reinterpret_cast<const size_t*>(set_argvlen)));
if (res == NULL || strcasecmp(res->str, "OK")) {
std::string res_str = "Exec command error: " + (res != NULL ? std::string(res->str) : "");
if (res == nullptr || strcasecmp(res->str, "OK")) {
std::string res_str = "Exec command error: " + (res != nullptr ? std::string(res->str) : "");
freeReplyObject(res);
return Status::Corruption(res_str);
}
Expand All @@ -249,7 +249,7 @@ Status RunSetCommand(redisContext* c) {
}

Status RunZAddCommand(redisContext* c) {
redisReply* res = NULL;
redisReply* res = nullptr;
for (size_t idx = 0; idx < 1; ++idx) {
const char* zadd_argv[4];
size_t zadd_argvlen[4];
Expand All @@ -272,8 +272,8 @@ Status RunZAddCommand(redisContext* c) {

res = reinterpret_cast<redisReply*>(redisCommandArgv(c, 4, reinterpret_cast<const char**>(zadd_argv),
reinterpret_cast<const size_t*>(zadd_argvlen)));
if (res == NULL || res->integer == 0) {
std::string res_str = "Exec command error: " + (res != NULL ? std::string(res->str) : "");
if (res == nullptr || res->integer == 0) {
std::string res_str = "Exec command error: " + (res != nullptr ? std::string(res->str) : "");
freeReplyObject(res);
return Status::Corruption(res_str);
}
Expand Down Expand Up @@ -339,11 +339,11 @@ int main(int argc, char* argv[]) {
}

for (size_t idx = 0; idx < thread_args.size(); ++idx) {
pthread_create(&thread_args[idx].tid, NULL, ThreadMain, &thread_args[idx]);
pthread_create(&thread_args[idx].tid, nullptr, ThreadMain, &thread_args[idx]);
}

for (size_t idx = 0; idx < thread_args.size(); ++idx) {
pthread_join(thread_args[idx].tid, NULL);
pthread_join(thread_args[idx].tid, nullptr);
}

std::chrono::system_clock::time_point end_time = std::chrono::system_clock::now();
Expand Down
2 changes: 1 addition & 1 deletion tools/binlog_sender/binlog_consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pstd::Status BinlogConsumer::Parse(std::string* scratch) {
if (pstd::FileExists(confile)) {
// DLOG(INFO) << "BinlogSender roll to new binlog" << confile;
delete queue_;
queue_ = NULL;
queue_ = nullptr;

pstd::NewSequentialFile(confile, &queue_);

Expand Down
2 changes: 1 addition & 1 deletion tools/binlog_sender/binlog_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ int main(int argc, char* argv[]) {
if (tv_start <= binlog_item.exec_time() && binlog_item.exec_time() <= tv_end) {
Status net_s = cli->Send(&redis_cmd);
if (net_s.ok()) {
net_s = cli->Recv(NULL);
net_s = cli->Recv(nullptr);
if (net_s.ok()) {
success_num++;
} else {
Expand Down
2 changes: 1 addition & 1 deletion tools/binlog_sender/progress_thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ void* ProgressThread::ThreadMain() {
fflush(stdout);
}
printf("\n");
return NULL;
return nullptr;
}
10 changes: 5 additions & 5 deletions tools/manifest_generator/include/pika_binlog.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ class Version {
uint64_t pro_offset_;
uint64_t logic_id_;

pthread_rwlock_t rwlock_;
std::shared_mutex rwlock_;

void debug() {
pstd::RWLock(&rwlock_, false);
std::shared_lock l(rwlock_);
printf("Current pro_num %u pro_offset %lu\n", pro_num_, pro_offset_);
}

Expand All @@ -51,13 +51,13 @@ class Binlog {
Binlog(const std::string& Binlog_path, const int file_size = 100 * 1024 * 1024);
~Binlog();

void Lock() { mutex_.Lock(); }
void Unlock() { mutex_.Unlock(); }
void Lock() { mutex_.lock(); }
void Unlock() { mutex_.unlock(); }

Status Put(const std::string& item);
Status Put(const char* item, int len);

Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint64_t* logic_id = NULL);
Status GetProducerStatus(uint32_t* filenum, uint64_t* pro_offset, uint64_t* logic_id = nullptr);
/*
* Set Producer pro_num and pro_offset with lock
*/
Expand Down
Loading

0 comments on commit 1f1a0fd

Please sign in to comment.