Exemplo n.º 1
0
Arquivo: tvthread.c Projeto: att/ast
tmain() {
    UNUSED(argc);
    UNUSED(argv);
    pthread_t thread[N_THREADS];
    size_t k, p, n;
    Mydisc_t disc[2];
    Obj_t *o, *list[2], obj;

    topts();

    /* create two dictionaries to volley objects back and forth */
    for (n = 0; n < 2; ++n) {
        if (!(Dict[n] = opendictionary(&disc[n]))) terror("Can't open dictionary %d", n);

        /* make objects */
        if (!(list[n] = malloc((N_OBJ / 2) * sizeof(Obj_t)))) terror("malloc failed %d", n);
        memset(list[n], 0, (N_OBJ / 2) * sizeof(Obj_t));

        for (o = list[n], k = 0; k < N_OBJ / 2; ++k, ++o) {
            o->value = n == 0 ? k : k + N_OBJ / 2;

            if (dtinsert(Dict[n], o) != o) terror("Insert failed n=%d k=%d", n, k);
            if (dtsearch(Dict[n], o) != o) { /* verify insert succeeded */
                terror("Search failed n=%d k=%d", n, k);
            }

            o->ins[n] += 1;
        }
    }

    for (p = 0; p < N_THREADS; ++p) pthread_create(&thread[p], 0, volley, (void *)((long)(p % 2)));

    for (p = 0; p < N_THREADS; ++p) pthread_join(thread[p], 0);

    tinfo("\tCheck integrity");
    n = dtsize(Dict[0]);
    p = dtsize(Dict[1]);
    tinfo("Dict[0]=%d Dict[1]=%d", n, p);
    if ((n + p) != N_OBJ) {
        for (k = 0; k < N_OBJ; ++k) {
            obj.value = k;
            if ((o = dtsearch(Dict[0], &obj))) continue;
            if ((o = dtsearch(Dict[1], &obj))) continue;
            terror("%d not found", k);
            dtsearch(Dict[0], &obj);
            dtsearch(Dict[1], &obj);
        }

        terror("Expecting %d objects but got (Dict[0]=%d + Dict[1]=%d) = %d", N_OBJ, n, p, n + p);
    }

    texit(0);
}
Exemplo n.º 2
0
/* to test handling of writing whole lines */
static ssize_t writef(Sfio_t* f, const void* data, size_t n, Sfdisc_t* disc)
{
	char	*dt;
	ssize_t	k;

	for(dt = (char*)data + n-1; dt >= (char*)data; --dt)
		if(*dt == '\n')
			break;

	if((k = (dt - (char*)data) + 1) == 0 )
		tinfo("Processing a partial line, ok");

	return k;
}
Exemplo n.º 3
0
int task_module::gm_rm_task(player_obj *player, const int task_cid)
{
  task_info_map_itor itor = player->task_data_->task_info_map_.find(task_cid);
  if (itor != player->task_data_->task_info_map_.end())
  {
    task_info * tinfo = itor->second;
    player->task_data_->task_info_map_.erase(task_cid);
    task_module::do_del_task_todo_info(player, task_cid);
    task_module::do_update_task_info_2_db(player, REQ_DELETE_TASK, tinfo);
    task_module::do_update_task_info_2_client(player, TASK_DEL, tinfo);
    task_info_pool::instance()->release(tinfo);
  }
  if (player->task_data_->task_acceptable_list_.find(task_cid))
  {
    player->task_data_->task_acceptable_list_.remove(task_cid);
    task_info tinfo(player->id(), task_cid, TASK_ST_ACCEPTABLE);
    task_module::do_update_task_info_2_client(player, TASK_DEL, &tinfo);
  }
  return 0;
}
Exemplo n.º 4
0
Arquivo: tvthread.c Projeto: att/ast
/* swap objects from one dictionary to another */
static void *volley(void *arg) {
    int deldt, insdt, n_move, dir, k;
    Obj_t obj, *o, *rv;

    Nthreads += 1; /* wait until all threads have been started */
    while (Nthreads < N_THREADS) tmsleep(0, 1);

    if ((deldt = (int)((long)arg)) < 0 || deldt > 1) {
        terror("Thread number must be 0 or 1, not %d", deldt);
    }
    insdt = !deldt;

    n_move = 0;
    for (dir = 1; dir >= -1; dir -= 2) {
        for (k = dir > 0 ? 0 : N_OBJ - 1; k >= 0 && k < N_OBJ; k += dir) {
            obj.value = k;
            if (!(o = dtsearch(Dict[deldt], &obj))) continue;

            if ((rv = dtdelete(Dict[deldt], o)) == o) {
                asoincint(&o->del[deldt]);

                if ((rv = dtinsert(Dict[insdt], o)) != o) terror("Insert %d failed", o->value);

                asoincint(&o->ins[insdt]);

                n_move += 1;
            } else if (rv) {
                terror("Unknown object %d", rv->value);
            }

            if (k % 100 == 0) tmsleep(0, 1);
        }
    }
    tinfo("Move %d (Dict[%d] -> Dict[%d])", n_move, deldt, insdt);

    return 0;
}
Exemplo n.º 5
0
tmain()
{
	int		k, code = 0;
	Vmalloc_t	*shm, *map;
	char		*arg[5];
	pid_t		ppid, cpid;

	if(k = tchild())
	{	cpid = getpid();
		shmfile = argv[k];
		mapfile = argv[k+1];

		tinfo("Child[pid=%d]: allocating heap memory before opening shm region", cpid);
		for(k = 0; k < 1024; ++k)
			if(!malloc(32*1024) )
				terror("Child[pid=%d]: Can't allocate segment %d", cpid, k);

		if(*shmfile)
		{	tinfo("Child[pid=%d]: opening shm region", cpid);
			if(!(shm = vmmopen(shmfile, 1, MAPSIZE)) )
				terror("Child[pid=%d]: Can't open shm region in child process", cpid);
			tinfo("Child[pid=%d]: shm region opened", cpid);
		}

		tinfo("Child[pid=%d]: allocating heap memory before opening map region", cpid);
		for(k = 0; k < 1024; ++k)
			if(!malloc(32*1024) )
				terror("Child[pid=%d]: Can't allocate segment %d", cpid, k);

		if(*mapfile)
		{	tinfo("Child[pid=%d]: opening map region", cpid);
			if(!(map = vmmopen(mapfile, -1, MAPSIZE)) )
				terror("Child[pid=%d]: Can't open map region in child process", cpid);
			tinfo("Child[pid=%d]: map region opened", cpid);
		}
	}
	else
	{	ppid = getpid();
		shmfile = tstfile("shm", -1);
		mapfile = tstfile("map", -1);
		(void)unlink(shmfile);
		(void)unlink(mapfile);
		
		tinfo("Parent[pid=%d]: %s: opening shm region", ppid, shmfile);
		if(shm = vmmopen(shmfile, 1, MAPSIZE) )
			tinfo("Parent[pid=%d]: %s: shm region opened", ppid, shmfile);
		else
		{	tnote("shm not supported");
			shmfile = "";
		}

		tinfo("Parent[pid=%d]: %s: opening map region", ppid, mapfile);
		if(map = vmmopen(mapfile, -1, MAPSIZE) )
			tinfo("Parent[pid=%d]: %s: map region opened", ppid, mapfile);
		else
		{	tnote("map not supported");
			mapfile = "";
		}

		switch((cpid = fork()) ) /* make a child process */
		{ default :
			code = twait(&cpid, 1);
			break;
		  case 0 :
			arg[0] = argv[0];
			arg[1] = "--child";
			arg[2] = shmfile;
			arg[3] = mapfile;
			arg[4] = 0;
			if(execv(argv[0], arg) < 0 )
				terror("Could not exec child process");
		  case -1:
			terror("Could not fork a child process");
		}
	}

	vmmrelease(shm, 1); vmclose(shm);
	vmmrelease(map, 1); vmclose(map);

	texit(code);
}
Exemplo n.º 6
0
tmain()
{
	Dt_t		*dt;
	Dtstat_t	stat;
	Obj_t		*p, *o, *obj, proto;
	char		*name;
	long		i, k, mid, n_mid, n_obj, meth;

	/* construct repetitive objects */
	for(i = 0; i < N_OBJ; i += R_OBJ)
	{	for(k = 0; k < R_OBJ; ++k)
		{	Obj[i+k].key = i;
			Obj[i+k].ord = k;
		}
	}

	for(meth = 0; meth < 4; ++meth)
	{	switch(meth)
		{ case 0:
			name = "Dtobag";
			if(!(dt = dtopen(&Disc, Dtobag)) )
				terror("%s: Can't open dictionary", name);
			break;
		  case 1:
			name = "Dtbag";
			if(!(dt = dtopen(&Disc, Dtbag)) )
				terror("%s: Can't open dictionary", name);
			break;
		  case 2:
			name = "Dtrhbag";
			if(!(dt = dtopen(&Disc, Dtrhbag)) )
				terror("%s: Can't open dictionary", name);
			break;
		  case 3:
			name = "Dtlist";
			if(!(dt = dtopen(&Disc, Dtlist)) )
				terror("%s: Can't open dictionary", name);
			break;
		  default: terror("Unknown storage method");
			break;
		}
		tinfo("Testing method %s:", name);
		dtcustomize(dt, DT_SHARE, 1); /* make it more interesting */

		/* add all objects into dictionary */
		for(k = 0; k < R_OBJ; ++k)
		for(i = 0; i < N_OBJ/R_OBJ; ++i)
		{	obj = Obj + i*R_OBJ + k;
			o = (meth == 3 || i%2 == 0) ? dtappend(dt,obj) : dtinsert(dt,obj);
			if(o != obj)
				terror("%s: dtappend (key=%d,ord=%d) failed", name, obj->key, obj->ord);
		}

		mid = ((N_OBJ/R_OBJ)/2) * R_OBJ; /* key for middle group */
		proto.key = mid;
		proto.ord = -1;

		if(meth == 3) /* testing ATMOST/ATLEAST for Dtlist */
		{	/* note that dtappend() was used to keep objects in order of insertion */
			if(!(o = dtatmost(dt, &proto)) )
				terror("%s: dtatmost (key=%d) failed", name, mid);
			if(o->ord != 0)
				terror("%s: dtatmost (key=%d) but ord=%d > 0", name, o->key, o->ord);

			if(!(o = dtatleast(dt, &proto)) )
				terror("%s: dtatleast (key=%d) failed", name, mid);
			if(o->ord != R_OBJ-1)
				terror("%s: dtatleast (key=%d) but ord=%d > 0", name, o->key, o->ord);

			n_obj = 0; /* test ordering */
			for(p = NIL(Obj_t*), o = dtfirst(dt); o; p = o, o = dtnext(dt,o) )
			{	n_obj += 1;
				if(p && p->ord > o->ord)
					terror("%s: objects not ordered correctly p=%d > o=%d",
						name, p->ord, o->ord);
			}
			if(n_obj != N_OBJ)
				terror("%s: Bad object count %d != %d", n_obj, N_OBJ);
		}

		if(meth == 0) /* testing ordering properties of Dtobag */
		{	
			n_obj = 0; /* test atmost/next */
			for(o = dtatmost(dt, &proto); o; o = dtnext(dt,o) )
			{	if(o->key == mid)
					n_obj += 1;
				else	break;
			}
			if(n_obj != R_OBJ)
				terror("%s: dtatmost/dtnext count n_obj=%d != %d", name, n_obj, R_OBJ);

			n_obj = 0; /* test atleast/prev */
			for(o = dtatleast(dt, &proto); o; o = dtprev(dt,o) )
			{	if(o->key == mid)
					n_obj += 1;
				else	break;
			}
			if(n_obj != R_OBJ)
				terror("%s: dtatleast/dtprev count n_obj=%d != %d", name, n_obj, R_OBJ);

			n_obj = 0; /* test linear order */
			for(p = NIL(Obj_t*), o = dtfirst(dt); o; p = o, o = dtnext(dt,o) )
			{	n_obj += 1;
				if(p && p->key > o->key)
					terror("%s: objects not ordered correctly p=%d > o=%d",
						name, p->key, o->key);
			}
			if(n_obj != N_OBJ)
				terror("%s: Bad object count %d != %d", n_obj, N_OBJ);
		}

		n_mid = n_obj = 0; /* walk forward and count objects */
		for(o = dtfirst(dt); o; o = dtnext(dt,o))
		{	n_obj += 1;
			if(o->key == mid)
				n_mid += 1;
		}
		if(n_obj != N_OBJ)
			terror("%s: Walk forward n_obj=%d != %d", name, n_obj, N_OBJ);
		if(n_mid != R_OBJ)
			terror("%s: Walk forward n_mid=%d != %d", name, n_mid, R_OBJ);

		n_mid = n_obj = 0; /* walk backward and count objects */
		for(o = dtlast(dt); o; o = dtprev(dt,o))
		{	n_obj += 1;
			if(o->key == mid)
				n_mid += 1;
		}
		if(n_obj != N_OBJ)
			terror("%s: Walk backward n_obj=%d != %d", name, n_obj, N_OBJ);
		if(n_mid != R_OBJ)
			terror("%s: Walk backward n_mid=%d != %d", name, n_mid, R_OBJ);

		n_mid = n_obj = 0; /* walk flattened list and count objects */
		for(o = (Obj_t*)dtflatten(dt); o; o = (Obj_t*)dtlink(dt,o) )
		{	n_obj += 1;
			if(o->key == mid)
				n_mid += 1;
		}
		if(n_obj != N_OBJ)
			terror("%s: Walk flattened list n_obj=%d != %d", name, n_obj, N_OBJ);
		if(n_mid != R_OBJ)
			terror("%s: Walk flattened list n_mid=%d != %d", name, n_mid, R_OBJ);

		n_mid = 0; /* delete a bunch of objects */
		for(i = 0; i < N_OBJ-1; i += R_OBJ)
		{	obj = Obj + i + R_OBJ/2; /* use the one in the middle of group */

			if((o = dtremove(dt, obj)) == obj )
				n_mid += 1;
			else	terror("%s: dtremove (key=%d,ord=%d) wrongly yielded (key=%d,ord=%d)",
					name, obj->key, obj->ord, o->key, o->ord);

			if((o = dtremove(dt, obj)) != NIL(Obj_t*) )
				terror("%s: dtremove (key=%d,ord=%d) wrongly yielded (key=%d,ord=%d)",
					name, obj->key, obj->ord, o->key, o->ord);

			if((o = dtdelete(dt, obj)) != NIL(Obj_t*) )
				n_mid += 1;
			else	terror("%s: dtdelete matching object to (key=%d,ord=%d) failed",
					name, obj->key, obj->ord);
		}
Exemplo n.º 7
0
tmain()
{
	Obj_t		*o, *next;
	Void_t		*huge;
	size_t		hugesz;
	Vmstat_t	sb;
	ssize_t		k, p;

	srandom(0);

	hugesz = Z_HUGE; /* one huge block to be resized occasionally */
	if(!(huge = vmalloc(Vmregion, hugesz)) )
		terror("Can't allocate block");

	for(k = 0; k < N_OBJ; ++k)
	{	
		/* free/resize all on this list */
		for(o = List[k]; o; o = next)
		{	next = o->next;

			if((RAND()%2) == 0 ) /* flip a coin to see if freeing */
				vmfree(Vmregion, o->obj);
			else /* resizing */
			{	o->size = ALLOCSIZE();
				if(!(o->obj = vmresize(Vmregion,o->obj,o->size,VM_RSMOVE)) )
					terror("Vmresize failed");
				TIME(p, k, o->size); /* add to a future list */
				o->next = List[p]; List[p] = o;
			}
		}

		if(COMPACT(k)) /* global compaction */
		{	if(vmstat(Vmregion, &sb) < 0)
				terror("Vmstat failed");
			tinfo("Arena: busy=(%u,%u) free=(%u,%u) extent=%u #segs=%d",
				sb.n_busy,sb.s_busy, sb.n_free,sb.s_free,
				sb.extent, sb.n_seg);
			if(vmcompact(Vmregion) < 0 )
				terror("Vmcompact failed");
			if(vmstat(Vmregion, &sb) < 0)
				terror("Vmstat failed");
			tinfo("Compact: busy=(%u,%u) free=(%u,%u) extent=%u #segs=%d",
				sb.n_busy,sb.s_busy, sb.n_free,sb.s_free,
				sb.extent, sb.n_seg);
		}

		if(RESIZE(k)) /* make the huge block bigger */
		{	hugesz += Z_HUGE;
			if(!(huge = vmresize(Vmregion, huge, hugesz, VM_RSMOVE)) )
				terror("Bad resize of huge block");
		}

		o = Obj+k; /* allocate a new block */
		o->size = ALLOCSIZE();
		if(!(o->obj = vmalloc(Vmregion, o->size)) )
			terror("Vmalloc failed");
		TIME(p, k, o->size);
		o->next = List[p]; List[p] = o;
	}

	if(vmdbcheck(Vmregion) < 0)
		terror("Corrupted region");

	if(vmstat(Vmregion, &sb) < 0)
		terror("Vmstat failed");
	tinfo("Full: Busy=(%u,%u) Free=(%u,%u) Extent=%u #segs=%d\n",
		sb.n_busy, sb.s_busy, sb.n_free, sb.s_free, sb.extent, sb.n_seg);
	if(vmcompact(Vmregion) < 0 )
		terror("Vmcompact failed");
	if(vmstat(Vmregion, &sb) < 0)
		terror("Vmstat failed");
	tinfo("Compact: Busy=(%u,%u) Free=(%u,%u) Extent=%u #segs=%d\n",
		sb.n_busy, sb.s_busy, sb.n_free, sb.s_free, sb.extent, sb.n_seg);

	/* now free all left-overs */
	for(o = List[N_OBJ]; o; o = o->next)
		vmfree(Vmregion,o->obj);
	vmfree(Vmregion,huge);

	if(vmstat(Vmregion, &sb) < 0)
		terror("Vmstat failed");
	tinfo("Free: Busy=(%u,%u) Free=(%u,%u) Extent=%u #segs=%d\n",
		sb.n_busy, sb.s_busy, sb.n_free, sb.s_free, sb.extent, sb.n_seg);
	if(vmcompact(Vmregion) < 0 )
		terror("Vmcompact failed2");
	if(vmstat(Vmregion, &sb) < 0)
		terror("Vmstat failed");
	tinfo("Compact: Busy=(%u,%u) Free=(%u,%u) Extent=%u #segs=%d\n",
		sb.n_busy, sb.s_busy, sb.n_free, sb.s_free, sb.extent, sb.n_seg);

	if(!(huge = vmalloc(Vmregion, 10)))
		terror("Vmalloc failed");
	if(vmstat(Vmregion, &sb) < 0)
		terror("Vmstat failed");
	tinfo("Small: Busy=(%u,%u) Free=(%u,%u) Extent=%u #segs=%d\n",
		sb.n_busy, sb.s_busy, sb.n_free, sb.s_free, sb.extent, sb.n_seg);

	texit(0);
}
Exemplo n.º 8
0
tmain()
{
	int		i, rv;
	void		*status;
	char		*objs[N_THREAD];
	pthread_t	thread[N_THREAD];
	int		nthreads = N_THREAD;
	int		iterations = ITERATIONS;
	int		objsize = OBJSIZE;
	int		repetitions = REPETITIONS;
#ifdef VMALLOC
	Vmstat_t	vmst;
#endif

	tresource(-1, 0);

	while(argc > 1)
	{	if(argv[1][0] == '-' && argv[1][1] == 't')
			nthreads = atoi(argv[1]+2);
		else if(argv[1][0] == '-' && argv[1][1] == 'i')
			iterations = atoi(argv[1]+2);
		else if(argv[1][0] == '-' && argv[1][1] == 'r')
			repetitions = atoi(argv[1]+2);
		else if(argv[1][0] == '-' && argv[1][1] == 'z')
			objsize = atoi(argv[1]+2);
		argc--; argv++;
	}

	if(nthreads <= 0 || nthreads > N_THREAD)
		terror("nthreads=%d must be in 1..%d", nthreads, N_THREAD);
	if(repetitions < nthreads)
		repetitions = 0;

	tinfo("nthreads=%d iterations=%d objsize=%d repetitions=%d",
		nthreads, iterations, objsize, repetitions );

	for(i = 0; i < nthreads; ++i)
		if(!(objs[i] = (char*)malloc(objsize)) )
			terror("Can't allocate objs[%d]", i);

	for(i = 0; i < nthreads; ++i)
	{	Worker_t	*w = (Worker_t*)malloc(sizeof(Worker_t));
		w->object = objs[i];
		w->objsize = objsize;
		w->iterations = iterations;
		w->repetitions = repetitions/nthreads;
		if((rv = pthread_create(&thread[i], NULL, worker, (void*)w)) != 0)
			terror("Failed to create thread %d", i);
	}
	for(i = 0; i < nthreads; ++i)
		if((rv = pthread_join(thread[i], &status)) != 0)
			terror("Failed waiting for thread %d", i);

	tresource(0, 0);

#ifdef VMALLOC
	vmstat(0, &vmst);
	twarn(vmst.mesg);
#endif

	texit(0);
}
Exemplo n.º 9
0
void defaults::read_config(void)
{
	int ival,i,i2,iar[4];
	float fval;
	bool ok;

	borderfont.setPixelSize(windowbuttonsize-5);

	static const char *par[] = {
	"ToolbarHeight",          // 0
	"WindowButtonSize",       // 1
	"LowerBorderHeight",      // 2
	"LowerBorderWidth",       // 3
	"PagerHeight",            // 4
	"WindowFontName",         // 5
	"WindowFontHeight",       // 6
	"IconFontName",           // 7
	"IconFontHeight",         // 8
	"ToolbarOnTop",           // 9
	"VirtualDesktops",        // 10 
	"ShowMenue",              // 11
	"AutoRaiseTime",          // 12
	"InactiveWindowColor",    // 13
	"UrgentWindowColor",      // 14
	"StartClientsUrgent",     // 15
	"RootBackgroundColor",    // 16 
	"RootBackgroundPicture",  // 17
	"PagerActiveColor",       // 18
	"PagerVisibleColor",      // 19
	"PagerInvisibleColor",    // 20
	"ShowClientMachines",     // 21
	"Exec",                   // 22
	"ShowWinlist",            // 23
	"Style",                  // 24
	"Maximize1",              // 25
	"Maximize2",              // 26
	"TileSplit",              // 27
	"TileMaxWithTab",         // 28
	"TileStart",              // 29
	"TileMinframe",           // 30
	NULL };
	
	QString fname;
	QString p1,p2;
	QFileInfo acc;
	QStyle *qs;
	
	fname = WindowManager::get_cfile("defaults");
	QFile istr(fname);

	if(fname.isNull() || ! istr.open(QIODevice::ReadOnly))
	{
		if(! fname.isNull())
			perror("cannot open defaults file");
	}	
	else
	{
		while(! istr.atEnd())
		{
			QTextStream tis(istr.readLine(1024));
			tis >> p1;
			if(p1.isEmpty() || p1[0] == '#')
				continue;

			tis >> p2;
			if(p2.isEmpty())
				continue;

			i = 0;
			do
			{
				if(p1 == par[i])
					break;
			}
			while(par[++i] != NULL);
			
			switch(i)
			{
				case 0:
					ival = p2.toInt();
	
					if(ival < 10 || ival > 500)
						logmsg << "ToolbarHeight: Value out of range\n";
					else
						tb_height = ival;
						
					break;
	
				case 1:
					ival = p2.toInt();
		
					if(ival < 6 || ival > 500)
						logmsg << "WindowButtonSize: Value out of range\n";
					else
						windowbuttonsize = ival;
		
					break;
	
				case 2:
					ival = p2.toInt();
	
					if(ival < 1 || ival > 500)
						logmsg << "LowerBorderHeight: Value out of range\n";
					else
							lowerborderheight = ival;
	
					break;
	
				case 3:
					ival = p2.toInt();
	
					if(ival < 1 || ival > 500)
						logmsg << "LowerBorderWidth: Value out of range\n";
					else
						lowerborderwidth = ival;
	
					break;
	
				case 4:
					ival = p2.toInt();
	
					if(ival < 4 && ival > 500)
						logmsg << "PagerHeight: Value out of range\n";
					else
						pager_height = ival;
	
					break;
	
				case 5:
					if(p2.toLower() == "fixed")
						break;
						
					borderfont.setFamily(p2);
					break;
	
				case 6:
					ival = p2.toInt();
	
					if(ival < 4 || ival > 500)
						logmsg << "WindowFontHeight: Value out of range\n";
					else
						borderfont.setPixelSize(ival);
	
					break;
	
				case 7:
					if(p2.toLower() == "fixed")
						break;
						
					toolbarfont.setFamily(p2);
					break;
	
				case 8:
					ival = p2.toInt();
	
					if(ival < 4 || ival > 500)
						logmsg << "IconFontHeight: Value out of range\n";
					else
						toolbarfont.setPixelSize(ival);
	
					break;
	
				case 9:
					if(p2.toUpper() == "TRUE")
						toolbar_top = TRUE;
		
					break;
	
				case 10:
					ival = p2.toInt();
	
					if(ival < 1 || ival > MAXDESKS)
					{
						logmsg << "VirtualDesktops: Value out of range\n";
						vdesks = 3;
					}
					else
						vdesks = ival;
	
					break;	
	
				case 11:
					if(p2.toUpper() == "FALSE")
						show_menu = FALSE;
	
					break;
	
				case 12:
					ival = p2.toInt();
	
					if(ival < 0 || ival > 100000)
						logmsg << "AutoRaiseTime: Value out of range\n";
					else
						autofocustime = ival;
	
					break;
					
				case 13:
					inactive_bg = new QColor();
					inactive_bg->setNamedColor(p2);
					break;
	
				case 14:
					urgent_bg.setNamedColor(p2);
					break;
	
				case 15:
					if(p2.toUpper() == "FALSE")
						starturgent = FALSE;
	
					break;
	
				case 16:
					root_bg.setNamedColor(p2);
					break;
	
				case 17:
					acc.setFile(p2);
					if(! acc.isReadable())
						break;
						
					root_pix = p2;
					break;
	
				case 18:
					pager_active.setNamedColor(p2);
					break;
	
				case 19:
					pager_visible.setNamedColor(p2);
					break;
	
				case 20:
					pager_window.setNamedColor(p2);
					break;
	
				case 21:
					if(p2.toUpper() == "TRUE")
						showclientmachines = TRUE;

					break;

				case 22:
					if(start_restart == FALSE)
					{
						QString cml = p2+tis.readLine();
						initexec.push(new QByteArray(cml.toAscii()));
					}	
					break;
				
				case 23:
					if(p2.toUpper() == "FALSE")
						show_winlist = FALSE;
	
					break;

				case 24:
					if((qs = QStyleFactory::create(p2)) == NULL)
					{
						logmsg << "Unknown style: " << p2 << '\n';
						if(p2 == "Platinum")
							p2 = "Plastique";
							
						if((qs = QStyleFactory::create(p2)) == NULL)
							break;
					}
					QApplication::setStyle(qs);
					break;

				case 25:
				case 26:
					i2 = 0;
					while(1)
					{
						iar[i2] = p2.toInt(&ok);

						if(ok == FALSE || i2 > 2)
							break;

						tis >> p2;

						if(p2.isEmpty())
							break;

						i2++;
					}
					if(i2 < 3)
					{
						logmsg << "invalid parameter for maximize\n";
						break;
					}
					
					if(i == 25)
					{
						tmx1 = iar[0]; tmy1 = iar[1]; tmx2 = iar[2]; tmy2 = iar[3];
					}	
					else	
					{
						smx1 = iar[0]; smy1 = iar[1]; smx2 = iar[2]; smy2 = iar[3];
					}	

					break;	

				case 27:
					fval = p2.toFloat();

					if(fval < 1 || fval > 99)
						logmsg << "TileSplit: Value out of range\n";
					else
						tleftspace = fval/100;

					break;

				case 28: 
					ival = p2.toInt();

					if(ival < 0 || ival > 10000)
						logmsg << "TileMaxOnTab: Value out of range\n";
					else
						maxontab = ival;

					break;

				case 29:
					for(i2=0; i2 < 10; i2++)
					{
						ival = p2.toInt(&ok);

						if(ok == FALSE)
							break;

						if(ival < 1 || ival > 10)
						{
							logmsg << "TileStart: value out of range\n";
							continue;
						}

						sttiled[ival-1] = TRUE;

						tis >> p2;

						if(p2.isEmpty())
							break;
					}
					
				case 30:
					ival = p2.toInt();

					if(ival < 0 || ival > 10000)
						logmsg << "TileMinframe: Value out of range\n";
					else
						wminframe = ival;

					break;

				default:
					logmsg << "WM: unknown parameter: " << p1 << '\n';
			}
		}
		istr.close();
	}	
	
	QFontInfo info(borderfont);
	if(info.family() != borderfont.family())
		logmsg << "WM: no match for font " << borderfont.family() << ", using " << info.family() << " instead\n";

	QFontInfo tinfo(toolbarfont);
	if(tinfo.family() != toolbarfont.family())
		logmsg << "WM: no match for font " << toolbarfont.family() << ", using " << tinfo.family() << " instead\n";
	
	tc_height = tb_height-4;

	if(pager_height > tb_height)
		pager_height = tb_height;
	
	if(borderfont.pixelSize() > windowbuttonsize-3)
	{
		windowbuttonsize = borderfont.pixelSize()+3;
		logmsg << "WM: windowborder too small for font, set to " << windowbuttonsize << '\n';
	}

	if(toolbarfont.pixelSize() > tc_height-4)
	{
		tc_height = toolbarfont.pixelSize()+4;
		tb_height = tc_height+4;
		logmsg << "WM: toolbar contents too small for font, set to " << tc_height << '\n';
	}
}
Exemplo n.º 10
0
tmain()
{
	int		i, k, m;
	ssize_t		size;
	Vmdisc_t	*dc;
	Region_t	region[N_REGION];
	char		*shmfile, *mapfile, *warn;

	warn = (char*)0;
	size = 0;
	m = sizeof(char*) == 4 ? 2 : 16;
	for(k = 0; k < N_REGION; ++k)
	{
		region[k].size = (trandom()%m + m)*m;
		region[k].size *= 1024*1024;

		if(k%(N_SHMREG+1) != 0 ) /* do a bunch of shm memory */
		{
			shmfile = tstfile("shm", k);
			if(!(dc = vmdcshare(shmfile, 1, region[k].size, -1)) ||
			   !(region[k].vm = vmopen(dc, Vmbest, 0)) )
			{	warn = "shmem";
				break;
			}

			tinfo("Region-shmem[%d] size=%lu addr=%p",
				k, region[k].size/(1024*1024), region[k].vm->data);
			size += region[k].size;
		}
		else /* interspersed the above with mmap */
		{	
			mapfile = tstfile("map", k);
			if(!(dc = vmdcshare(mapfile, -1, region[k].size, -1)) ||
			   !(region[k].vm = vmopen(dc, Vmbest, 0)) )
			{	warn = "mmap";
				break;
			}

			tinfo("Region-mmap[%d] size=%lu addr=%p",
				k, region[k].size/(1024*1024), region[k].vm->data);
			size += region[k].size;
		}

		for(i = 0; i < k; ++i)
		{	if((char*)region[i].vm->data >= (char*)region[k].vm->data &&
			   (char*)region[i].vm->data <= ((char*)region[k].vm->data + region[k].size) )
				terror("Region[%d] and Region[%d] overlap", i, k);
		}
	}

	if(size > 0 )
		tinfo("#regions to try=%d #regions actually opened=%d total memory=%luM",
			N_REGION, k, size/(1024*1024) );

	for(i = 0; i < k; ++i)
		vmclose(region[i].vm);

	if(warn && k == 0)
		terror("Region-%s[%d] size=%luM failed", warn, k, region[k].size/(1024*1024) );

	texit(0);
}
Exemplo n.º 11
0
void Decoder::read() {
  auto& s = top();

  size_t totalVarIntCount = 0;
  size_t optionalFieldBits = 0;
  if (s.state == IN_STRUCT) {
    size_t nbits = s.dataType->optionalFields.size();
    optionalFieldBits = nbits;
    size_t nbytes = byteCount(nbits);

    cursor_.gather(nbytes);
    auto optionalSet = ensure(nbytes).first;

    // Now we know which optionals are set
    // Assign by tag.
    size_t optionalIdx = 0;
    for (auto& p : s.dataType->fields) {
      auto tag = p.first;
      if (!p.second.isRequired && !testBit(optionalSet, optionalIdx++)) {
        continue;
      }
      TypeInfo tinfo(schema_, p.second.type);
      s.addType(tinfo, p.second, tag, 1);
    }

    // Structs encode the bitfield first, so we can use only one bitfield
    // for both optional fields and bools and strict enums
    readBoolsAndStrictEnums(nbits);
  } else {
    if (s.state == IN_MAP_VALUE) {
      s.addType(s.list.mapKeyType, StructField(), 0, s.list.remaining);
    }
    s.addType(s.list.valueType, StructField(), 0, s.list.remaining);
    ++totalVarIntCount;  // element count
  }

  s.ints.values.reserve(s.ints.count);
  s.int64s.values.reserve(s.int64s.count);
  s.bytes.values.reserve(s.bytes.count);
  // Waste some memory. Oh well, the code is simpler :)
  if (s.bools.count + s.totalStrictEnumBits) {
    s.bools.values.reserve(byteCount(optionalFieldBits + s.bools.count +
                                     s.totalStrictEnumBits));
  }
  s.strictEnums.values.reserve(s.strictEnums.count);
  s.vars.values.reserve(s.vars.count);
  s.internedStrings.values.reserve(s.internedStrings.count);

  // Read ints
  size_t varIntCount = s.ints.count;
  size_t varInt64Count = s.int64s.count;
  size_t varLengthCount = s.vars.count;
  size_t internCount = s.internedStrings.count;
  if (s.state == IN_STRUCT) {
    varIntCount -= (s.str.fixedInt16Tags.size() + s.str.fixedInt32Tags.size());
    varInt64Count -= s.str.fixedInt64Tags.size();
  }
  totalVarIntCount += varIntCount + 2 * varInt64Count + varLengthCount +
    internCount;
  if (totalVarIntCount) {
    size_t maxSize = folly::GroupVarint32::maxSize(totalVarIntCount);
    cursor_.gatherAtMost(maxSize);

    folly::StringPiece data = SP(cursor_.peek());
    folly::GroupVarint32Decoder decoder(data, totalVarIntCount);

    if (s.state != IN_STRUCT) {
      uint32_t n;
      if (!decoder.next(&n)) {
        throw TProtocolException("too few ints on the wire");
      }
      DCHECK_EQ(n, s.list.remaining);
    }

    for (size_t i = 0; i < varIntCount; i++) {
      uint32_t val;
      if (!decoder.next(&val)) {
        throw TProtocolException("too few ints on the wire: int");
      }
      s.ints.values.push_back(val);
    }

    for (size_t i = 0; i < varInt64Count; i++) {
      uint32_t hi;
      uint32_t lo;
      if (!decoder.next(&hi) || !decoder.next(&lo)) {
        throw TProtocolException("too few ints on the wire: int64");
      }
      uint64_t val = ((uint64_t)hi << 32) | lo;
      s.int64s.values.push_back(val);
    }

    for (size_t i = 0; i < varLengthCount; i++) {
      uint32_t val;
      if (!decoder.next(&val)) {
        throw TProtocolException("too few ints on the wire: var");
      }
      s.vars.values.push_back(val);
    }

    for (size_t i = 0; i < internCount; i++) {
      uint32_t val;
      if (!decoder.next(&val)) {
        throw TProtocolException("too few ints on the wire: intern");
      }
      auto sp = internTable_->get(val);
      s.internedStrings.values.push_back(sp);
      if (s.state == IN_STRUCT) {
        // fixed size
        s.str.internedStringTags[i].second.length = sp.size();
      }
    }

    uint32_t tmp;
    CHECK(!decoder.next(&tmp));  // or else we have an internal error

    size_t bytesUsed = data.size() - decoder.rest().size();
    cursor_.skip(bytesUsed);
    s.bytesRead += bytesUsed;
  }

  // Read bools and strict enums, already done for structs
  if (s.state != IN_STRUCT) {
    readBoolsAndStrictEnums(0);
  }

  // Read bytes
  if (s.bytes.count) {
    s.bytes.values.resize(s.bytes.count);
    cursor_.pull(&s.bytes.values.front(), s.bytes.count);
    s.bytesRead += s.bytes.count;
  }

  // Read fixed-size fields, currently only for structs
  if (s.state == IN_STRUCT) {
    if (!s.str.fixedInt16Tags.empty()) {
      for (auto tag : s.str.fixedInt16Tags) {
        s.ints.values.push_back(cursor_.readBE<uint16_t>());
        s.str.intTags.emplace_back(tag);
      }
      s.bytesRead += s.str.fixedInt16Tags.size() * sizeof(uint16_t);
    }

    if (!s.str.fixedInt32Tags.empty()) {
      for (auto tag : s.str.fixedInt32Tags) {
        s.ints.values.push_back(cursor_.readBE<uint32_t>());
        s.str.intTags.emplace_back(tag);
      }
      s.bytesRead += s.str.fixedInt32Tags.size() * sizeof(uint32_t);
    }

    if (!s.str.fixedInt64Tags.empty()) {
      for (auto tag : s.str.fixedInt64Tags) {
        s.int64s.values.push_back(cursor_.readBE<uint64_t>());
        s.str.int64Tags.push_back(tag);
      }
      s.bytesRead += s.str.fixedInt64Tags.size() * sizeof(uint64_t);
    }
  }

}