-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async generate diskann cache after diskann deserialize
Signed-off-by: [email protected] <cqy123456>
- Loading branch information
1 parent
aeb6931
commit 0fa0627
Showing
4 changed files
with
145 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
#include <mutex> | ||
#include <condition_variable> | ||
|
||
namespace diskann { | ||
class Semaphore { | ||
public: | ||
Semaphore(long count = 0) : count(count) {} | ||
void Signal() | ||
{ | ||
std::unique_lock<std::mutex> unique(mt); | ||
++count; | ||
if (count <= 0) { | ||
cond.notify_one(); | ||
} | ||
} | ||
void Wait() | ||
{ | ||
std::unique_lock<std::mutex> unique(mt); | ||
--count; | ||
if (count < 0) { | ||
cond.wait(unique); | ||
} | ||
} | ||
bool IsWaitting() { | ||
std::unique_lock<std::mutex> unique(mt); | ||
return count < 0; | ||
} | ||
|
||
private: | ||
std::mutex mt; | ||
std::condition_variable cond; | ||
long count; | ||
}; | ||
} // namespace diskann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters