示例#1
0
gint
DisplayStopThread(camera_t* cam)
{
  displaythread_info_t *info;
  chain_t *display_service;
  display_service=GetService(cam,SERVICE_DISPLAY);
  
  if (display_service!=NULL) { // if display service running... 
    info=(displaythread_info_t*)display_service->data;
    
    // send request for cancellation:
    pthread_mutex_lock(&info->mutex_cancel);
    info->cancel_req=1;
    pthread_mutex_unlock(&info->mutex_cancel);
    
    // when cancellation occured, join:
    pthread_join(display_service->thread, NULL);
    
    pthread_mutex_lock(&display_service->mutex_data);
    pthread_mutex_lock(&display_service->mutex_struct);
    RemoveChain(cam,display_service);
#ifdef HAVE_SDLLIB
    SDLQuit(display_service);
#endif
    
    pthread_mutex_unlock(&display_service->mutex_struct);
    pthread_mutex_unlock(&display_service->mutex_data);
    FreeChain(display_service);
  }
  return (1);
}
示例#2
0
gint
DisplayStartThread(camera_t* cam)
{
  chain_t *display_service=NULL;
  displaythread_info_t *info=NULL;

  display_service=GetService(cam,SERVICE_DISPLAY);

  if (display_service==NULL) {// if no display service running...
    display_service=(chain_t*)malloc(sizeof(chain_t));
    display_service->current_buffer=NULL;
    display_service->next_buffer=NULL;
    display_service->data=(void*)malloc(sizeof(displaythread_info_t));
    info=(displaythread_info_t*)display_service->data;
    pthread_mutex_init(&display_service->mutex_struct, NULL);
    pthread_mutex_init(&display_service->mutex_data, NULL);
    pthread_mutex_init(&info->mutex_cancel, NULL);
    
    pthread_mutex_lock(&info->mutex_cancel);
    info->cancel_req=0;
    pthread_mutex_unlock(&info->mutex_cancel);
    
    pthread_mutex_lock(&display_service->mutex_data);
    CommonChainSetup(cam, display_service,SERVICE_DISPLAY);
    pthread_mutex_lock(&display_service->mutex_struct);

    InsertChain(cam, display_service);
    
    if (pthread_create(&display_service->thread, NULL, DisplayThread, (void*)display_service)) {
      RemoveChain(cam, display_service);
      pthread_mutex_unlock(&display_service->mutex_struct);
      pthread_mutex_unlock(&display_service->mutex_data);
      FreeChain(display_service);
      return(-1);
    }

    pthread_mutex_unlock(&display_service->mutex_struct);
    pthread_mutex_unlock(&display_service->mutex_data);
    
  }
  return (1);
}
示例#3
0
gint
V4lStopThread(camera_t* cam)
{
  v4lthread_info_t *info;
  chain_t *v4l_service;
  v4l_service=GetService(cam,SERVICE_V4L);

  if (v4l_service!=NULL) { // if V4L service running...
    info=(v4lthread_info_t*)v4l_service->data;
    /* Clean cancel handler: */
    pthread_mutex_lock(&info->mutex_cancel);
    info->cancel_req=1;
    pthread_mutex_unlock(&info->mutex_cancel);
    
    /* common handlers...*/
    pthread_join(v4l_service->thread, NULL);
    
    pthread_mutex_lock(&v4l_service->mutex_data);
    pthread_mutex_lock(&v4l_service->mutex_struct);
    RemoveChain(cam,v4l_service);
    
    /* Do custom cleanups here...*/
    if ((info->frame.image!=NULL)&&(info->frame.allocated_image_bytes>0)) {
      free(info->frame.image);
      info->frame.allocated_image_bytes=0;
    }

    close(info->v4l_dev);

    /* Mendatory cleanups: */
    pthread_mutex_unlock(&v4l_service->mutex_struct);
    pthread_mutex_unlock(&v4l_service->mutex_data);
    FreeChain(v4l_service);
    v4l_service=NULL;
    
  }
  
  return (1);
}
示例#4
0
文件: gogame.cpp 项目: kota7/gogamer
void Gogame::RemoveChain(unsigned int x, unsigned int y)
{
  // remove all stones connected to (x, y) and of the same color

  unsigned int color = board[y][x];

  // do nothing if the color is neither black nor white
  if (color != BL && color != WH) return;

  // remove this point
  board[y][x] = EM;
  if (color == BL) {
    b_captured++;
  } else {
    w_captured++;
  }

  // and record it in the transition field
  transitions.push_back(Transition(movenumber, x, y, -color, currentnode, false));


  // loop over the four adjacent point
  unsigned int xx;
  unsigned int yy;
  int increment;
  for (int k = 0; k < 4; k++)
  {
    increment = 2*(k % 2) - 1;
    if (k < 2) {
      xx = x + increment;
      yy = y;
    } else {
      xx = x;
      yy = y + increment;
    }

    if (board[yy][xx] == color) RemoveChain(xx, yy);
  }
}
示例#5
0
gint
V4lStartThread(camera_t* cam)
{
  chain_t* v4l_service=NULL;
  v4lthread_info_t *info=NULL;
  char *stemp;

  stemp=(char*)malloc(STRING_SIZE*sizeof(char));

  v4l_service=GetService(cam, SERVICE_V4L);

  if (v4l_service==NULL) { // if no V4L service running...
    v4l_service=(chain_t*)malloc(sizeof(chain_t));
    v4l_service->current_buffer=NULL;
    v4l_service->next_buffer=NULL;
    v4l_service->data=(void*)malloc(sizeof(v4lthread_info_t));
    info=(v4lthread_info_t*)v4l_service->data;
    pthread_mutex_init(&v4l_service->mutex_data, NULL);
    pthread_mutex_init(&v4l_service->mutex_struct, NULL);
    pthread_mutex_init(&info->mutex_cancel, NULL);
    
    /* if you want a clean-interrupt thread:*/
    pthread_mutex_lock(&info->mutex_cancel);
    info->cancel_req=0;
    pthread_mutex_unlock(&info->mutex_cancel);
    
    /* setup v4l_thread: handles, ...*/
    pthread_mutex_lock(&v4l_service->mutex_data);
    
    CommonChainSetup(cam, v4l_service,SERVICE_V4L);
    
    info->frame.image=NULL;
    info->frame.allocated_image_bytes=0;

    // open V4L device
    info->v4l_dev=-1;
    info->v4l_dev = open(cam->prefs.v4l_dev_name, O_RDWR);
    if (info->v4l_dev < 0) {
      sprintf(stemp,"Failed to open V4L device %s",cam->prefs.v4l_dev_name);
      Error(stemp);
      free(stemp);
      stemp=NULL;
      FreeChain(v4l_service);
      v4l_service=NULL;
      return(-1);
    }

    /* Insert chain and start service*/
    pthread_mutex_lock(&v4l_service->mutex_struct);
    InsertChain(cam, v4l_service);
    if (pthread_create(&v4l_service->thread, NULL, V4lThread,(void*) v4l_service)) {
      /* error starting thread. You should cleanup here
	 (free, unset global vars,...):*/
      
      /* Mendatory cleanups:*/
      RemoveChain(cam, v4l_service);
      pthread_mutex_unlock(&v4l_service->mutex_struct);
      pthread_mutex_unlock(&v4l_service->mutex_data);
      if ((info->frame.image!=NULL)&&(info->frame.allocated_image_bytes>0)) {
	free(info->frame.image);
	info->frame.allocated_image_bytes=0;
      }
      free(stemp);
      stemp=NULL;
      FreeChain(v4l_service);
      v4l_service=NULL;
      return(-1);
    }

    pthread_mutex_unlock(&v4l_service->mutex_struct);
    pthread_mutex_unlock(&v4l_service->mutex_data);
    
  }
  free(stemp);
  stemp=NULL;
  return (1);
}
示例#6
0
int Disintegrate(ITEM *i)
{
	SUB *s;
	if(!Duped(i))
		return(-1);
	Place(i,NULL);
	while((s=i->it_Properties)!=NULL)
	{
		switch(s->pr_Key)
		{
		case KEY_ROOM:
			UnRoom(i);
			break;
		case KEY_OBJECT:
			UnObject(i);
			break;
		case KEY_PLAYER:
			UnPlayer(i);
			break;
		case KEY_GENEXIT:
			UnGenExit(i);
			break;
		case KEY_MSGEXIT:
			UnMsgExit(i,(MSGEXIT *)s);
			break;
		case KEY_CHAIN:
			RemoveChain(i,((CHAIN *)(s))->ch_Chained);
			break;
		case KEY_USERFLAG:
		case KEY_USERFLAG2:
			UnUserFlag(i);
			break;
		case KEY_CONDEXIT:
			UnCondExit(i,(CONDEXIT *)s);
			break;
		case KEY_CONTAINER:
			UnContainer(i);
			break;
		case KEY_INHERIT:
			UnInherit(i);
			break;
		case KEY_SNOOP:;
		case KEY_SNOOPBACK:
			StopAllSnoops(i);
			StopSnoopsOn(i);
			break;
		case KEY_DUPED:
			UnlockItem(((DUP *)(s))->du_Master);
			FreeSub(i,s);
			break;
		case KEY_USERTEXT:
			UnUserText(i);
			break;
		case KEY_INOUTHERE:
			KillIOH(i);
			break;
			
		default:fprintf(stderr,"SUBID=%d\n",s->pr_Key);
			Error("Disintegrate: Prop Problem");
		}
	}
	KillEventQueue(i);
	if(FreeItem(i)<0)
	{
		i->it_Perception=-1;	/* Queue deletion */
		return(-1);
	}
	if(i==Me())
		SetMe(NULL);
	if(i==Item1)
		Item1=NULL;
	if(i==Item2)
		Item2=NULL;
	return(0);
}
示例#7
0
文件: gogame.cpp 项目: kota7/gogamer
void Gogame::CheckAndRemove(unsigned int x, unsigned int y)
{
  // check the liberty of point (x, y)
  // and if it has no liberty, remove all connected stones to (x, y)
  if (!HasLiberty(x, y)) RemoveChain(x, y);
}