Example #1
0
/*
 *----------------------------------------------------------------------------
 * Main loop (when paused)
 * Return value: 0 = continue, not 0 = finish
 *----------------------------------------------------------------------------
 */
int vgs2_pause()
{
	static struct InputInf pi;
	struct InputInf ci;
	int push_flag=0;
	int push=0;
	int i;

	vgs2_touch(&ci.s,&ci.cx,&ci.cy,&ci.dx,&ci.dy);
	if(0==ci.s && 0!=pi.s) {
		push_flag=1;
		ci.s=1;
		ci.cx=pi.cx;
		ci.cy=pi.cy;
	}
	memcpy(&pi,&ci,sizeof(pi));

	vgs2_boxfSP(0,0,XSIZE,YSIZE,5);

	vgs2_boxfSP(30,40,130,160,12);
	vgs2_boxSP(28,38,132,162,105);
	myprint(45,46,"- PAUSE -");
	for(i=0;i<3;i++) {
		if(ci.s && HITCHK(40,60+i*33,80,25,ci.cx-4,ci.cy-4,8,8)) {
			vgs2_boxfSP(40,60+i*33,120,85+i*33,60);
			vgs2_boxSP(40,60+i*33,120,85+i*33,111);
			if(push_flag) {
				push=i+1;
			}
		} else {
			vgs2_boxfSP(40,60+i*33,120,85+i*33,8);
			vgs2_boxSP(40,60+i*33,120,85+i*33,107);
		}
	}
	myprint(57,70,"RESUME");
	myprint(61,103,"RESET");
	myprint(65,136,"EXIT");
	if(push) {
		memset(&pi,0,sizeof(pi));
		switch(push) {
			case 1:
				break;
			case 2:
				/* TODO: implement reset proceure */
				break;
			case 3:
				return 1;
		}
		vgs2_setPause(0);
	}
	return 0;
}
Example #2
0
//Create and SDL surface from an image.
SDL_Surface* Renderer::loadSurface( std::string path ) {

	//Final optimized image
	SDL_Surface* optimizedsurface = NULL;

    //Load image at specified path
    SDL_Surface* loadedSurface = IMG_Load( path.c_str() );

    myprint(path.c_str());

    if( loadedSurface == NULL )
    {
        printf( "Unable to load image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
    }
    else
    {
		optimizedsurface = SDL_ConvertSurface( loadedSurface, screensurface->format, 0 );

		if( optimizedsurface == NULL )
		{
			printf( "Unable to optimize image %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
		}

	}

	//Get rid of old loaded surface
	SDL_FreeSurface( loadedSurface );

    return optimizedsurface;
}
Example #3
0
int main () {
	  int pass = 0;
	  int fail = 0;
	  int r;
	  int p;
	  int index;
	  int handPos;

      struct gameState post, pre;

      printf ("Unit Test: cardtest4.c\n");
      printf ("   Target: Village Card\n");
      for(p=0; p<4; p++) {
    	  for(index=0; index<20; index++) {
    		  for(handPos=0; handPos<5; handPos++) {
    			  reset(&post, p, index, handPos);
    			  memcpy (&pre, &post, sizeof(struct gameState));
    			  set(&pre, p, handPos);
    			  playVillage(&post, handPos);
    			  r = mycompare(&pre, &post, p);
				  if (r == 0) { pass++; }
				  else {
					  fail++;
					  if(VERBOSE){
						  printf("\nFailed Test: p:%d index:%d handPos:%d\n", p, index, handPos);
						  printf("ORACLE\n");
						  myprint(&pre, p);
						  printf("RESULTS\n");
						  myprint(&post, p);
						  printf("\n");
					  }
				  }

    		  }
    	  }
      }
      if (fail)
          printf ("   Status: FAILED\n");
      else
    	  printf ("   Status: PASSED\n");

	  printf ("   Passed: %d\n", pass);
	  printf ("   Failed: %d\n", fail);

      return 0;
}
Example #4
0
bool GalaxyApMGR::HookDIspatchException()
{
	HANDLE  Device;
	DWORD   BytesReturned;
	
	
	Device = CreateFile(
		TEST_KIDISPAT_WIN32_DEVICE_NAME_A,
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_NO_BUFFERING,
		NULL
		);
	
	if (Device == INVALID_HANDLE_VALUE)
	{
		printf("createfile fail %d\r\n", GetLastError());
		return 0;	
	}
		DWORD datasize;
	HX_DYNC_FUNCTION *pdata;
	get_dync_funs_hook(&pdata, datasize);
	//这个是专门把老的os的的实现跳转到自己的实现中的

	printf(" send size %x", datasize);
	if (!DeviceIoControl(
		Device,
		IOCTL_TEST_KIDISPAT_InlineHook,
		pdata,
		datasize,
		NULL,
		0,
		&BytesReturned,
		NULL
		))
	{
		myprint("DeviceIoControl   IOCTL_TEST_KIDISPAT_InlineHook fail %d\r\n", GetLastError());
		CloseHandle(Device);
		return 0;
	}
	CloseHandle(Device);
	myprint(" send io control  IOCTL_TEST_KIDISPAT_InlineHook success \r\n");
	return 1;
}
Example #5
0
/*Begin input_network_topology*/
void input_network_topology(AdjTab * matrix)
{
    FILE *fp; /*file descriptor for the input file*/
    char ch;
    int count=0;
    // long length=0;
    log_entry();
    fp = fopen(FILENAME,"r");
    // fseek(fp, 0L, SEEK_END);
    // length =ftell(fp);
    fseek(fp, 0L, SEEK_SET);
    while((ch= fgetc(fp))!=EOF)
    {
        myprint("%c",ch);
        if(!isspace(ch) && ch!='-')
        {
            matrix->count++;
        }
    }
    myprint("\n");
    print("%d",matrix->count);
    matrix->ptr = malloc(sizeof(int) * matrix->count);
    count =0;
    fseek(fp, 0L, SEEK_SET);
    while((ch= fgetc(fp))!=EOF)
    {
        if(!isspace(ch))
        {
            if(ch=='-')
            {
                char c;
                c = fgetc(fp);
                matrix->ptr[count] = (-1)*(c -'0');
            }
            else
            {
                matrix->ptr[count] = ch-'0';
            }
            count++;
        }
    }
    log_exit();
    return ;
} /*End input_network_topology()*/
int main() {
  initBuffer();
  MY_TYPE **grids = NULL;
  MY_TYPE number = loadAllGrids(&grids);
  allocateStat(number);
  int i;

  for (i=0; i<number; ++i) {
    solveGrid(grids[i]);
  }

  LOG_WARN myprint("Global stats :\n");
  LOG_ERROR printStat(calculateGlobalStat());
  LOG_INFO myprint("Done !! \n");

  clearAllGrids(&grids);
  flush();
  return 0;
}
Example #7
0
bool Main::runSLS() {
#ifdef PARALLEL_STATIC
  if (m_options->par_postOnly)
    return true;  // skip SLS for static post mode
#endif
#ifdef ENABLE_SLS
  if (!m_options->in_subproblemFile.empty())
    return true;  // no SLS in case of subproblem processing
  if (m_options->slsIter <= 0)
    return true;
  oss ss;
  ss << "Running SLS " << m_options->slsIter << " times for "
     << m_options->slsTime << " seconds" << endl;
  myprint(ss.str());
  m_slsWrapper.reset(new SLSWrapper());
  m_slsWrapper->init(m_problem.get(), m_options->slsIter, m_options->slsTime);
  m_slsWrapper->run();
  myprint("SLS finished.\n");
#endif
  return true;
}
static int switchme(int val) {
  switch(val) {
   case 1:
    return val * val;
   case 2:
    myprint("hi");
    return 0;
   case 3:
    return startval + 100;
   case 4:
    return 5;
   case 5:
    myprint("hi there");
    return 66;
   case 20:
    return 55;
   default:
    myprint("error");
    return 66;
  }
}
Example #9
0
//////////////////////////////////////////////////////////////////////////
//会把驱动也卸载掉的。
bool		GalaxyApMGR::UnSetupReloadOS()
{
		if (!SendHookPort(IOCTL_HOOKPORTBYPASS_UNHOOKPORT))
		{
				myprint("卸载 hookport 失败\r\n");
				return false;
		}
		m_bSetupReloadOS	=	false;
		UnloadNTDriver(szReloadOsDriverName);
		return 1;
		
}
Example #10
0
bool GalaxyApMGR::HookOldFuns()
{
			HANDLE  Device;
	DWORD   BytesReturned;
	
	
	Device = CreateFile(
		TEST_KIDISPAT_WIN32_DEVICE_NAME_A,
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_NO_BUFFERING,
		NULL
		);
	
	if (Device == INVALID_HANDLE_VALUE)
	{
		printf("createfile fail %d\r\n", GetLastError());
		return 0;	
	}

		DWORD datasize;
	HX_DYNC_FUNCTION *pdata;
	get_dync_funs_hook_old(&pdata, datasize);

			if (m_bSetupReloadOS)	//如果启用了新内核,在HOOK的时候,就在老的函数开头inline hook JMP到新内核中
			{
					for(int i=0;i<datasize/sizeof(HX_DYNC_FUNCTION);i++)
					{
							pdata[i].delta	=m_uNewOsBaseDelt;
					}
			}
	if (!DeviceIoControl(
		Device,
		IOCTL_TEST_KIDISPAT_HOOK_OLD,
		pdata,
		datasize,
		NULL,
		0,
		&BytesReturned,
		NULL
		))
	{
		printf("DeviceIoControl IOCTL_TEST_KIDISPAT_HOOK_OLD fail %d\r\n", GetLastError());
		CloseHandle(Device);
		return 0;
	}
	CloseHandle(Device);
	myprint(" send io control  IOCTL_TEST_KIDISPAT_HOOK_OLD success \r\n");
	return 1;

}
Example #11
0
/*
 *----------------------------------------------------------------------------
 * Main loop
 * Return value: 0 = continue, not 0 = finish
 *----------------------------------------------------------------------------
 */
int vgs2_loop()
{
	static int x,y;
	static struct InputInf pi;
	struct InputInf ci;
	vgs2_touch(&ci.s,&ci.cx,&ci.cy,&ci.dx,&ci.dy);
	if(pi.s==0 && ci.s!=0) vgs2_eff(0);
	memcpy(&pi,&ci,sizeof(ci));
	x+=ci.dx;
	y+=ci.dy;
	myprint(x,y,"Hello,World!");
	return 0;
}
Example #12
0
int main(void)
{
	trap_init();
	sched_init();
	sti();
	move_to_user_mode();

	myprint("In kernel");

	while(1){}

	return 0;
}
Example #13
0
/*
 *----------------------------------------------------------------------------
 * Main loop
 * Return value: 0 = continue, not 0 = finish
 *----------------------------------------------------------------------------
 */
int vgs2_loop()
{
	myprint(4,4,"Envelope");
	myprint(27,20,"AT");
	myprint(53,20,"DT");
	myprint(82,20,"ST");
	myprint(117,20,"RT");
	myprint(13,182,"ON");
	myprint(99,182,"OFF");
	return 0;
}
Example #14
0
/*Begin Main*/
int main(int argc, char const *argv[])
{
    /* code */
    int choice,src,dest; /*choice value */
    AdjTab *new_matrix;
    AdjMat adj_mat;

    new_matrix = malloc(sizeof(AdjTab));
    while(1)
    {
        print("CS542 Link State Routing Simulator");
        myprint("(1) Input Network Topology File\n(2) Build a Connection Table\n(3) Shortest Path to Destination Router\n(4) Exit\n");
        scanf("%d",&choice);
        switch(choice)
        {
            case 1:
                /*calling a function to parse the input file.*/
                input_network_topology(new_matrix);
                convert_to_two_d_array(new_matrix,&adj_mat);
            break;

            case 2:
                    print("Select source");
                    scanf("%d",&src);

            break;

            case 3:
                    print("Select destination");
                    scanf("%d",&dest);
                    shortest_path_tree(&adj_mat,src,dest);
                    // print("%d",dijsktra(&adj_mat,src,dest));
            break;

            case 4:
                debug("*****************EXITING THE PROJECT****************");
                exit(0);
            break;

            case 5:
            break;

            default:
            break;
        }
    }
    return 0;
} /*End Main*/
Example #15
0
bool	GalaxyApMGR::SendReplace()
	{
	
	HANDLE  Device;
	DWORD   BytesReturned;
	
	
	Device = CreateFile(
		TEST_KIDISPAT_WIN32_DEVICE_NAME_A,
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_NO_BUFFERING,
		NULL
		);
	
	if (Device == INVALID_HANDLE_VALUE)
	{
		printf("createfile fail %d\r\n", GetLastError());
		return 0;	
	}
		char szBuffer[512];
		ZeroMemory(szBuffer, sizeof(szBuffer));
		*(PULONG)szBuffer	=	m_uNewOsBaseDelt;
	strcpy(&szBuffer[4], szStrongOD);

	if (!DeviceIoControl(
		Device,
		IOCTL_TEST_KIDISPAT_HOOK_REPLACE,
		szBuffer,
		sizeof(szBuffer),
		&m_uNewOsBase,		//返回了newaddress
		sizeof(m_uNewOsBase),
		&BytesReturned,
		NULL
		))
	{
		printf("DeviceIoControl %d fail %d\r\n", IOCTL_TEST_KIDISPAT_HOOK_REPLACE, GetLastError());
		CloseHandle(Device);
		return 0;
	}
	CloseHandle(Device);
	myprint(" send io control  %d success RetSize:%x\r\n",IOCTL_TEST_KIDISPAT_HOOK_REPLACE, BytesReturned);
	return 1;
}
Example #16
0
void slow_log(const char *fmt, ...)
{
	char buffer[4096] = { 0 };
        va_list ap;

        va_start(ap, fmt);
        vsnprintf(buffer, sizeof buffer, fmt, ap);
        va_end(ap);

	free(slow_history[window_history_n - 1]);
	memmove(&slow_history[1], &slow_history[0], (window_history_n - 1) * sizeof(char *));
	slow_history[0] = strdup(buffer);

	myprint(w_slow, buffer);

	if (win_resize)
		recreate_terminal();
}
Example #17
0
bool	GalaxyApMGR::SendHookPort(DWORD	IOCTL_CODE)
{

	HANDLE  Device;
	DWORD   BytesReturned;
	
	
	Device = CreateFile(
		HOOKPORTBYPASS_WIN32_DEVICE_NAME_A,
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_NO_BUFFERING,
		NULL
		);
	
	if (Device == INVALID_HANDLE_VALUE)
	{
		printf("createfile fail %d\r\n", GetLastError());
		return 0;	
	}
	
	if (!DeviceIoControl(
		Device,
		IOCTL_CODE,
		szStrongOD,
		sizeof(szStrongOD),
		&m_uNewOsBase,		//返回了newaddress
		sizeof(m_uNewOsBase),
		&BytesReturned,
		NULL
		))
	{
		printf("DeviceIoControl %d fail %d\r\n", IOCTL_CODE, GetLastError());
		CloseHandle(Device);
		return 0;
	}
	CloseHandle(Device);
	myprint(" send io control  %d success RetBuffer:%X ,RetSize:%x\r\n",IOCTL_CODE,m_uNewOsBase, BytesReturned);
	return 1;
		
}
Example #18
0
bool	GalaxyApMGR::unHookKidisp()
{

			HANDLE  Device;
	DWORD   BytesReturned;
	
	
	Device = CreateFile(
		TEST_KIDISPAT_WIN32_DEVICE_NAME_A,
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_NO_BUFFERING,
		NULL
		);
	
	if (Device == INVALID_HANDLE_VALUE)
	{
		printf("createfile fail %d\r\n", GetLastError());
		return 0;	
	}

	if (!DeviceIoControl(
		Device,
		IOCTL_TEST_KIDISPAT_UNHOOK,
		&m_uNewOsBase,
		sizeof(m_uNewOsBase),
		NULL,
		0,
		&BytesReturned,
		NULL
		))
	{
		printf("DeviceIoControl IOCTL_TEST_KIDISPAT_UNHOOK fail %d\r\n", GetLastError());
		CloseHandle(Device);
		return 0;
	}
	CloseHandle(Device);
	myprint(" send io control  IOCTL_TEST_KIDISPAT_UNHOOK success \r\n");
	return 1;
		
}
Example #19
0
//目录文件计数
void countDirFile(FILE* file,struct DirEntry entryListPtr[],int dirSize,char path[],char target[],int* dirNum,int* fileNum){
	int i,j;

	
	char nameptr[12];
	short firstClus;
	
	for(i=0;i<dirSize;i++){
		
		if(entryListPtr[i].DIR_Attr==0x10){
			
			if(getVaildName(nameptr,entryListPtr[i].DIR_Name,entryListPtr[i].DIR_Attr)==1){

				
				firstClus=entryListPtr[i].DIR_FstClus;
				char name[120];
				strcpy(name,path);
				strcat(name,nameptr);
				
				if(isSubString(name,target)!=0){

					if(isSubString(name,target)==-1){
						(*dirNum)++;
					}
					strcat(name,"/");
				
					int entrySize=BPB_BytsPerSec>>5;
					struct DirEntry entryListPtr1[entrySize];
					long clusBegin=(FirstDataSectors+firstClus-2)*BPB_BytsPerSec;
				
					if(fileRead(file,entryListPtr1,clusBegin,BPB_BytsPerSec)==0){
						myprint("目录读取失败");
					}
					countDirFile(file,entryListPtr1,entrySize,name,target,dirNum,fileNum);
			
				}
				
				
				
			}
			
		}
	}
Example #20
0
/* static master mode for distributed execution */
bool Main::runSearchStatic() {
  bool preOnly = m_options->par_preOnly, postOnly = m_options->par_postOnly,
        local = m_options->par_solveLocal;

  bool success = true;
  if (!postOnly) {
    success = success && m_search->doLearning();
  }
  if (true) {  // TODO
    /* find frontier from scratch */
    success = success && m_search->findFrontier();
  }
  if (!postOnly) {
    /* writes CSV with subproblem stats */
    success = success && m_search->writeSubprobStats();
  }
  if (!postOnly && !local) {
    /* generate files for subproblems */
    success = success && m_search->writeJobs();
    if (m_search->getSubproblemCount()==0) m_solved = true;
  }
  if (local && !preOnly) {
    /* solve external subproblems locally */
    success = success && m_search->extSolveLocal();
  }
  if (!local && !preOnly && !postOnly) {
    /* run Condor and wait for results */
    success = success && m_search->runCondor();
  }
  if (!local && !preOnly) {
    /* read external results */
    success = success && m_search->readExtResults();
  }

  if (!success) {
    myprint("!!! Search failed. !!!\n");
    err_txt("Main search routine failed.");
    return false;
  }

  return true;
}
Example #21
0
bool GalaxyApMGR::SetProtectInfo()
{
	
	HANDLE  Device;
	DWORD   BytesReturned;
	
	
	Device = CreateFile(
		TEST_KIDISPAT_WIN32_DEVICE_NAME_A,
		GENERIC_READ | GENERIC_WRITE,
		FILE_SHARE_READ | FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_FLAG_NO_BUFFERING,
		NULL
		);
	
	if (Device == INVALID_HANDLE_VALUE)
	{
		printf("createfile fail %d\r\n", GetLastError());
		return 0;	
	}

	if (!DeviceIoControl(
		Device,
		IOCTL_TEST_KIDISPAT_PROTECT_INFO,
		&m_protect_info,
		sizeof(m_protect_info),
		NULL,
		0,
		&BytesReturned,
		NULL
		))
	{
		printf("DeviceIoControl IOCTL_TEST_KIDISPAT_PROTECT_INFO fail %d\r\n", GetLastError());
		CloseHandle(Device);
		return 0;
	}
	CloseHandle(Device);
	myprint(" send io control  IOCTL_TEST_KIDISPAT_PROTECT_INFO success , NewAddress is %X\r\n",m_protect_info.PidOrName);
	return 1;
}
void main(void)
{
real4 glat, glong, gspeed;
real2 gangle;
char b1[110], gvalid;

  setbaud(BAUD9600);
  PORTA = 0;
  myprint("\nComplete LATLONG GPS data (binary) v1.0\n\n");
    
  gps_sync();
  while(1) {
    gps_read(b1);
	
	gvalid = b1[18];
	
	glat.c[3] = b1[52];
	glat.c[2] = b1[53];
	glat.c[1] = b1[54];
	glat.c[0] = b1[55];

	glong.c[3] = b1[56];
	glong.c[2] = b1[57];
	glong.c[1] = b1[58];
	glong.c[0] = b1[59];

	gspeed.c[3] = b1[66];
	gspeed.c[2] = b1[67];
	gspeed.c[1] = b1[68];
	gspeed.c[0] = b1[69];
	
	gangle.c[1] = b1[70];
	gangle.c[0] = b1[71];

    PORTA = 0;	  	
    print_latlong(&glat, &glong, &gspeed, &gangle, gvalid);
	PIOC = 0;
	PORTB=glat.c[0];
  }  
  	 }
Example #23
0
bool	GalaxyApMGR::unSetupMyKidispatchexcepion()
{
		bool	bret	=false;
		if (!m_bSetupKidisp)
		{
				myprint("还没安装MyKidispatchexcepion\r\n");
				return 1;
		}
		bret	=	unHookKidisp();
		if (!bret)
		{
				return bret;

		}
		UnloadNTDriver(szExceptionDriverName);
		if (bret)
		{
				m_bSetupKidisp	=	false;	//已经卸载了,则置位为FALSE
		}

		return bret ;
}
Example #24
0
void status_line(char *fmt, ...)
{
	char *line = NULL;
        va_list ap;

	wattron(w_line2, A_REVERSE);

	wmove(w_line2, 0, 0);

        va_start(ap, fmt);

	vasprintf(&line, fmt, ap);
        myprint(w_line2, line);
	free(line);

        va_end(ap);

	wattroff(w_line2, A_REVERSE);

	wnoutrefresh(w_line2);

	if (win_resize)
		recreate_terminal();
}
Example #25
0
int queen() {
  int n = 0;			// count of answer
  int i = 0, j = 0;
  while (i < QUEEN) {
    while (j < QUEEN) {
      if (valid(i, j)) {
	a[i] = j;
	j = 0;
	break;			// go to next line
      } else {
	++j;			// try next col
      }
    } // while j

    if (a[i] == -1) {		// fail for line i
      if (i == 0) {		// fail for line 0
	break;			// fail, and should finish
      } else {			// 
	--i;
	j = a[i] + 1;		// restart from j+1
	a[i] = INITVAL;		// return to last line
	continue;		// dont increase i
      }
    } // if a[i] == -1

    if (i == QUEEN-1) {		// reach last line
      printf("answer %d\n", ++n);	// get one answer
      myprint();		// print answer

      j = a[i] + 1;		// check if next col is also answer
      a[i] = INITVAL;
      continue;			// similar to previous line
    }
    ++i;
  }   // while i
}
Example #26
0
void BoundPropagatorMaster::operator() () {

  bool allDone = false;
  size_t noPropagated = 0;

  try { while (!allDone) {

    SearchNode* n = NULL;
    Subproblem* sp = NULL;
    bool hasMore = false;
    noPropagated = 0;
    boost::thread* tp = NULL;

    do {
      {
        GETLOCK(m_spaceMaster->mtx_solved, lk);

        while( m_spaceMaster->solved.empty() && m_spaceMaster->leaves.empty() ) {
          CONDWAIT(m_spaceMaster->cond_solved, lk);
        }

        if (m_spaceMaster->leaves.size()) {
          // new leaf node to propagate
          n = m_spaceMaster->leaves.front();
          m_spaceMaster->leaves.pop();
        } else if (m_spaceMaster->solved.size()) {
          // new externally solved subproblem
          sp = m_spaceMaster->solved.front();
          n = sp->root; // root node of subproblem

          // collect subproblem statistics
          {
//            myprint("Adding subproblem to statistics\n");
            GETLOCK(m_spaceMaster->mtx_stats, lk2);
//            myprint("Acquired mutex\n");
            m_spaceMaster->avgStats->addSubprob(sp);
          }

          { // clean up processing thread
            GETLOCK(m_spaceMaster->mtx_activeThreads, lk2);
            map< Subproblem*, boost::thread* >::iterator it = m_spaceMaster->activeThreads.find(sp);
            if (it!=m_spaceMaster->activeThreads.end()) {
              // tp = m_space->activeThreads.find(p)->second;
              tp = it->second;
              m_spaceMaster->activeThreads.erase(sp);
              tp->join();
              delete tp;
            }
          }

          delete sp;
          m_spaceMaster->solved.pop();
        }

      } // mtx_solved released

      { // actual propagation
        GETLOCK(m_spaceMaster->mtx_space, lk);
        propagate(n, true);
        ++noPropagated;
      }

      { //check if there's more to propagate
        GETLOCK(m_spaceMaster->mtx_solved, lk);
        hasMore = !m_spaceMaster->solved.empty() || !m_spaceMaster->leaves.empty();
      }

    } while (hasMore);



    { // TODO: Make sure race condition can't happen
      GETLOCK(m_spaceMaster->mtx_searchDone,lk);
      if (m_spaceMaster->searchDone) { // search process done?
        GETLOCK(m_spaceMaster->mtx_activeThreads,lk2);
        if (m_spaceMaster->activeThreads.empty()) { // no more processing threads
          allDone = true;
        }
      } else { // search not done, notify
        { // notify the search that the buffer is open again
          GETLOCK(m_spaceMaster->mtx_allowedThreads,lk);
          m_spaceMaster->allowedThreads += noPropagated;
          m_spaceMaster->cond_allowedThreads.notify_one();
        }
      }
    }

  } // overall while(!allDone) loop

  myprint("\t!!! PROP done !!!\n");

  } catch (boost::thread_interrupted i) {
    myprint("\t!!! PROP aborted !!!\n");
  }

}
Example #27
0
int
main( int argc, char **argv )
{
	Avlnode	*tree = NULL, *n;
	char	command[ 10 ];
	char	name[ 80 ];
	char	*p;

	printf( "> " );
	while ( fgets( command, sizeof( command ), stdin ) != NULL ) {
		switch( *command ) {
		case 'n':	/* new tree */
			( void ) tavl_free( tree, free );
			tree = NULL;
			break;
		case 'p':	/* print */
			( void ) myprint( tree );
			break;
		case 't':	/* traverse with first, next */
			printf( "***\n" );
			for ( n = tavl_end( tree, TAVL_DIR_LEFT );
			    n != NULL;
				n = tavl_next( n, TAVL_DIR_RIGHT ))
				printf( "%s\n", n->avl_data );
			printf( "***\n" );
			break;
		case 'f':	/* find */
			printf( "data? " );
			if ( fgets( name, sizeof( name ), stdin ) == NULL )
				exit( EXIT_SUCCESS );
			name[ strlen( name ) - 1 ] = '\0';
			if ( (p = (char *) tavl_find( tree, name, avl_strcmp ))
			    == NULL )
				printf( "Not found.\n\n" );
			else
				printf( "%s\n\n", p );
			break;
		case 'i':	/* insert */
			printf( "data? " );
			if ( fgets( name, sizeof( name ), stdin ) == NULL )
				exit( EXIT_SUCCESS );
			name[ strlen( name ) - 1 ] = '\0';
			if ( tavl_insert( &tree, strdup( name ), avl_strcmp,
			    avl_dup_error ) != 0 )
				printf( "\nNot inserted!\n" );
			break;
		case 'd':	/* delete */
			printf( "data? " );
			if ( fgets( name, sizeof( name ), stdin ) == NULL )
				exit( EXIT_SUCCESS );
			name[ strlen( name ) - 1 ] = '\0';
			if ( tavl_delete( &tree, name, avl_strcmp ) == NULL )
				printf( "\nNot found!\n" );
			break;
		case 'q':	/* quit */
			exit( EXIT_SUCCESS );
			break;
		case '\n':
			break;
		default:
			printf("Commands: insert, delete, print, new, quit\n");
		}

		printf( "> " );
	}

	return( 0 );
}
Example #28
0
int main(void)
{
	myprint();

	return 0;
}
Example #29
0
int
main( int argc, char **argv )
{
	Avlnode	*tree = NULL;
	char	command[ 10 ];
	char	name[ 80 ];
	char	*p;

	printf( "> " );
	while ( fgets( command, sizeof( command ), stdin ) != NULL ) {
		switch( *command ) {
		case 'n':	/* new tree */
			( void ) avl_free( tree, free );
			tree = NULL;
			break;
		case 'p':	/* print */
			( void ) myprint( tree );
			break;
		case 't':	/* traverse with first, next */
#ifdef AVL_NONREENTRANT
			printf( "***\n" );
			for ( p = (char * ) avl_getfirst( tree );
			    p != NULL;
				p = (char *) avl_getnext())
				printf( "%s\n", p );
			printf( "***\n" );
#else
			printf( "*** reentrant interface not implemented ***" );
#endif
			break;
		case 'f':	/* find */
			printf( "data? " );
			if ( fgets( name, sizeof( name ), stdin ) == NULL )
				exit( EXIT_SUCCESS );
			name[ strlen( name ) - 1 ] = '\0';
			if ( (p = (char *) avl_find( tree, name, avl_strcmp ))
			    == NULL )
				printf( "Not found.\n\n" );
			else
				printf( "%s\n\n", p );
			break;
		case 'i':	/* insert */
			printf( "data? " );
			if ( fgets( name, sizeof( name ), stdin ) == NULL )
				exit( EXIT_SUCCESS );
			name[ strlen( name ) - 1 ] = '\0';
			if ( avl_insert( &tree, strdup( name ), avl_strcmp, 
			    avl_dup_error ) != 0 )
				printf( "\nNot inserted!\n" );
			break;
		case 'd':	/* delete */
			printf( "data? " );
			if ( fgets( name, sizeof( name ), stdin ) == NULL )
				exit( EXIT_SUCCESS );
			name[ strlen( name ) - 1 ] = '\0';
			if ( avl_delete( &tree, name, avl_strcmp ) == NULL )
				printf( "\nNot found!\n" );
			break;
		case 'q':	/* quit */
			exit( EXIT_SUCCESS );
			break;
		case '\n':
			break;
		default:
			printf("Commands: insert, delete, print, new, quit\n");
		}

		printf( "> " );
	}

	return( 0 );
}
Example #30
0
/*
 * meta_back_getconn
 * 
 * Prepares the connection structure
 * 
 * FIXME: This function needs to receive some info on the type of operation
 * it is invoked by, so that only the correct pool of candidate targets
 * is initialized in case no connection was available yet.
 * 
 * At present a flag that says whether the candidate target must be unique
 * is passed; eventually an operation agent will be used.
 */
struct metaconn *
meta_back_getconn(
		struct metainfo *li,
	       	Connection 	*conn,
	       	Operation 	*op,
		int 		op_type,
		struct berval	*ndn,
		int 		*candidate )
{
	struct metaconn *lc, lc_curr;
	int cached = -1, i = -1, err = LDAP_SUCCESS;
	int new_conn = 0;

	/* Searches for a metaconn in the avl tree */
	lc_curr.conn = conn;
	ldap_pvt_thread_mutex_lock( &li->conn_mutex );
	lc = (struct metaconn *)avl_find( li->conntree, 
		(caddr_t)&lc_curr, meta_back_conn_cmp );
	ldap_pvt_thread_mutex_unlock( &li->conn_mutex );

	/* Looks like we didn't get a bind. Open a new session... */
	if ( !lc ) {
		lc = metaconn_alloc( li->ntargets );
		lc->conn = conn;
		new_conn = 1;
	}

	/*
	 * looks in cache, if any
	 */
	if ( li->cache.ttl != META_DNCACHE_DISABLED ) {
		cached = i = meta_dncache_get_target( &li->cache, ndn );
	}

	if ( op_type == META_OP_REQUIRE_SINGLE ) {

		/*
		 * tries to get a unique candidate
		 * (takes care of default target 
		 */
		if ( i < 0 ) {
			i = meta_back_select_unique_candidate( li, ndn );
		}

		/*
		 * if any is found, inits the connection
		 */
		if ( i < 0 ) {
			if ( new_conn ) {
				metaconn_free( lc );
			}

			send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
				NULL, "", NULL, NULL );

			return NULL;
		}
				
#ifdef NEW_LOGGING
		LDAP_LOG( BACK_META, INFO,
			"meta_back_getconn: got target %d for ndn=\"%s\" from cache\n", 
			i, ndn->bv_val, 0 );
#else /* !NEW_LOGGING */
		Debug( LDAP_DEBUG_CACHE,
	"==>meta_back_getconn: got target %d for ndn=\"%s\" from cache\n%s",
				i, ndn->bv_val, "" );
#endif /* !NEW_LOGGING */

		/*
		 * Clear all other candidates
		 */
		( void )meta_clear_unused_candidates( li, lc, i, 0 );

		/*
		 * The target is activated; if needed, it is
		 * also init'd. In case of error, init_one_conn
		 * sends the appropriate result.
		 */
		err = init_one_conn( conn, op, li->targets[ i ],
				&lc->conns[ i ] );
		if ( err != LDAP_SUCCESS ) {
		
			/*
			 * FIXME: in case one target cannot
			 * be init'd, should the other ones
			 * be tried?
			 */
			( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
			if ( new_conn ) {
				metaconn_free( lc );
			}
			return NULL;
		}

		if ( candidate ) {
			*candidate = i;
		}

	/*
	 * require all connections ...
	 */
	} else if (op_type == META_OP_REQUIRE_ALL) {
		for ( i = 0; i < li->ntargets; i++ ) {

			/*
			 * The target is activated; if needed, it is
			 * also init'd
			 */
			int lerr = init_one_conn( conn, op, li->targets[ i ],
					&lc->conns[ i ] );
			if ( lerr != LDAP_SUCCESS ) {
				
				/*
				 * FIXME: in case one target cannot
				 * be init'd, should the other ones
				 * be tried?
				 */
				( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
				err = lerr;
				continue;
			}
		}

	/*
	 * if no unique candidate ...
	 */
	} else {
		for ( i = 0; i < li->ntargets; i++ ) {
			if ( i == cached 
		|| meta_back_is_candidate( &li->targets[ i ]->suffix, ndn ) ) {

				/*
				 * The target is activated; if needed, it is
				 * also init'd
				 */
				int lerr = init_one_conn( conn, op,
						li->targets[ i ],
						&lc->conns[ i ] );
				if ( lerr != LDAP_SUCCESS ) {
				
					/*
					 * FIXME: in case one target cannot
					 * be init'd, should the other ones
					 * be tried?
					 */
					( void )meta_clear_one_candidate( &lc->conns[ i ], 1 );
					err = lerr;
					continue;
				}
			}
		}
	}

	if ( new_conn ) {
		
		/*
		 * Inserts the newly created metaconn in the avl tree
		 */
		ldap_pvt_thread_mutex_lock( &li->conn_mutex );
		err = avl_insert( &li->conntree, ( caddr_t )lc,
			       	meta_back_conn_cmp, meta_back_conn_dup );

#if PRINT_CONNTREE > 0
		myprint( li->conntree );
#endif /* PRINT_CONNTREE */
		
		ldap_pvt_thread_mutex_unlock( &li->conn_mutex );

#ifdef NEW_LOGGING
		LDAP_LOG( BACK_META, INFO,
			"meta_back_getconn: conn %ld inserted\n", lc->conn->c_connid, 0, 0);
#else /* !NEW_LOGGING */
		Debug( LDAP_DEBUG_TRACE,
			"=>meta_back_getconn: conn %ld inserted\n%s%s",
			lc->conn->c_connid, "", "" );
#endif /* !NEW_LOGGING */
		
		/*
		 * Err could be -1 in case a duplicate metaconn is inserted
		 */
		if ( err != 0 ) {
			send_ldap_result( conn, op, LDAP_OTHER,
			NULL, "Internal server error", NULL, NULL );
			metaconn_free( lc );
			return NULL;
		}
	} else {
#ifdef NEW_LOGGING
		LDAP_LOG( BACK_META, INFO,
			"meta_back_getconn: conn %ld fetched\n", lc->conn->c_connid, 0, 0 );
#else /* !NEW_LOGGING */
		Debug( LDAP_DEBUG_TRACE,
			"=>meta_back_getconn: conn %ld fetched\n%s%s",
			lc->conn->c_connid, "", "" );
#endif /* !NEW_LOGGING */
	}
	
	return lc;
}