2017-05-26 04:48:44 +08:00
|
|
|
/*
|
|
|
|
* Orderer.actor.h
|
|
|
|
*
|
|
|
|
* This source file is part of the FoundationDB open source project
|
|
|
|
*
|
|
|
|
* Copyright 2013-2018 Apple Inc. and the FoundationDB project authors
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-02-22 02:25:11 +08:00
|
|
|
*
|
2017-05-26 04:48:44 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// When actually compiled (NO_INTELLISENSE), include the generated version of this file. In intellisense use the source version.
|
|
|
|
#if defined(NO_INTELLISENSE) && !defined(FDBSERVER_ORDERER_ACTOR_G_H)
|
|
|
|
#define FDBSERVER_ORDERER_ACTOR_G_H
|
2018-10-20 01:30:13 +08:00
|
|
|
#include "fdbserver/Orderer.actor.g.h"
|
2017-05-26 04:48:44 +08:00
|
|
|
#elif !defined(FDBSERVER_ORDERER_ACTOR_H)
|
|
|
|
#define FDBSERVER_ORDERER_ACTOR_H
|
|
|
|
|
2017-07-15 06:49:30 +08:00
|
|
|
#include "fdbclient/Notified.h"
|
2018-08-11 06:18:24 +08:00
|
|
|
#include "flow/actorcompiler.h" // This must be the last #include.
|
2017-05-26 04:48:44 +08:00
|
|
|
|
|
|
|
template <class Seq>
|
|
|
|
class Orderer {
|
|
|
|
public:
|
|
|
|
explicit Orderer( Seq s ) : ready(s), started(false) {}
|
|
|
|
void reset( Seq s ) {
|
|
|
|
ready = NotifiedVersion(s);
|
|
|
|
started = false;
|
|
|
|
}
|
2019-06-25 17:47:35 +08:00
|
|
|
Future<bool> order( Seq s, TaskPriority taskID = TaskPriority::DefaultYield ) {
|
2017-05-26 04:48:44 +08:00
|
|
|
if ( ready.get() < s )
|
|
|
|
return waitAndOrder( this, s, taskID );
|
|
|
|
else
|
|
|
|
return dedup(s);
|
|
|
|
}
|
|
|
|
void complete( Seq s ) {
|
|
|
|
ASSERT( s == ready.get() && started );
|
|
|
|
started = false;
|
|
|
|
ready.set(s+1);
|
|
|
|
}
|
|
|
|
Seq getNextSequence() { return ready.get(); } // Returns the next sequence number which has *not* been returned from order()
|
|
|
|
Future<Void> whenNextSequenceAtLeast( Seq v ) {
|
|
|
|
return ready.whenAtLeast(v);
|
|
|
|
}
|
|
|
|
private:
|
2019-06-25 17:47:35 +08:00
|
|
|
ACTOR static Future<bool> waitAndOrder( Orderer<Seq>* self, Seq s, TaskPriority taskID ) {
|
2018-08-11 04:57:10 +08:00
|
|
|
wait( self->ready.whenAtLeast(s) );
|
|
|
|
wait( yield( taskID ) || self->shutdown.getFuture() );
|
2017-05-26 04:48:44 +08:00
|
|
|
return self->dedup(s);
|
|
|
|
}
|
|
|
|
bool dedup( Seq s ) {
|
|
|
|
if (s != ready.get() || started)
|
|
|
|
return false;
|
|
|
|
started = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool started;
|
|
|
|
NotifiedVersion ready; // FIXME: Notified<Seq>
|
|
|
|
Promise<Void> shutdown; // Never set, only broken on destruction
|
|
|
|
};
|
|
|
|
|
2018-08-11 05:05:28 +08:00
|
|
|
#include "flow/unactorcompiler.h"
|
|
|
|
|
2017-07-15 06:49:30 +08:00
|
|
|
#endif
|