Ejemplo n.º 1
0
	void lock(my_actor* host)
	{
		host->assert_enter();
		my_actor::quit_guard qg(host);
		bool complete = false;
		mutex_trig_handle ath(host);
		mutex_trig_notifer ntf;
		LAMBDA_THIS_REF4(ref4, host, complete, ath, ntf);
		host->send(_strand, [&ref4]
		{
			auto& lockActorID_ = ref4->_lockActorID;
			auto& host_ = ref4.host;
			if (!lockActorID_ || host_->self_id() == lockActorID_)
			{
				lockActorID_ = host_->self_id();
				ref4->_recCount++;
				ref4.complete = true;
			}
			else
			{
				auto& ntf_ = ref4.ntf;
				ntf_ = ref4.ath.make_notifer();
				wait_node wn = { ntf_, host_->self_id() };
				ref4->_waitQueue.push_front(wn);
				ref4.complete = false;
			}
		});

		if (!complete)
		{
			ath.wait();
		}
	}
Ejemplo n.º 2
0
	void lock_upgrade(my_actor* host)
	{
		host->assert_enter();
		my_actor::quit_guard qg(host);
		bool complete = false;
		mutex_trig_handle ath(host);
		mutex_trig_notifer ntf;
		LAMBDA_THIS_REF4(ref4, host, complete, ath, ntf);
		host->send(_strand, [&ref4]
		{
			assert(ref4->_shared);
			assert(ref4->_inSet.find(ref4.host->self_id()) != ref4->_inSet.end());
			assert(ref4->_inSet.find(ref4.host->self_id())->second);
			auto& inSet_ = ref4->_inSet;
			if (inSet_.size() == 1)
			{
				ref4.complete = true;
				inSet_[ref4.host->self_id()] = true;
			}
			else
			{
				auto& ntf_ = ref4.ntf;
				ref4.complete = false;
				ntf_ = ref4.ath.make_notifer();
				wait_node wn = { ntf_, ref4.host->self_id(), false };
				ref4->_waitQueue.push_front(wn);
			}
		});
		if (!complete)
		{
			ath.wait();
		}
	}
TUint CTupleStoreImpl::PutL(TTupleType aTupleType, const TTupleName& aTupleName, const TDesC& aSubName, 
		const TComponentName& aComponent,
		const TDesC8& aSerializedData, TBBPriority aPriority, TBool aReplace,
		const TTime& aLeaseExpires, TBool aKeepExisting)
{
	CALLSTACKITEM_N(_CL("CTupleStoreImpl"), _CL("PutL"));

	if (aTupleName.iModule.iUid == KBBAnyUidValue ||
		aTupleName.iId == KBBAnyId ||
		aComponent.iModule.iUid == KBBAnyUidValue ||
		aComponent.iId == KBBAnyId) User::Leave(KErrArgument);

	TUint ret;
	{
		TAutomaticTransactionHolder ath(*this);

		TBool exists=SeekNameL(aTupleType, aTupleName, aSubName);
		if (exists && aKeepExisting) {
			UpdateL();
			iTable.SetColL(ELeaseExpires, aLeaseExpires);
			MDBStore::PutL();
			return 0;
		} else if (exists && aReplace) {
			UpdateL();
		} else {
			InsertL();
			iTable.SetColL(ETupleType, aTupleType);
			iTable.SetColL(ENameModule, aTupleName.iModule.iUid);
			iTable.SetColL(ENameId, aTupleName.iId);
			iTable.SetColL(ENameSubName1, aSubName);
			iTable.SetColL(ENameSubName2, aSubName.Left(iSubNameIndexLength));
			iTable.SetColL(EPriority, aPriority);
			iTable.SetColL(EComponentModule, aComponent.iModule.iUid);
			iTable.SetColL(EComponentId, aComponent.iId);
		}
		ret=iTable.ColUint(ETupleId);

		if (aSerializedData.Length() > 0) {
			RADbColWriteStream w; w.OpenLA(iTable, EData);
			w.WriteUint32L(aSerializedData.Length());
			w.WriteL(aSerializedData);
			w.CommitL();
		} else {
			iTable.SetColNullL(EData);
		}
		iTable.SetColL(ELeaseExpires, aLeaseExpires);
		MDBStore::PutL();
	}

	if (aLeaseExpires < iNextExpiry) {
		TTime now=GetTime();
		TTimeIntervalSeconds s;
		aLeaseExpires.SecondsFrom(now, s);
		TInt wait=s.Int();
		iTimer->Wait(wait);
	}
	return ret;
}
Ejemplo n.º 4
0
	bool timed_lock_upgrade(int tm, my_actor* host)
	{
		host->assert_enter();
		my_actor::quit_guard qg(host);
		bool complete = false;
		mutex_trig_handle ath(host);
		mutex_trig_notifer ntf;
		msg_list<wait_node>::iterator nit;
		LAMBDA_THIS_REF5(ref5, host, complete, ath, ntf, nit);
		host->send(_strand, [&ref5]
		{
			assert(ref5->_shared);
			assert(ref5->_inSet.find(ref5.host->self_id()) != ref5->_inSet.end());
			assert(ref5->_inSet.find(ref5.host->self_id())->second);
			auto& inSet_ = ref5->_inSet;
			if (inSet_.size() == 1)
			{
				ref5.complete = true;
				inSet_[ref5.host->self_id()] = true;
			}
			else
			{
				auto& ntf_ = ref5.ntf;
				auto& waitQueue_ = ref5->_waitQueue;
				ref5.complete = false;
				ntf_ = ref5.ath.make_notifer();
				wait_node wn = { ntf_, ref5.host->self_id(), false };
				waitQueue_.push_front(wn);
				ref5.nit = waitQueue_.begin();
			}
		});
		if (!complete)
		{
			if (!ath.timed_wait(tm))
			{
				host->send(_strand, [&ref5]
				{
					auto& complete_ = ref5.complete;
					auto& notified_ = ref5.ntf._notified;
					complete_ = notified_;
					notified_ = true;
					if (!complete_)
					{
						ref5->_waitQueue.erase(ref5.nit);
					}
				});
				if (!complete)
				{
					return false;
				}
				ath.wait();
			}
		}
		return true;
	}
Ejemplo n.º 5
0
	bool timed_lock(int tm, my_actor* host)
	{
		host->assert_enter();
		my_actor::quit_guard qg(host);
		msg_list<wait_node>::iterator nit;
		bool complete = false;
		mutex_trig_handle ath(host);
		mutex_trig_notifer ntf;
		LAMBDA_THIS_REF5(ref5, host, nit, complete, ath, ntf);
		host->send(_strand, [&ref5]
		{
			auto& lockActorID_ = ref5->_lockActorID;
			auto& host_ = ref5.host;
			if (!lockActorID_ || host_->self_id() == lockActorID_)
			{
				lockActorID_ = host_->self_id();
				ref5->_recCount++;
				ref5.complete = true;
			}
			else
			{
				auto& ntf_ = ref5.ntf;
				ntf_ = ref5.ath.make_notifer();
				wait_node wn = { ntf_, host_->self_id() };
				ref5->_waitQueue.push_front(wn);
				ref5.nit = ref5->_waitQueue.begin();
				ref5.complete = false;
			}
		});

		if (!complete)
		{
			if (!ath.timed_wait(tm))
			{
				host->send(_strand, [&ref5]
				{
					auto& notified_ = ref5.ntf._notified;
					auto& complete_ = ref5.complete;
					complete_ = notified_;
					notified_ = true;
					if (!complete_)
					{
						ref5->_waitQueue.erase(ref5.nit);
					}
				});
				if (!complete)
				{
					return false;
				}
				ath.wait();
			}
		}
		return true;
	}
Ejemplo n.º 6
0
	void wait(my_actor* host, actor_lock_guard& mutex)
	{
		host->assert_enter();
		assert(mutex._host == host);
		my_actor::quit_guard qg(host);
		mutex_trig_handle ath(host);
		mutex_trig_notifer ntf;
		LAMBDA_THIS_REF2(ref2, ath, ntf);
		host->send(_strand, [&ref2]
		{
			ref2.ntf = ref2.ath.make_notifer();
			wait_node wn = { ref2.ntf };
			ref2->_waitQueue.push_back(wn);
		});
		mutex.unlock();
		ath.wait();
		mutex.lock();
	}
Ejemplo n.º 7
0
	void quited_lock(my_actor* host)
	{
		assert(host->self_strand()->running_in_this_thread());
		assert(_strand->running_in_this_thread());
		assert(host->in_actor());
		assert(host->is_quited());
		host->check_stack();

		if (!_lockActorID || host->self_id() == _lockActorID)
		{
			_lockActorID = host->self_id();
			_recCount++;
		}
		else
		{
			mutex_trig_handle ath(host);
			mutex_trig_notifer ntf = ath.make_notifer();
			wait_node wn = { ntf, host->self_id() };
			_waitQueue.push_back(wn);
			ath.wait();
		}
	}
Ejemplo n.º 8
0
	bool timed_wait(int tm, my_actor* host, actor_lock_guard& mutex)
	{
		host->assert_enter();
		assert(mutex._host == host);
		my_actor::quit_guard qg(host);
		mutex_trig_handle ath(host);
		mutex_trig_notifer ntf;
		msg_list<wait_node>::iterator nit;
		bool timed = false;
		LAMBDA_THIS_REF4(ref4, ath, nit, ntf, timed);
		host->send(_strand, [&ref4]
		{
			ref4.ntf = ref4.ath.make_notifer();
			wait_node wn = { ref4.ntf };
			ref4->_waitQueue.push_front(wn);
			ref4.nit = ref4->_waitQueue.begin();
		});
		mutex.unlock();
		if (!ath.timed_wait(tm))
		{
			host->send(_strand, [&ref4]
			{
				if (!ref4.ntf._notified)
				{
					ref4.timed = true;
					ref4->_waitQueue.erase(ref4.nit);
				}
			});
			if (!timed)
			{
				ath.wait();
			}
		}
		mutex.lock();
		return !timed;
	}