bool HandlerBroker::connect(MyThread * TID, const wxString& sDevName,const std::string& strDevInit, DEVID *id){

	DevDesc * pNewDev; 
	DevDesc* pDevLocker = getDev(sDevName);
	if (!pDevLocker) return false;
	std::string strUniqueDev = std::string(sDevName.utf8_str())+ pDevLocker->makeUniqueDev(strDevInit);
	{
		wxMutexLocker ml1(mtxDevHandlesTreeEdit);
		std::map<std::string, CountedDevHandle*>::iterator itDevH = mapDevHandlesInUse.find(strUniqueDev);
		if(itDevH != mapDevHandlesInUse.end()){
			pNewDev = itDevH->second->dev;
		}else{
			pNewDev = pDevLocker->clone();
			if (!(pNewDev->connect(strDevInit)))return false;

			wxMutexLocker ml2(mtxBusLockTreeEdit);
			std::string strBusLock= pNewDev->makeBusLock(strDevInit);
			pNewDev->itBusLocker =  mapBusLockers.find(strBusLock);
			if(pNewDev->itBusLocker == mapBusLockers.end())
				pNewDev->itBusLocker = mapBusLockers.insert(std::make_pair(strBusLock, new mtxCont)).first;
			++(*(pNewDev->itBusLocker->second));
			itDevH = mapDevHandlesInUse.insert( std::make_pair( strUniqueDev, new CountedDevHandle(pNewDev)) ).first; 
			itDevH->second->dev->itDevH = itDevH;
		}
		++(*(itDevH->second));
	}

	wxMutexLocker ml0(mtxDevTreeEdit);
	std::map<MyThread *, ThrDevs*>::iterator it=mapThreadDevsInUse.find(TID); 
	if (it == mapThreadDevsInUse.end()) it = mapThreadDevsInUse.insert(std::pair<MyThread * , ThrDevs*>(TID, new ThrDevs(TID)) ).first; 
	*id = it->second->insert(pNewDev);

	return true;
};
void HandlerBroker::remove(MyThread * TID){

	wxMutexLocker ml(mtxDevTreeEdit);
	wxMutexLocker ml2(mtxBusLockTreeEdit);
	std::map<MyThread *, ThrDevs*>::iterator it = mapThreadDevsInUse.find(TID);
	if (it == mapThreadDevsInUse.end()){return ;}
	ThrDevs * pthD = it->second;
	mtxDevHandlesTreeEdit.Lock();
	ThrDevs::iterator ddIt;
	ThrDevs::iterator itLast= pthD->end();
	DevDesc * pDev;
	for(ddIt = pthD->begin(); ddIt != itLast; ++ddIt){
		pDev = ddIt->second;
		if (!--(*(pDev->itDevH->second))){
			pDev->disconnect();
			if(!--(*(pDev->itBusLocker->second)))
				mapBusLockers.erase(pDev->itBusLocker);				
		//	delete pDev->itDevH->second;
			mapDevHandlesInUse.erase(pDev->itDevH);
			delete pDev;
		}
	}
	mtxDevHandlesTreeEdit.Unlock(); 
	delete pthD;
	mapThreadDevsInUse.erase(it); 
	return ;
}
	Wire::~Wire(void)
	{
		int32 ret = 0;

		// DEBUG
		UOSUTIL_DOUT(("~Wire(): entered"));

		if (_p1 && _p2) {
			MutexLocker ml1(_p1);
			MutexLocker ml2(_p2);

			ret = _p1->disconnect(_p2->getBlock(), _p2);
			if (ret == FAILURE) {
				// DEBUG
				UOSUTIL_DOUT(("~Wire(): disconnect failure on %s\n",
					_p1->getAbsoluteName()));
			}

			ret = _p2->disconnect(_p1->getBlock(), _p1);
			if (ret == FAILURE) {
				// DEBUG
				UOSUTIL_DOUT(("~Wire(): disconnect failure on %s\n",
					_p2->getAbsoluteName()));
			}

			/*
			 * Pin2 is an input pin for sure, so the buffer pool is shared among
			 * wires. If there are no more peers connected to pin2, it means
			 * that no more wires share buffer pool and this is the last wire.
			 * So delete the bp2 buffer pool.
			 */

			if (!_p2->getPeersCount()) {
				delete _bp2; _p2->_ibp = NULL; _p2->_bpSet = false;
			}

			/*
			 * In case of bidirectional wire, Pin1 behaves like Pin2. So
			 * check for type and do the same us below.
			 */
			if (_type == BIDIRECTIONAL) {
				// DEBUG
				UOSUTIL_DOUT(("~Wire(): doing cleanup for bidirectional wire\n"));
				UOSUTIL_DOUT(("~Wire(): p1 = %s, p2 = %s\n",
					_p1->getAbsoluteName(), _p2->getAbsoluteName()));

				if (!_p1->getPeersCount()) {
					delete _bp1; _p1->_ibp = NULL; _p1->_bpSet = false;
				}
			}
		}

		// DEBUG
		UOSUTIL_DOUT(("~Wire(): ok"));
	}
Exemple #4
0
const QString& KstIfaceImpl::string(const QString& name) {
  KstReadLocker ml(&KST::stringList.lock());
  KstStringList::Iterator it = KST::stringList.findTag(name);

  if (it != KST::stringList.end()) {
    KstReadLocker ml2(*it);
    return (*it)->value();
  }

  return QString::null;
}
bool KstData::matrixTagNameNotUniqueInternal(const QString& tag) {
  /* verify that the tag name is not empty */
  if (tag.stripWhiteSpace().isEmpty()) {
    return true;
  }

  /* verify that the tag name is not used by a data object */
  KstReadLocker ml(&KST::matrixList.lock());
  KstReadLocker ml2(&KST::scalarList.lock());
  if (KST::matrixList.tagExists(tag) || KST::scalarList.tagExists(tag)) {
    return true;
  }
  return false;
}
Exemple #6
0
bool KST::vectorTagNameNotUnique(const QString &tag, bool warn, void *p) {
  /* verify that the tag name is not empty */
  if (tag.stripWhiteSpace().isEmpty()) {
      if (warn) {
        KMessageBox::sorry(static_cast<QWidget*>(p), i18n("Empty tag names are not allowed."));
      }
      return true;
  }

  /* verify that the tag name is not used by a data object */
  KstReadLocker ml(&KST::vectorList.lock());
  KstReadLocker ml2(&KST::scalarList.lock());
  if (KST::vectorList.findTag(tag) != KST::vectorList.end() ||
      KST::scalarList.findTag(tag) != KST::scalarList.end()) {
      if (warn) {
        KMessageBox::sorry(static_cast<QWidget*>(p), i18n("%1: this name is already in use. Change it to a unique name.").arg(tag));
      }
      return true;
  }

  return false;
}
	int32 Wire::_allocate(void)
	{
		uint32 max_buf_size = 0, p1_bsz = 0, p2_bsz = 0;
		int32 max_buf_count = 0, p1_bco = 0, p2_bco = 0;
		int32 ret = 0;

		char tmp[4096];

		// get right buffers info
		if (_p1->getStatus() == Pin::CONNECTED) {
			p1_bsz = _p1->_real_bufsz;
			p1_bco = _p1->_real_bufcount;
		} else {
			p1_bsz = _p1->_pref_bufsz;
			p1_bco = _p1->_pref_bufcount;
		}

		if (_p2->getStatus() == Pin::CONNECTED) {
			p2_bsz = _p2->_real_bufsz;
			p2_bco = _p2->_real_bufcount;
		} else {
			p2_bsz = _p2->_pref_bufsz;
			p2_bco = _p2->_pref_bufcount;
		}

		// select right buffers size and count
		max_buf_size = p1_bsz > p2_bsz ? p1_bsz : p2_bsz;
		max_buf_count = p1_bco > p2_bco ? p1_bco : p2_bco;

		// DEBUG
		UOSUTIL_DOUT(("Wire::_allocate(): BSZ = %u, BCO = %d\n", max_buf_size,
			max_buf_count));

		// lock pins
		MutexLocker ml1(_p1);
		MutexLocker ml2(_p2);

		// check which pin needs a buffer pool
		if (!_p1->_bpSet) {
			// check if this wire is bidirectional
			if (_type == BIDIRECTIONAL) {
				// build buffer pool name
				snprintf(tmp, sizeof(tmp), "BP1[%s,%s]",
					_p1->getAbsoluteName(), _p2->getAbsoluteName());

				// create buffer pool object
				_bp1 = new BufferPool();
				if (!_bp1)
					return FAILURE;

				// allocate buffer pool for Pin 1
				ret = _bp1->init(tmp, max_buf_size, max_buf_count);
				if (ret == FAILURE) {
					delete _bp1; return FAILURE;
				}

				// DEBUG
				UOSUTIL_DOUT(("Wire::_allocate(): allocating bp for pin %s\n",
					_p1->getAbsoluteName()));

				// associate bp1 to pin 1
				_p1->_ibp = _bp1;
			} else {
				// set input buffer pool for pin 1 to NULL
				_p1->_ibp = NULL;
			}

			// signal that buffer pool has been set
			_p1->_bpSet = true;
		} else {
			// use pin 1's buffer pool
			_bp1 = _p1->_ibp;
			_multipoint_on_bp1 = true;

			// DEBUG
			UOSUTIL_DOUT(("Wire::_allocate(): it is multipoint\n"));
			UOSUTIL_DOUT(("Wire::_allocate(): using buffer pool of pin %s (%s)\n",
				_p1->getAbsoluteName(), _bp1 ?
				"and is ok" :
				"and is null"));
		}

		/*
		 * Notice that data flow from pin1 to pin2. Buffer pool
		 * is associated to the input pin so I need to create
		 * a buffer pool only for pin2.
		 */

		if (!_p2->_bpSet) {
			// build buffer pool name
			snprintf(tmp, sizeof(tmp), "BP2[%s,%s]", _p1->getAbsoluteName(),
				_p2->getAbsoluteName());

			// create buffer pool object
			_bp2 = new BufferPool();
			if (!_bp2)
				return FAILURE;

			// allocate buffer pool for Pin 2
			ret = _bp2->init(tmp, max_buf_size, max_buf_count);
			if (ret == FAILURE) {
				delete _bp2; return FAILURE;
			}

			// associate bp2 to pin 2
			_p2->_ibp = _bp2;

			// signal that buffer pool has been set
			_p2->_bpSet = true;

			// DEBUG
			UOSUTIL_DOUT(("Wire::_allocate(): allocating bp for pin %s\n",
				_p2->getAbsoluteName()));
		} else {
			// use pin 2's buffer pool
			_bp2 = _p2->_ibp;
			_multipoint_on_bp2 = true;

			// DEBUG
			UOSUTIL_DOUT(("Wire::_allocate(): - it is multipoint\n"));
			UOSUTIL_DOUT(("Wire::_allocate(): using buffer pool of pin %s (%s)\n",
				_p2->getAbsoluteName(), _bp2 ?
				"and is ok" :
				"and is null"));
		}

		// set real parameters for pins
		_p1->_real_bufsz = max_buf_size;
		_p1->_real_bufcount = max_buf_count;
		_p2->_real_bufsz = max_buf_size;
		_p2->_real_bufcount = max_buf_count;

		// ok
		return SUCCESS;
	}
int
main(int argc, char** argv)
{
  // Fetch a bootstrap object. The bootstrap object is a special 'root' object
  // from which you can get at everything else. CreateCellMLBootstrap() is a
  // C++ binding specific method, which fetches the CellMLBootstrap object.
  // It is the only non-OO method that you should ever call from the CellML
  // API.
  // ObjRef is a template defined in cellml-api-cxx-support.hpp. CreateCellMLBootstrap
  // has already_Addrefd<iface::cellml_api::CellMLBootstrap> as its return type,
  // which is the signal that a reference is added (i.e. the reference count is
  // incremented on the return value, and the caller must ensure it is decremented).
  // ObjRef will, when given an already_Addrefd argument, not increment the reference
  // count, but will decrement it when it goes out of scope. If an ObjRef is constructed
  // from a pointer or another ObjRef, it will add a reference on construction,
  // and release the reference on destruction.
  ObjRef<iface::cellml_api::CellMLBootstrap> cbs(CreateCellMLBootstrap());

  // Now would be a good time to see what methods we can call. In the
  // CellML_DOM_API source, find interfaces/CellML_APISPEC.idl.
  // This defines the interfaces you can call. Search down to find
  // this text...
  /*
  interface CellMLBootstrap
    : XPCOM::IObject
  {
    ...
   */
  // We want to load a model, so we want the modelLoader attribute. We fetch
  // the attribute like this...
  ObjRef<iface::cellml_api::DOMModelLoader> ml(cbs->modelLoader());

  // Suppose we only had a general model loader...
  ObjRef<iface::cellml_api::ModelLoader> generalModelLoader(ml);
  // if we wanted to get from this to a DOM model loader, we can't just cast,
  // because the API is designed so it can work through bridges and we might
  // need to switch to a different bridge (you can cast from an interface to a
  // parent interface in the inheritance hierarchy, but not the other way).
  // Instead, we call query_interface to ask the underlying object if it
  // supports the interface we want, and to return us a value.
  ObjRef<iface::cellml_api::DOMModelLoader> ml2(do_QueryInterface(generalModelLoader));
  // ml2 would be null if generalModelLoader didn't support DOMModelLoader.

  // Start a try, because we might get an exception...
  try
  {
    // We now have a DOMModelLoader, stored in ml. DOMModelLoader inherits from
    // ModelLoader, which defines a loadFromURL operation (check in the IDL).
    // Be warned that is a synchronous (blocking) load. In a real application,
    // you are probably better to download the file using another asynchronous
    // http library, and then creating the model from the serialised text.
    ObjRef<iface::cellml_api::Model> model(ml->loadFromURL(L"http://www.cellml.org/models/beeler_reuter_1977_version04/download"));

    // Fetch the models cmeta:id (there obviously lots of other things we could
    // do here!)
    std::wstring cmid = model->cmetaId();
    printf("Model's cmeta:id is %S\n", cmid.c_str());
  }
  // Most parts of the CellML API raise this exception. The DOM/MathML API, on the
  // other hand, raises iface::dom::DOMException.
  catch (iface::cellml_api::CellMLException&)
  {
    // Unfortunately, due to the need to support the 'lowest common
    // denominator' of functionality in our bindings, exceptions can't have
    // supplementary information (to suit XPCOM). However, many classes have
    // a way to get the last error, e.g. lastErrorMessage on ModelLoader.
    // However, threadsafety is potentially an issue with this.
    std::wstring msg = ml->lastErrorMessage();
    printf("Got a CellML Exception loading a model. Error was %S\n",
           msg.c_str());
    return 1;
  }

  return 0;
}
Exemple #9
0
int
main(void) {
    float *a = malloc(sizeof(float)*NUM + SSE_ALIGN);
    /* make sure that pointers are aligned to multiplies of 16 bytes */
    a = (float *) align(a, SSE_ALIGN);

    /* write values to a and b */
    for (int i = 0; i < NUM; i++) {
        a[i] = i;
    }

    /* invoke the function written in the vector language */
    ml0(NUM, a);

    /* read values from c */
    printf("Result for vector a after ml0:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml1(NUM, a);
    printf("Result for vector a after ml1:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml2(NUM, a);
    printf("Result for vector a after ml2:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml3(NUM, a);
    printf("Result for vector a after ml3:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml4(NUM, a);
    printf("Result for vector a after ml4:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml5(NUM, a);
    printf("Result for vector a after ml5:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml6(NUM, a);
    printf("Result for vector a after ml6:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml7(NUM, a);
    printf("Result for vector a after ml7:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    ml8(NUM, a);
    printf("Result for vector a after ml8:\n");
    for (int i = 0; i < NUM; i++) {
        printf("%f ", a[i]);
    }
    printf("\n");

    return 0;
}
Exemple #10
0
// resolve two clauses, if possible.
int
resolveClauses(Array<BinaryTree_AVL<Clause> > &clausesArray, 
	Clause &cl1, Clause &cl2, int &clausesAdded, unsigned int currentDepth)
{
	// check if any of the clauses are empty
	statistics[ResolutionsAttempted] += 1;
	totalstatistics[TotalResolutionsAttempted] += 1;
	if (cl1.isEmpty() || cl2.isEmpty())
	{
		return(VALID);
	}

	// check if clauses can be resolved
	if (!cl1.getSOS() && !cl2.getSOS())
	{
		// one clause must be in the set-of-support
		return(NOMATCH);
	}
	if ((cl1.getType() == Clause::Negative && 
	     cl2.getType() == Clause::Negative) ||
	    (cl1.getType() == Clause::Positive && 
	     cl2.getType() == Clause::Positive))
	{
		// two positive clauses or two negative clauses
		// can not be resolved.
		return(NOMATCH);
	}

	// attempt to resolve two clauses. use A-ordering resolution,
	// try to resolve maximal literals.
	//
	Literal maxlit1;
	if (cl1.getMaximalLiteral(maxlit1) != OK)
	{
		ERROR("getMaximalLiteral failed.", errno);
		return(NOTOK);
	}
	Literal maxlit2;
	if (cl2.getMaximalLiteral(maxlit2) != OK)
	{
		ERROR("getMaximalLiteral failed.", errno);
		return(NOTOK);
	}
	if ((cl1.getTotalMembers() > maxliterals) ||
	    (cl2.getTotalMembers() > maxliterals))
	{
		statistics[MaximumLiteralsClausesRejected] += 1;
		totalstatistics[TotalMaximumLiteralsClausesRejected] += 1;
		return(NOMATCH);
	}
	if (maxlit1.unify_ne(~maxlit2))
	{
		return(NOMATCH);
	}

	// factor clauses
	Substitutions subs;
	if (factor(maxlit1, cl1, subs) == NOTOK)
	{
		ERROR("factor failed.", errno);
		return(NOTOK);
	}
	if (factor(maxlit2, cl2, subs) == NOTOK)
	{
		ERROR("factor failed.", errno);
		return(NOTOK);
	}

	// attempt to unify the clauses
	subs.clear();
	int status = unify(maxlit1, ~maxlit2, subs);
	switch (status)
	{
	case OK:
		if (verbose)
		{
			cout << endl;
			Literal ml1(maxlit1);
			cout << "max literal 1 (before subs): " << ml1 << endl;
			subs.applyTo(ml1);
			cout << "max literal 1 (after subs): " << ml1 << endl;
			Literal ml2(maxlit2);
			cout << "max literal 2 (before subs): " << ml2 << endl;
			subs.applyTo(ml2);
			cout << "max literal 2 (after subs): " << ml2 << endl;
			MustBeTrue(equal(ml1, ~ml2));
		}
		break;
	case NOMATCH:
		return(NOMATCH);
	default:
		ERROR("unify failed.", errno);
		return(status);
	}

	// can resolve, remove literals from clauses
	Clause newcl1(cl1);
	if (newcl1.remove(maxlit1) != OK)
	{
		ERROR("remove failed.", errno);
		return(NOTOK);
	}
	if (subs.applyTo(newcl1) != OK)
	{
		ERROR("applyTo failed.", errno);
		return(NOTOK);
	}
	Clause newcl2(cl2);
	if (newcl2.remove(maxlit2) != OK)
	{
		ERROR("remove failed.", errno);
		return(NOTOK);
	}
	if (subs.applyTo(newcl2) != OK)
	{
		ERROR("applyTo failed.", errno);
		return(NOTOK);
	}

	// store new clause and update flag
	Clause newcl = newcl1+newcl2;
	if (newcl.renameVariables() != OK)
	{
		ERROR("renameVariables failed.", errno);
		return(NOTOK);
	}
	newcl.setDepth(currentDepth+1);
	newcl.setNumber(nextClause++);
	if (clausesArray[currentDepth+1].insert(newcl) != OK)
	{
		ERROR("insert failed.", errno);
		return(NOTOK);
	}
	clausesAdded = 1;

	// indicate the clauses that were resolved
	statistics[ClausesGenerated] += 1;
	totalstatistics[TotalClausesGenerated] += 1;
	dumpnewclause(cl1, cl2, newcl);

	// check if we found an empty clause
	if (newcl.isEmpty())
	{
		return(VALID);
	}
	else
	{
		return(OK);
	}
}