Skip to content

Commit 5d30402

Browse files
committed
在苹果上使用普通thread
1 parent b80e3a1 commit 5d30402

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

CodeFormatServer/src/Session/IOSession.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,19 @@ IOSession::~IOSession()
1818
{
1919
if(_logicThread)
2020
{
21+
#ifndef __APPLE__
2122
_logicThread->request_stop();
23+
#else
24+
_running = false;
25+
_logicThread->join();
26+
#endif
2227
}
2328
}
2429

2530
int IOSession::Run(asio::io_context& ioc)
2631
{
32+
//Æ»¹ûÔÝδ֧³Ö Õâ¸öjthread
33+
#ifndef __APPLE__
2734
_logicThread = std::make_shared<std::jthread>([&ioc](std::stop_token st)
2835
{
2936
while (!st.stop_requested())
@@ -33,6 +40,17 @@ int IOSession::Run(asio::io_context& ioc)
3340
std::this_thread::sleep_for(std::chrono::milliseconds(1));
3441
}
3542
});
43+
#else
44+
_logicThread = std::make_shared<std::thread>([&ioc, this]()
45+
{
46+
while (_running)
47+
{
48+
ioc.run();
49+
ioc.reset();
50+
std::this_thread::sleep_for(std::chrono::milliseconds(1));
51+
}
52+
});
53+
#endif
3654

3755
return 0;
3856
}

LuaParser/src/LuaIdentify.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#pragma once
2-
3-
#include "LuaParser/LuaIdentify.h"
1+
#include "LuaParser/LuaIdentify.h"
42
#include "LuaDefine.h"
53

64
std::array<unsigned char, UCHAR_MAX + 2> LuaIdentify::LuaCharType = {

include/CodeFormatServer/Session/IOSession.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ class IOSession
1919
ProtocolBuffer _protocolBuffer;
2020
private:
2121
LanguageService _service;
22+
#ifndef __APPLE__
2223
std::shared_ptr<std::jthread> _logicThread;
24+
#else
25+
std::shared_ptr<std::thread> _logicThread = nullptr;
26+
volatile bool _running = true;
27+
#endif
28+
2329
};

0 commit comments

Comments
 (0)