no message
parent
22d1d4178a
commit
8d8b9839e5
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Author: caiyuzheng
|
* @Author: caiyuzheng
|
||||||
* @Date: 2021-10-06 23:05:26
|
* @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
|
* @LastEditors: Please set LastEditors
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: \generallib\general\src\threadsafe\thread_safe_list.h
|
* @FilePath: \generallib\general\src\threadsafe\thread_safe_list.h
|
||||||
|
@ -74,8 +74,8 @@ public:
|
||||||
m_mux.unlock();
|
m_mux.unlock();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
using vIterator = typename std::list<T>::iterator;
|
||||||
T PopFront()
|
vIterator PopFront()
|
||||||
{
|
{
|
||||||
if (!m_data.empty())
|
if (!m_data.empty())
|
||||||
{
|
{
|
||||||
|
@ -84,9 +84,11 @@ public:
|
||||||
auto ret1 = *ret;
|
auto ret1 = *ret;
|
||||||
m_data.erase(ret);
|
m_data.erase(ret);
|
||||||
m_mux.unlock();
|
m_mux.unlock();
|
||||||
return ret1;
|
|
||||||
}
|
}
|
||||||
|
return m_data.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
T PopFrontAndWait()
|
T PopFrontAndWait()
|
||||||
{
|
{
|
||||||
if (!m_data.empty())
|
if (!m_data.empty())
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* @Author: your name
|
* @Author: your name
|
||||||
* @Date: 2021-03-15 23:07:25
|
* @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
|
* @LastEditors: Please set LastEditors
|
||||||
* @Description: In User Settings Edit
|
* @Description: In User Settings Edit
|
||||||
* @FilePath: \cpp11\cpp11_test.cpp
|
* @FilePath: \cpp11\cpp11_test.cpp
|
||||||
|
@ -35,10 +35,11 @@ int main(int argc, char **argv)
|
||||||
ip.PushFront(102);
|
ip.PushFront(102);
|
||||||
ip.PushFront(111);
|
ip.PushFront(111);
|
||||||
|
|
||||||
void *p = &ip;
|
ThreadSafeList<int> *p = &ip;
|
||||||
std::thread t1([p]{
|
std::thread t1([p]{
|
||||||
Sleep(4000);
|
Sleep(4000);
|
||||||
((ThreadSafeList<int>*)p)->PushFront(123);
|
((ThreadSafeList<int>*)p)->PushFront(123);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
std::cout<<ip.PopFrontAndWait()<<"\r\n";
|
||||||
|
|
Loading…
Reference in New Issue