Exemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    int lPisarzy = 2;
    int lCzytelnikow = 5;
    int lKsiazek = 3;
    listaCzytelnikow = new QList<Czytelnik*>();
    listaPisarzy = new QList<Pisarz*>();

    biblioteka = new Biblioteka(lKsiazek);
    QObject::connect(biblioteka, SIGNAL(showCzytelnicy()), this, SLOT(slot_showCzytelicy()), Qt::DirectConnection);
    QObject::connect(biblioteka, SIGNAL(showPisarze()), this, SLOT(slot_showPisarze()), Qt::DirectConnection);

    for (int i = 0 ; i < lPisarzy ; i++ ){
        Pisarz *pisarz = new Pisarz(i+1);
        listaPisarzy->append(pisarz);

        QObject::connect(pisarz, SIGNAL(stoppedDoNothing()), pisarz, SLOT(slot_stoppedDoNothing()), Qt::DirectConnection);
        QObject::connect(pisarz, SIGNAL(stoppedWriting()), pisarz, SLOT(slot_stoppedWriting()), Qt::DirectConnection);
        QObject::connect(pisarz, SIGNAL(boredToDeath()), pisarz, SLOT(slot_boredToDeath()), Qt::DirectConnection);
        QObject::connect(pisarz, SIGNAL(startDoNothingAgain()), pisarz, SLOT(doNothing()), Qt::DirectConnection);

        QObject::connect(pisarz, SIGNAL(freeSlot()), biblioteka, SLOT(slot_freeSlotPisarz()), Qt::DirectConnection);
        QObject::connect(pisarz, SIGNAL(meWantsWrite(Pisarz*)), biblioteka, SLOT(slot_requestedSlotByPisarz(Pisarz*)), Qt::DirectConnection);
    }

    for (int i = 0 ; i < lCzytelnikow ; i++ ){
        Czytelnik *czytelnik = new Czytelnik(i+1);
        listaCzytelnikow->append(czytelnik);

        QObject::connect(czytelnik, SIGNAL(stoppedDoNothing()), czytelnik, SLOT(slot_stoppedDoNothing()), Qt::DirectConnection);
        QObject::connect(czytelnik, SIGNAL(stoppedReading()), czytelnik, SLOT(slot_stoppedReading()), Qt::DirectConnection);
        QObject::connect(czytelnik, SIGNAL(boredToDeath()), czytelnik, SLOT(slot_boredToDeath()), Qt::DirectConnection);
        QObject::connect(czytelnik, SIGNAL(startDoNothingAgain()), czytelnik, SLOT(doNothing()), Qt::DirectConnection);

        QObject::connect(czytelnik, SIGNAL(freeSlot()), biblioteka, SLOT(slot_freeSlotCzytelnik()), Qt::DirectConnection);
        QObject::connect(czytelnik, SIGNAL(meWantsRead(Czytelnik*)), biblioteka, SLOT(slot_requestedSlotByCzytelnik(Czytelnik*)), Qt::DirectConnection);
    }


    for ( int i = 0 ; i < listaCzytelnikow->size() ; i++ ){
        (*listaCzytelnikow)[i]->startThread();
    }

    for ( int i = 0 ; i < listaPisarzy->size() ; i++ ){
        (*listaPisarzy)[i]->startThread();
    }

    ui->setupUi(this);
}
Exemplo n.º 2
0
void cli_cmd_trace(size_t argc,const sASTNode **argv) {
	if(argc == 0)
		printTraces();
	else {
		int slot = freeSlot();
		if(slot == -1)
			cmds_throwEx("Can't add another trace-command! Limit reached.\n");

		size_t size = MAX_CMD_LEN;
		char *cmd = (char*)mem_alloc(MAX_CMD_LEN);
		char *curCmd = cmd;
		for(size_t i = 0; i < argc; i++) {
			size_t len = ast_toString(argv[i],curCmd,size);
			size -= len + 1;
			if(size < 2 || i >= argc - 1)
				break;
			curCmd[len] = ' ';
			curCmd[len + 1] = '\0';
			curCmd += len + 1;
		}

		mprintf("Added command '%s' in slot %d\n",cmd,slot);
		traceCmds[slot] = cmd;
	}
}
Exemplo n.º 3
0
bool SearchListItem::operator<(const QTreeWidgetItem & other_) const {
    const SearchListItem * other = dynamic_cast<const SearchListItem*>(&other_);
    if (!other)
        return false;

	int col = 0;
	if(treeWidget())
	col = treeWidget()->sortColumn();

	switch(col) {
	case 0:
		return n() < other->n();
	case 1:
		return user() < other->user();
	case 2:
		return text(2) < other->text(2);
	case 3:
		return size() < other->size();
	case 4:
		return speed() < other->speed();
	case 5:
		return inQueue() < other->inQueue();
	case 6:
		return freeSlot();
	case 7:
		return length() < other->length();
	case 8:
		return bitrate() < other->bitrate();
	case 9:
		return dir() < other->dir() ;
	}

  return false;
}
Exemplo n.º 4
0
static void meta_free(void *mem)
{
  Slot *s;
  if (mem==NULL) return; /*Legal, but misleading*/

  s=((Slot *)mem)-1;
  if (s->magic==SLOTMAGIC_VALLOC)
  { /*Allocated with special alignment*/
    freeSlot(s);
    mm_free(((char *)mem)-meta_getpagesize());
  }
  else if (s->magic==SLOTMAGIC) 
  { /*Ordinary allocated block */
    freeSlot(s);
    mm_free(s);
  }
  else if (s->magic==SLOTMAGIC_FREED)
    CmiAbort("Free'd block twice");
  else /*Unknown magic number*/
    CmiAbort("Free'd non-malloc'd block");
}
Exemplo n.º 5
0
    Ptr get(Args&&... args)
    {
        if (m_firstFreeIndex > -1)
        {
            Ptr object(new (m_slots[m_firstFreeIndex].first)T(std::forward<Args>(args)...), [this](T* ptr) {
                freeSlot(ptr);
            });

            m_slots[m_firstFreeIndex].second = false;
            while (m_slots[++m_firstFreeIndex].second == false)
            {
                if (m_firstFreeIndex == m_slots.size())
                {
                    m_firstFreeIndex = -1;
                    break;
                }
            }
            return std::move(object);
        }
        return nullptr;
    }
Exemplo n.º 6
0
void destroyAssembler(Assembler a) {
  freeSlot(a->origin, a->id);
  free(a);
}