-
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 deserialize
Signed-off-by: Ubuntu <[email protected]>
- Loading branch information
Ubuntu
committed
Nov 24, 2023
1 parent
9534d56
commit 7540f97
Showing
4 changed files
with
114 additions
and
45 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