1
0
mirror of https://github.com/ohwgiles/laminar.git synced 2026-03-02 03:40:21 +00:00

resolves #63: remove locks

Add an example to the User Manual for using flock instead
This commit is contained in:
Oliver Giles
2018-09-28 12:42:46 +03:00
parent a7aac62897
commit 18012a8d7a
4 changed files with 39 additions and 77 deletions

View File

@@ -180,14 +180,6 @@ int main(int argc, char** argv) {
fprintf(stderr, "Missing $JOB or $RUN or param is not in the format key=value\n");
return EINVAL;
}
} else if(strcmp(argv[1], "lock") == 0) {
auto req = laminar.lockRequest();
req.setLockName(argv[2]);
req.send().wait(waitScope);
} else if(strcmp(argv[1], "release") == 0) {
auto req = laminar.releaseRequest();
req.setLockName(argv[2]);
req.send().wait(waitScope);
} else {
fprintf(stderr, "Unknown command %s\n", argv[1]);
return EINVAL;

View File

@@ -6,8 +6,6 @@ interface LaminarCi {
start @1 (jobName :Text, params :List(JobParam)) -> (result :MethodResult, buildNum :UInt32);
run @2 (jobName :Text, params :List(JobParam)) -> (result :JobResult, buildNum :UInt32);
set @3 (jobName :Text, buildNum :UInt32, param :JobParam) -> (result :MethodResult);
lock @4 (lockName :Text) -> ();
release @5 (lockName :Text) -> ();
struct JobParam {
name @0 :Text;

View File

@@ -141,31 +141,6 @@ public:
return kj::READY_NOW;
}
// Take a named lock
kj::Promise<void> lock(LockContext context) override {
std::string lockName = context.getParams().getLockName();
LLOG(INFO, "RPC lock", lockName);
auto& lockList = locks[lockName];
lockList.emplace_back(kj::newPromiseAndFulfiller<void>());
if(lockList.size() == 1)
lockList.front().fulfiller->fulfill();
return std::move(lockList.back().promise);
}
// Release a named lock
kj::Promise<void> release(ReleaseContext context) override {
std::string lockName = context.getParams().getLockName();
LLOG(INFO, "RPC release", lockName);
auto& lockList = locks[lockName];
if(lockList.size() == 0) {
LLOG(INFO, "Attempt to release unheld lock", lockName);
return kj::READY_NOW;
}
lockList.erase(lockList.begin());
if(lockList.size() > 0)
lockList.front().fulfiller->fulfill();
return kj::READY_NOW;
}
private:
// Implements LaminarWaiter::complete
void complete(const Run* r) override {
@@ -175,7 +150,6 @@ private:
}
private:
LaminarInterface& laminar;
std::unordered_map<std::string, std::list<kj::PromiseFulfillerPair<void>>> locks;
std::unordered_map<const Run*, std::list<kj::PromiseFulfillerPair<RunState>>> runWaiters;
};