void brelse(buf *buffer){
  //wakeup();
  if(CheckStatus(buffer, STAT_LOCKED)){
    printf("Wakeup processes wating for any buffer\n");
    if(CheckStatus(buffer, STAT_LOCKED | STAT_VALID | STAT_WAITED)){
      //wakeup();
      printf("Wakeup processes waiting for buffer of blkno %d\n", buffer -> blkno);
    }
    //raise_cpu_level();
    if(CheckStatus(buffer, STAT_VALID) && !CheckStatus(buffer, STAT_OLD)){
      printf("Enqueued to the tail of free list\n");
      insert_list(&f_head, buffer, FREETAIL);
      MakeStatus(buffer, STAT_VALID);
    }
    else{
      printf("Enqueued to the head of free list\n");
      insert_list(&f_head, buffer, FREEHEAD);
      MakeStatus(buffer, STAT_VALID);
    }
    //lower_cpu_level();
  }
  else{
    printf("Error! buffer should be locked\n");
  }
}
buf *getblk(int blknum){
  while(&h_head[blknum % 4] != NULL){
    buf *buffer = Search(blknum);
    if(buffer != NULL){
      assert(buffer != NULL);
      if(IsStatus(buffer, STAT_LOCKED)){
	//sleep();
	printf("SCENARIO 5\n");
	printf("Process goes to sleep\n");
	AddStatus(buffer, STAT_WAITED);
	return NULL;
	continue;
      }
      //scenario 1
      printf("SCENARIO 1\n");
      MakeStatus(buffer, (STAT_LOCKED | STAT_VALID));
      RemFromFreeList(buffer);
      return buffer;	
    }
    else{
      //if(IsInFreeList(buffer)){
      if(IsEmptyFree()){
	//scenario 4
	//sleep();
	printf("SCENARIO 4\n");
	printf("Process goes to sleep\n");
	return buffer;
	//continue;
      }
      //RemFromFreeList(buffer);
      //RemoveFromFree()
      buf *ref = ref_free_head();
      if(CheckStatus(ref, STAT_DWR)){
	//scenario 3
	printf("SCENARIO 3\n");	//asynchronous write buffer to disk;
	buf *prev = ref -> free_bp;
	buf *next = ref -> free_fp;
	prev -> free_fp = next;
	next -> free_bp = prev;
	MakeStatus(ref, STAT_LOCKED | STAT_VALID | STAT_KRDWR | STAT_OLD);
	continue;
      }
      //scenario 2
      printf("SCENARIO 2\n");
      buf *additionalbuf = remove_free_head();
      RemStatus(additionalbuf, STAT_VALID);
      additionalbuf -> blkno = blknum;
      AddToHash(additionalbuf);
      printf("Kernel HDD access occuring\n");
      AddStatus(additionalbuf, STAT_KRDWR);
      printf("Kernel HDD access finished\n");
      RemStatus(additionalbuf, STAT_KRDWR);
      AddStatus(additionalbuf, STAT_VALID);
      return additionalbuf;
    }
  }
  printf("BUFFER NOT FOUND\n");
  return NULL;
}
Exemple #3
0
void LMsg(int err, const char *fmt, ...)
{
	va_list ap;
	char buf[MAXPATHLEN * 2];
	char *p = buf;
	Canvas *cv;

	va_start(ap, fmt);
	(void)vsnprintf(p, ARRAY_SIZE(buf) - 100, fmt, ap);
	va_end(ap);
	if (err) {
		p += strlen(p);
		*p++ = ':';
		*p++ = ' ';
		strncpy(p, strerror(err), buf + ARRAY_SIZE(buf) - p - 1);
		buf[ARRAY_SIZE(buf) - 1] = 0;
	}
	for (display = displays; display; display = display->d_next) {
		for (cv = D_cvlist; cv; cv = cv->c_next)
			if (cv->c_layer == flayer)
				break;
		if (cv == NULL)
			continue;
		MakeStatus(buf);
	}
}
Exemple #4
0
void XmppClient::Connect(std::string username, std::string password)
{
    this->username = username;
    this->password = password;

    client = new Client(JID (std::string(username + "@pvp.net/xiff")), std::string("AIR_" + password));
    connectionTcpClient = new ConnectionTCPClient( client->logInstance(), (QString("chat." + region() + ".lol.riotgames.com")).toUtf8().constData(), 5223);
    connectionTls = new ConnectionTLS( client, connectionTcpClient, client->logInstance());
    client->setConnectionImpl(connectionTls);
    client->setCompression(true);
    client->registerMessageHandler(this);
    client->registerPresenceHandler(this);
    client->connect(false);
    xmppHandler = new std::thread(ClientReceiveUpdate, client);

    client->setPresence (Presence::Chat, 1, MakeStatus(1, "", 0, 0, 0, "", 0, 0, 0, "", "", "", 0));
    client->rosterManager()->registerRosterListener(this);
    isConnected = true;
}