Exemplo n.º 1
0
int mod_rwlock(A_UNUSED int argc,A_UNUSED char *argv[]) {
	if((startsem = semcrt(READERS + WRITERS)) < 0)
		error("Unable to create start-sem");
	if(rwcrt(&lck) < 0)
		error("Unable to create rw-lock");

	for(int i = 0; i < WRITERS; ++i) {
		if(startthread(thread_write,NULL) < 0)
			error("Unable to start reader-thread");
	}
	for(int i = 0; i < READERS; ++i) {
		if(startthread(thread_read,NULL) < 0)
			error("Unable to start reader-thread");
	}
	/* go! */
	for(int i = 0; i < READERS + WRITERS; ++i)
		semup(startsem);
	join(0);

	if(curval != WRITERS * RETRIES)
		printe("Something went wrong. curval should be %d, but is %d\n",WRITERS * RETRIES,curval);

	rwdestr(&lck);
	return 0;
}
Exemplo n.º 2
0
int mod_fsreads(int argc,char *argv[]) {
	struct dirent e;
	DIR *dir;
	size_t count = argc >= 3 ? atoi(argv[2]) : 10;
	size_t i,j;
	for(i = 0; i < THREAD_COUNT; i++) {
		if(startthread(threadFunc,strdup("/zeros")) < 0)
			error("Unable to start thread");
	}

	for(j = 0; j < count; j++) {
		dir = opendir("/bin");
		if(!dir)
			error("Unable to open dir '/bin'");
		for(i = 0; i < THREAD_COUNT; i++) {
			char *path;
			if(!readdir(dir,&e))
				break;
			if(strcmp(e.d_name,".") == 0 || strcmp(e.d_name,"..") == 0)
				continue;
			path = (char*)malloc(MAX_PATH_LEN);
			if(!path)
				error("Not enough memory");
			strcpy(path,"/bin/");
			strcat(path,e.d_name);
			if(startthread(threadFunc,(void*)path) < 0)
				error("Unable to start thread");
		}
		closedir(dir);
	}
	join(0);
	return 0;
}
Exemplo n.º 3
0
 void Sound::update(const ServerMessage &message)
 {
     std::string fname;
     std::cout << "ohai from sound" << std::endl;
     switch(message.type)
     {
         case ServerMessage::death:
             startthread("resources/asta_la_vista.wav");
             break;
         case ServerMessage::move:
             startthread("resources/step.wav");
         break;
         default:
         break;
     }
 }
Exemplo n.º 4
0
/************
 *
 *功能:check cdms  statu  every    1s 
 *
 *
 *
 **/
void    mainview::CheckNetworkState()
{

    QFile file( "/sys/class/net/"+netconfig->devicename+"/operstate" );
    if ( file.open(QIODevice::ReadOnly | QIODevice::Text) ) {
        QByteArray  line = file.readLine();
        QString mg = line;
        file.close();
        qDebug() << mg;
        if(mg.compare("down\n") == 0)
        {
            if(netconfig->devicename.compare("wlan0")==0)
                QProcess::execute("ifconfig wlan0 up");
            else 
                startthread("/etc/init.d/networking  restart");
        }
    }

    QFile file_s( "./server.txt" );
    if ( file_s.open(QIODevice::ReadOnly | QIODevice::Text) ) {
        QByteArray  line = file_s.readLine();
        QString mg = line;
        file_s.close();
        QStringList md = mg.split("\n");
        http->CheckService(md.at(0));    
    }
    else
    {
        emit_widgets(1);
    }
    
    


}
Exemplo n.º 5
0
int mod_tls(A_UNUSED int argc,A_UNUSED char *argv[]) {
	a = tlsadd();
	b = tlsadd();
	if(startthread(otherThread,NULL) < 0)
		error("Unable to start thread");
	for(size_t i = 0; i < 4; i++) {
		tlsset(a,tlsget(a) + 1);
		tlsset(b,tlsget(b) + 1);
		printf("[%d] t1=%lu, t2=%lu\n",gettid(),tlsget(a),tlsget(b));
	}
	return 0;
}
Exemplo n.º 6
0
int mod_thread(A_UNUSED int argc,A_UNUSED char *argv[]) {
	int threads[THREAD_COUNT];
	if(usemcrt(&usem,1) < 0)
		error("Unable to create lock");

	size_t i;
	for(i = 0; i < THREAD_COUNT; i++)
		sassert((threads[i] = startthread(myThread,NULL)) >= 0);
	for(i = 0; i < THREAD_COUNT; i++)
		join(threads[i]);
	return EXIT_SUCCESS;
}
Exemplo n.º 7
0
static void firenforget(void) {
	size_t i;
	uint64_t start = rdtsc();
	for(i = 0; i < TEST_COUNT; ++i) {
		int res = startthread(thread_func,NULL);
		if(res < 0) {
			printe("startthread failed");
			return;
		}
	}
	uint64_t end = rdtsc();
	printf("startthread : %Lu cycles/call\n",(end - start) / TEST_COUNT);
}
Exemplo n.º 8
0
static void dotest(int fd) {
	regAddr = mmap(NULL,REG_SIZE,REG_SIZE,PROT_READ | PROT_WRITE,MAP_PRIVATE,fd,0);
	if(regAddr == NULL)
		error("mmap failed");

	int i;
	for(i = 0; i < THREAD_COUNT; ++i) {
		if(startthread(thread_entry,NULL) < 0)
			error("startthread failed");
	}

	join(0);

	munmap(regAddr);
}
Exemplo n.º 9
0
// deliver data that is already available
void datacloud::deliverdata(databuf *hfield,databuf *texture,databuf *fogmap,BOOLINT immediate,int *col,int *row,int *hlod,int *tlod)
   {
   float prio,p;

   jobqueueelem *job,*scan;

   BOOLINT isavailable;

   // start periodical tasks
   if (!immediate)
      {
      if (!DELIVERED)
         {
         // delete delayed jobs
         deletedelayedjobs();

         // delete delayed tiles
         deletedelayedtiles();

         // delete expired tiles
         deleteexpiredtiles();

         // shrink cache to maximum allowed size
         shrinkcache(MAXSIZE*1024*1024);
         }

      // load pending tiles in the background
      startthread();
      }

   // check deferred data delivery
   if (!immediate)
      if (DELIVERED)
         // stop deferred data delivery if time is up
         if (gettime()-DELIVERYSTART>TIMESLOT)
            {
            DELIVERED=FALSE;
            return;
            }

   // scan jobs
   if (!immediate)
      {
      prio=0.0f;

      job=NULL;
      scan=JOBQUEUETAIL;

      while (scan!=NULL)
         {
         p=0.0f;

         isavailable=TRUE;

         // check the availability of all required maps:

         if (scan->hfield!=NULL)
            if (!scan->hfield->isavailable) isavailable=FALSE;
            else p=getpriority(scan->hfield);

         if (scan->texture!=NULL)
            if (!scan->texture->isavailable) isavailable=FALSE;

         if (scan->fogmap!=NULL)
            if (!scan->fogmap->isavailable) isavailable=FALSE;

         // check the priority of the job
         if (isavailable && p>=prio)
            {
            prio=p;
            job=scan;
            }

         scan=scan->prev;
         }
      }
   else job=JOBQUEUE;

   // deferred data delivery
   if (job!=NULL)
      {
      // return maps
      if (job->hfield!=NULL) *hfield=*(job->hfield->tile);
      if (job->texture!=NULL) *texture=*(job->texture->tile);
      if (job->fogmap!=NULL) *fogmap=*(job->fogmap->tile);

      // return tile position
      if (col!=NULL) *col=job->col;
      if (row!=NULL) *row=job->row;

      // return level of detail
      if (hlod!=NULL) *hlod=job->hlod;
      if (tlod!=NULL) *tlod=job->tlod;

      // check for immediate delivery
      if (immediate) DELIVERED=FALSE;
      // remember starting time of deferred delivery
      else if (!DELIVERED)
         {
         DELIVERED=TRUE;
         DELIVERYSTART=gettime();
         }

      // remove finished job from queue
      deletejob(job);
      }
   else DELIVERED=FALSE;
   }
Exemplo n.º 10
0
void Updater::Start(){
	boost::thread startthread(Runner(this));
}
Exemplo n.º 11
0
 void onstart ()
 {
     startthread();
 }
Exemplo n.º 12
0
/************
 *
 *功能:主界面
 * 初始实例化所有的子窗口对象,设置字符编码,检测读取版本号,
 *更改或创建wifi管理工具wpa_supplicant的配置文件wpa_supplicant.conf,启动wifi后台管理服务,
 *设置主界面样式和初始化布局,多个子窗口间通信的信号和槽的初始化连接操作。
 *
 *
 **/
mainview::mainview(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::mainview)
{
    /****set Shortcut Keys*****/
    QShortcut  *m_ALT_down_Accel= new QShortcut(QKeySequence(tr("Ctrl+Shift+Alt+Y")), this);

    this->login     = NULL;
    this->netconfig = NULL;
    this->wifi      = NULL;
    ui->setupUi(this);
    logo_x=QApplication::desktop()->width()/2-100;
    logo_y=50;
    open = false;

    //this->setStyleSheet("background-image:url(:/images/terminal-bg.jpg);");
    /*********Set  Unicode *********/
    QTextCodec *codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForTr(codec);
    QTextCodec::setCodecForLocale(codec);
    QTextCodec::setCodecForCStrings(codec);

    spicy_thread_id.clear();

    QFile file_version( "./version.txt" );
    if ( file_version.open(QIODevice::ReadOnly | QIODevice::Text) ) {
        QByteArray  line = file_version.readLine();
        QString mg = line;
        file_version.close();
        QStringList md = mg.split("\n");
        version = "ver "+md.at(0);
    }
    else
    {
        version = "ver 3.0.1";
    }

        QFile  file_eth("./wpa_supplicant.conf");
            if (!file_eth.open(QIODevice::ReadOnly)&&
                file_eth.open(QIODevice::WriteOnly|QIODevice::Text)) {
                QTextStream out(&file_eth);
                out<<"ctrl_interface=/var/run/wpa_supplicant\nctrl_interface_group=0\nap_scan=1\n"<<endl;
                out.flush();

                file_eth.close();
            }
            else
                file_eth.close();

    //start wpa_supplicant  service
    QProcess::execute("ifconfig wlan0 up");
    startthread("wpa_supplicant -Dwext -iwlan0 -c ./wpa_supplicant.conf "); 
    //startthread("dhclient wlan0");
    /*********Set Button Style************/
    ui->pushButton->setStyleSheet("background-color:transparent");
    //ui->pushButton->setStyleSheet("border: 0px");//消除边框,取消点击效果
    ui->pushButton->setText("");
    ui->pushButton->setFlat(true);
    ui->pushButton->setFocusPolicy(Qt::NoFocus);
    ui->pushButton_1->setStyleSheet("QPushButton{text-align:left;}");
    ui->pushButton_1->setStyleSheet("border: 0px");//消除边框,取消点击效果
    ui->pushButton_1->setStyleSheet("background-color:transparent");
    ui->pushButton_1->setText("");
    ui->pushButton_1->setFlat(true);
    ui->pushButton_1->setFocusPolicy(Qt::NoFocus);
    //ui->pushButton_2->setStyleSheet("border: 0px");//消除边框,取消点击效果
    ui->pushButton_2->setStyleSheet("background-color:transparent");
    ui->pushButton_2->setText("");
    ui->pushButton_2->setFlat(true);
    ui->pushButton_2->setFocusPolicy(Qt::NoFocus);
    //ui->pushButton_3->setStyleSheet("border: 0px");//消除边框,取消点击效果
    ui->pushButton_3->setStyleSheet("background-color:transparent");
    ui->pushButton_3->setText("");
    ui->pushButton_3->setFlat(true);
    ui->pushButton_3->setFocusPolicy(Qt::NoFocus);
    //ui->pushButton_4->setStyleSheet("border: 0px");//消除边框,取消点击效果
    ui->pushButton_4->setStyleSheet("background-color:transparent");
    ui->pushButton_4->setText("");
    ui->pushButton_4->setFlat(true);
    ui->pushButton_4->setFocusPolicy(Qt::NoFocus);
    //ui->pushButton_5->setStyleSheet("border: 0px");//消除边框,取消点击效果
    ui->pushButton_5->setStyleSheet("background-color:transparent");
    ui->pushButton_5->setText("");
    ui->pushButton_5->setFlat(true);
    ui->pushButton_5->setFocusPolicy(Qt::NoFocus);
    //ui->pushButton_5->setVisible(false);
#if  1
    this->login = new  Login();
    this->netconfig = new NetworkConfig();
    this->wifi = new  Wifi();
    //this->termigrate = new  Termigrate();

    http = new  SocketService();
    changepasswd= new  ChangePasswd();
    hostlist = new  CreateVmlist();
    
    ui->widgetstack->addWidget(login);
    ui->widgetstack->addWidget(netconfig);
    ui->widgetstack->addWidget(changepasswd);
    ui->widgetstack->addWidget(wifi);
    ui->widgetstack->addWidget(hostlist);
    ui->widgetstack->resize(0,0);


    ui->widgetlist->setMovement(QListView::Static);
    ui->widgetlist->setFocusPolicy(Qt::NoFocus);
    ui->widgetlist->addItem("用户登录");
    ui->widgetlist->addItem("修改配置");
    ui->widgetlist->addItem("修改密码");
    ui->widgetlist->setSpacing(4);
    ui->widgetlist->setMouseTracking(true);
    ui->widgetlist->item(0)->setSizeHint(QSize(30,30));
    ui->widgetlist->item(1)->setSizeHint(QSize(30,30));
    ui->widgetlist->item(2)->setSizeHint(QSize(30,30));

    


    connect(this,SIGNAL(loadoperator(int)),this,SLOT(changeslots(int)));
    connect(ui->widgetlist,SIGNAL(currentRowChanged(int)),this,SLOT(deal_widgets(int)));
    connect(ui->widgetlist,SIGNAL(itemEntered(QListWidgetItem *)),this,SLOT(changeColor(QListWidgetItem *)));
    for(int i=0;i<ui->widgetlist->count();i++)
    {
        ui->widgetlist->item(i)->setBackground(QBrush(QColor(255,255,255)));
        ui->widgetlist->item(i)->setSelected(false);
    }


    /********Set  Function Key As following:reflush, wifi, help, shutdown, reboot**********/
    //get vmhostlist by  click  the  reflush  function
    setMouseTracking(true);
    ui->pushButton->setMouseTracking(true);
    ui->pushButton_1->setMouseTracking(true);
    ui->pushButton_2->setMouseTracking(true);
    ui->pushButton_3->setMouseTracking(true);
    ui->pushButton_4->setMouseTracking(true);
    ui->pushButton_5->setMouseTracking(true);
    connect(ui->pushButton,SIGNAL(clicked()),this->http,SLOT(gethostlist_slots()));
    connect(this->http,SIGNAL(signals_vmlist(QString)),this,SLOT(reflushlisttable(QString)));



    connect(ui->pushButton_1,SIGNAL(clicked()),this,SLOT(moreoperator()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(wifioperator()));
    connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(helpoperator()));
    connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(closecomputer()));
    connect(ui->pushButton_5,SIGNAL(clicked()),this,SLOT(rebootcomputer()));

    /*** this function is logining  when the login window whose login_signals had been sended by click the OK_button.**/
    connect(this->login,SIGNAL(signals_loginmsg(QString)),this->http,SLOT(login_slots(QString)));//send login information by httpsocket
    //connect(this->login,SIGNAL(signals_loginmsg(QString)),this->hostlist,SLOT(getuserinfo(QString)));//send login information 
    connect(this->http,SIGNAL(signals_loginview(int)),this,SLOT(emit_widgets(int)));
    connect(m_ALT_down_Accel, SIGNAL(activated()), this, SLOT(docreen()));

    /*** this is connect the signals with the networkconfigview and modify the password windows **/
    connect(this->netconfig,SIGNAL(signals_cdms(QString)),this->http,SLOT(registertocdms(QString)));
    connect(this->netconfig,SIGNAL(signals_modifycdms(QString)),this->http,SLOT(modifycdmsSlots(QString)));
    connect(this->changepasswd,SIGNAL(signals_modify(QString)),this->http,SLOT(updateUserinfo(QString)));
    connect(this->changepasswd,SIGNAL(docancel()),this->http,SLOT(gethostlist_slots()));

    /*** when click the OK_button that is the networkconfigview button,the thread will be create to runing shell command**/
    connect(this->netconfig,SIGNAL(signals_startthread(QString)),this,SLOT(startthread(QString)));


    /***it is registertocdms at first when the  programmer  running***/
    connect(this->http,SIGNAL(signals_register()),this->netconfig,SLOT(SendRegisterData()));
    /***if connect error,switch to netconfig view***/
    connect(this->http,SIGNAL(signals_connectError(int)),this,SLOT(emit_widgets(int)));
    /*** it's used to  start  the  spicy  protocol thread at the  SocketService class***/
    connect(this->http,SIGNAL(signals_startspicy(QString)),this,SLOT(startthread(QString)));
    //connect(this->http,SIGNAL(signals_tohostlistcheck(QString)),this->hostlist,SLOT(checkuserinfo(QString)));//check the userinfo is the same as  already logininfo

    /****there is  the  signals which serves for  vmhostlist contained  three vmhost most****/
    connect(this->hostlist,SIGNAL(signals_vm(QString)),this->http,SLOT(getconnectinfo_slots(QString)));
    connect(this->hostlist,SIGNAL(signals_connect(QString)),this->http,SLOT(isableconnectslots(QString)));
    connect(this->hostlist,SIGNAL(signals_start(QString)),this->http,SLOT(startvmslots(QString)));
    connect(this->hostlist,SIGNAL(signals_down(QString)),this->http,SLOT(shutdownvmslots(QString)));
    connect(this->hostlist,SIGNAL(signals_reboot(QString)),this->http,SLOT(rebootvmslots(QString)));

    /*******it's connected the  windows  with  the   choose  table on the  mainview  windows*******/
    connect(this,SIGNAL(signals_widgets(int)),ui->widgetstack,SLOT(setCurrentIndex(int)));
    /****it's used  to  execute  the  shell command int  the  function of  Wifi class****/
    connect(this->wifi,SIGNAL(signals_connect(QString)),this,SLOT(startthread(QString)));
    /****it's used to update  connected  wifiname on  the  mainview  background ********/
    connect(this->wifi,SIGNAL(signals_update()),this,SLOT(repaint()));
    connect(this->wifi,SIGNAL(siglogin(int)),this,SLOT(deal_widgets(int)));

    /******it's used  to  migrate  vitural machine ,that send oldip to tcp server for close it********/
    //connect(this->http,SIGNAL(signals_startmigrate(QString)),this->termigrate,SLOT(WriteIpToShm(QString)));
#endif
}
Exemplo n.º 13
0
// deliver data that is already available
void datacloud::deliverdata(databuf *hfield,databuf *texture,databuf *fogmap,BOOLINT immediate,int *col,int *row,int *hlod,int *tlod)
   {
   // start periodical tasks
   if (!immediate)
      {
      if (!DELIVERED)
         {
         // delete expired tiles
         deleteexpiredtiles();

         // shrink cache to maximum allowed size
         shrinkcache(MAXSIZE*1024*1024);
         }

      // load pending tiles in the background
      startthread();
      }

   // check deferred data delivery
   if (!immediate)
      if (DELIVERED)
         {
         double upload=minitime()-DELIVERYSTART;

         // stop deferred data delivery because time is up
         if (upload>TIMESLOT)
            {
            DELIVERED=FALSE;
            return;
            }
         }

   jobqueueelem *job=JOBQUEUE;

   // scan jobs
   if (!immediate)
      while (job!=NULL)
         {
         BOOLINT isavailable=TRUE;

         // check availability of maps:

         if (job->hfield!=NULL)
            if (!job->hfield->isavailable) isavailable=FALSE;

         if (job->texture!=NULL)
            if (!job->texture->isavailable) isavailable=FALSE;

         if (job->fogmap!=NULL)
            if (!job->fogmap->isavailable) isavailable=FALSE;

         // start deferred data delivery
         if (isavailable) break;

         job=job->next;
         }

   // data delivery
   if (job!=NULL)
      {
      // return maps
      if (job->hfield!=NULL) *hfield=*(job->hfield->tile);
      if (job->texture!=NULL) *texture=*(job->texture->tile);
      if (job->fogmap!=NULL) *fogmap=*(job->fogmap->tile);

      // return tile position
      if (col!=NULL) *col=job->col;
      if (row!=NULL) *row=job->row;

      // return level of detail
      if (hlod!=NULL) *hlod=job->hlod;
      if (tlod!=NULL) *tlod=job->tlod;

      // check for immediate delivery
      if (immediate) DELIVERED=FALSE;
      // remember starting time of deferred delivery
      else if (!DELIVERED)
         {
         DELIVERED=TRUE;
         DELIVERYSTART=minitime();
         }

      // remove finished job from queue
      deletejob(job);
      }
   else DELIVERED=FALSE;
   }