Skip to content

Commit

Permalink
minor modify
Browse files Browse the repository at this point in the history
  • Loading branch information
loveyacper committed Jun 29, 2018
1 parent ddc5d84 commit 60e033b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
7 changes: 3 additions & 4 deletions cpp/util/include/util/tc_lockfree_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,12 @@ class LockFreeQueue
{
bsuccess = __sync_bool_compare_and_swap(&(((Entry*)&(_head[1]))[pos].flag), FLAG_NULL, FLAG_SETTOOK);
}while(false == bsuccess);

((Entry*)&(_head[1]))[pos].data = val;
__sync_synchronize();

((Entry*)&(_head[1]))[pos].flag = FLAG_SETED;

__sync_synchronize();

return RT_OK;
}

Expand Down Expand Up @@ -165,10 +164,10 @@ class LockFreeQueue
}while(false == bsuccess);

val = ((Entry*)&(_head[1]))[pos].data;
__sync_synchronize();

((Entry*)&(_head[1]))[pos].flag = FLAG_NULL;

__sync_synchronize();
return RT_OK;
}

Expand Down
5 changes: 1 addition & 4 deletions cpp/util/src/tc_epoller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ void TC_Epoller::create(int max_connections)

_iEpollfd = epoll_create(_max_connections + 1);

if(_pevs != NULL)
{
delete[] _pevs;
}
delete[] _pevs;

_pevs = new epoll_event[_max_connections + 1];
}
Expand Down
13 changes: 10 additions & 3 deletions cpp/util/src/tc_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,23 @@ string TC_File::simplifyDirectory(const string& path)

string TC_File::load2str(const string &sFullFileName)
{
ifstream ifs(sFullFileName.c_str());
ifstream ifs(sFullFileName.c_str(), std::ios_base::binary);
if (ifs.bad())
return "";

return string(istreambuf_iterator<char>(ifs), istreambuf_iterator<char>());
std::string s((istreambuf_iterator<char>(ifs)), istreambuf_iterator<char>());
ifs.close();

return s;
}

void TC_File::load2str(const string &sFullFileName, vector<char> &buffer)
{
buffer.clear();

ifstream ifs(sFullFileName.c_str());
ifstream ifs(sFullFileName.c_str(), std::ios_base::binary);
if (ifs.bad())
return;

buffer.insert(buffer.end(), istreambuf_iterator<char>(ifs), istreambuf_iterator<char>());
}
Expand Down
5 changes: 1 addition & 4 deletions cpp/util/src/tc_thread_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ pthread_key_t TC_ThreadPool::g_key;
void TC_ThreadPool::destructor(void *p)
{
ThreadData *ttd = (ThreadData*)p;
if(ttd)
{
delete ttd;
}
delete ttd;
}

void TC_ThreadPool::exit()
Expand Down

0 comments on commit 60e033b

Please sign in to comment.