no message

master
zcy 2021-11-17 17:25:49 +08:00
parent 22d1d4178a
commit 8d8b9839e5
2 changed files with 21 additions and 18 deletions

View File

@ -1,7 +1,7 @@
/*
* @Author: caiyuzheng
* @Date: 2021-10-06 23:05:26
* @LastEditTime: 2021-11-17 17:06:03
* @LastEditTime: 2021-11-17 17:24:46
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \generallib\general\src\threadsafe\thread_safe_list.h
@ -60,22 +60,22 @@ public:
m_mux.unlock();
return 0;
}
int EmplaceEnd(T v)
int EmplaceEnd(T v)
{
m_mux.lock();
auto itr = m_data.begin();
for (int i = 0; itr != m_data.end(), itr++)
{
m_mux.lock();
auto itr = m_data.begin();
for (int i = 0; itr != m_data.end(), itr++)
{
i++;
if (i == pos)
break;
}
m_data.emplace(itr, v);
m_mux.unlock();
return 0;
i++;
if (i == pos)
break;
}
T PopFront()
m_data.emplace(itr, v);
m_mux.unlock();
return 0;
}
using vIterator = typename std::list<T>::iterator;
vIterator PopFront()
{
if (!m_data.empty())
{
@ -84,9 +84,11 @@ public:
auto ret1 = *ret;
m_data.erase(ret);
m_mux.unlock();
return ret1;
}
return m_data.end();
}
T PopFrontAndWait()
{
if (!m_data.empty())

View File

@ -1,7 +1,7 @@
/*
* @Author: your name
* @Date: 2021-03-15 23:07:25
* @LastEditTime: 2021-11-17 17:05:44
* @LastEditTime: 2021-11-17 17:17:37
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \cpp11\cpp11_test.cpp
@ -35,10 +35,11 @@ int main(int argc, char **argv)
ip.PushFront(102);
ip.PushFront(111);
void *p = &ip;
ThreadSafeList<int> *p = &ip;
std::thread t1([p]{
Sleep(4000);
((ThreadSafeList<int>*)p)->PushFront(123);
});
std::cout<<ip.PopFrontAndWait()<<"\r\n";