- XBT_IN("(%p; %p)", this, issuer);
- /* FIXME: check where to validate the arguments */
- RawImplPtr synchro = nullptr;
-
- if (locked_) {
- /* FIXME: check if the host is active ? */
- /* Somebody using the mutex, use a synchronization to get host failures */
- synchro = RawImplPtr(new RawImpl());
- (*synchro).set_host(issuer->get_host()).start();
- synchro->simcalls_.push_back(&issuer->simcall);
- issuer->waiting_synchro = synchro;
- sleeping_.push_back(*issuer);
- } else {
- /* mutex free */
- locked_ = true;
+ /* If the mutex is recursive */
+ if (is_recursive_) {
+ if (owner_ == issuer) {
+ recursive_depth++;
+ auto res = MutexAcquisitionImplPtr(new kernel::activity::MutexAcquisitionImpl(issuer, this), true);
+ res->grant();
+ return res;
+ } else if (owner_ == nullptr) { // Free
+ owner_ = issuer;
+ recursive_depth = 1;
+ auto res = MutexAcquisitionImplPtr(new kernel::activity::MutexAcquisitionImpl(issuer, this), true);
+ res->grant();
+ return res;
+ }
+
+ for (auto acq : ongoing_acquisitions_)
+ if (acq->get_issuer() == issuer) {
+ acq->recursive_depth_++;
+ return acq;
+ }
+
+ // Not yet in the ongoing acquisition list. Get in there
+ auto res = MutexAcquisitionImplPtr(new kernel::activity::MutexAcquisitionImpl(issuer, this), true);
+ ongoing_acquisitions_.push_back(res);
+ return res;
+ }
+
+ // None-recursive mutex
+ auto res = MutexAcquisitionImplPtr(new kernel::activity::MutexAcquisitionImpl(issuer, this), true);
+ if (owner_ == nullptr) { // Lock is free, take it