Skip to content

Commit 3d6b3ec

Browse files
committed
[SR-1639] Move sourcekitdInProc to std::mutex
SourceKit's in-process mode uses libdispatch sparingly. Removing all usages of libdispatch would allow SourceKit to more easily be ported to Linux. We can begin this process with the `sourcekitd-test` executable, which makes use of `sourcekitd_send_request_sync`. Migrate this usage to the C++ std::condition_variable.
1 parent 009f69b commit 3d6b3ec

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

tools/SourceKit/tools/sourcekitd/bin/InProc/sourcekitdInProc.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
#include "llvm/Support/Mutex.h"
1919
#include "llvm/Support/Path.h"
2020

21-
// FIXME: Portability ?
2221
#include <Block.h>
23-
#include <dispatch/dispatch.h>
22+
#include <condition_variable>
23+
#include <mutex>
2424

2525
#ifdef LLVM_ON_WIN32
2626
#include <windows.h>
@@ -102,16 +102,17 @@ void sourcekitd::set_interrupted_connection_handler(
102102
//===----------------------------------------------------------------------===//
103103

104104
sourcekitd_response_t sourcekitd_send_request_sync(sourcekitd_object_t req) {
105-
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
105+
sourcekitd_response_t ReturnedResp = nullptr;
106+
std::condition_variable handleRequestCondition;
106107

107-
sourcekitd_response_t ReturnedResp;
108108
sourcekitd::handleRequest(req, [&](sourcekitd_response_t resp) {
109109
ReturnedResp = resp;
110-
dispatch_semaphore_signal(sema);
110+
handleRequestCondition.notify_one();
111111
});
112112

113-
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
114-
dispatch_release(sema);
113+
std::mutex m;
114+
std::unique_lock<std::mutex> lk(m);
115+
handleRequestCondition.wait(lk, [&]{ return ReturnedResp != nullptr; });
115116
return ReturnedResp;
116117
}
117118

0 commit comments

Comments
 (0)