Skip to content

Commit b80e3a1

Browse files
committed
增加一个退出线程的步骤
1 parent 920abfb commit b80e3a1

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

CodeFormatServer/src/LanguageClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ int LanguageClient::Run(std::shared_ptr<asio::io_context> ioc)
208208
_ioc = ioc;
209209
if (_session)
210210
{
211-
return _session->Run(*ioc);
211+
int ret = _session->Run(*ioc);
212+
_session = nullptr;
213+
return ret;
212214
}
213215
return 1;
214216
}

CodeFormatServer/src/Session/IOSession.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,43 +16,45 @@ IOSession::IOSession()
1616

1717
IOSession::~IOSession()
1818
{
19+
if(_logicThread)
20+
{
21+
_logicThread->request_stop();
22+
}
1923
}
2024

2125
int IOSession::Run(asio::io_context& ioc)
2226
{
23-
std::thread t([&ioc]()
27+
_logicThread = std::make_shared<std::jthread>([&ioc](std::stop_token st)
2428
{
25-
while(true)
29+
while (!st.stop_requested())
2630
{
2731
ioc.run();
2832
ioc.reset();
2933
std::this_thread::sleep_for(std::chrono::milliseconds(1));
3034
}
3135
});
32-
t.detach();
36+
3337
return 0;
3438
}
3539

3640
std::string IOSession::Handle(std::shared_ptr<ProtocolParser> parser)
3741
{
3842
try
3943
{
40-
4144
auto params = parser->GetParams();
4245

4346
if (!params.is_null())
4447
{
4548
auto start = chrono::system_clock::now();
4649
auto result = _service.Dispatch(parser->GetMethod(), params);
4750
std::cerr << format("request {}, it cost: {}ms\n", parser->GetMethod(),
48-
chrono::duration_cast<chrono::milliseconds>(
49-
chrono::system_clock::now() - start
50-
).count());
51+
chrono::duration_cast<chrono::milliseconds>(
52+
chrono::system_clock::now() - start
53+
).count());
5154
if (result)
5255
{
5356
return parser->SerializeProtocol(result);
5457
}
55-
5658
}
5759
}
5860
catch (std::exception& e)

include/CodeFormatServer/Session/IOSession.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22
#include <string>
3-
3+
#include <thread>
44
#include "asio/io_context.hpp"
55
#include "CodeFormatServer/LanguageService.h"
66
#include "CodeFormatServer/Protocol/ProtocolBuffer.h"
@@ -19,4 +19,5 @@ class IOSession
1919
ProtocolBuffer _protocolBuffer;
2020
private:
2121
LanguageService _service;
22+
std::shared_ptr<std::jthread> _logicThread;
2223
};

lua.template.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ keep_one_space_between_table_and_bracket = true
2626
align_table_field_to_first_field = false
2727
# if true, ormat like this "local t <const> = 1"
2828
keep_one_space_between_namedef_and_attribute = false
29+
# continous line distance
30+
max_continuous_line_distance = 1
31+
# if true, iff any one of the consecutive rows meets the condition of aligning to the equal sign,
32+
# the consecutive rows will be aligned to the equal sign
33+
weak_alignment_rule = false
2934
# see document for detail
3035
continuous_assign_statement_align_to_equal_sign = true
3136
# see document for detail
@@ -37,6 +42,7 @@ do_statement_no_indent = false
3742
# if true, the conditional expression of the if statement will not be a continuation line indent
3843
if_condition_no_continuation_indent = false
3944

45+
4046
# optional crlf/lf
4147
end_of_line = crlf
4248

0 commit comments

Comments
 (0)