コード例 #1
0
ファイル: gtk_ctrl.cpp プロジェクト: dewn49/FreeJ
void *gtk_run(void *arg) {
  while(!quit) {
    update_layer_list();
    jsleep(0,100);
    update_effect_list();
    jsleep(0,100);
    gdk_threads_enter();
    while(gtk_events_pending()) {
      jsleep(0,50);
      gtk_main_iteration();
    }
    gdk_threads_leave();
    jsleep(0,100);
  }
  return(NULL);
}
コード例 #2
0
int fuse_serve_mount_start_shutdown(void)
{
	char b = 1;
	int i = 0;
	bool failed_found;
	Dprintf("%s()\n", __FUNCTION__);

	if (shutdown_has_started())
		return -1;

	helper.shutdown_started = 1;

	// NOTE: we can probably update this and helper_thread's code
	// so that calling this function shortly after an add or remove is
	// safe.
	while (helper.alive)
	{
		if (++i > 4*MAX_START_SHUTDOWN_WAIT)
		{
			fprintf(stderr, "%s(): Mounts or unmounts still in progress. Good luck with the shutdown!\n", __FUNCTION__);
			break;
		}
		jsleep(HZ / 4);
	}

	// Purge failed mounts
	do {
		mount_t ** mp;
		failed_found = 0;
		for (mp = mounts; mp && *mp; mp++)
			if (!(*mp)->mounted) {
				mount_t * m = *mp;
				failed_found = 1;
				mounts_remove(m);
				free(m->fstitch_path);
				fuse_opt_free_args(&m->args);
				free(m->mountpoint);
				hash_map_destroy(m->parents);
				memset(m, 0, sizeof(*m));
				free(m);
				break;
			}
	} while (failed_found);

	// If only root is mounted unmount it and return shutdown
	if (nmounts == 1)
		return unmount_root();

	// Start the calling of fuse_serve_mount_step_shutdown()
	if (write(unmount_pipe[1], &b, 1) != 1)
	{
		perror("fuse_serve_mount_start_shutdown(): write");
		helper.shutdown_started = 0;
		return -1;
	}

	return 0;
}
コード例 #3
0
static int helper_shutdown(void)
{
	int r = 0;

	while (helper.alive)
	{
		if (++r > 4*MAX_HELPER_SHUTDOWN_WAIT)
		{
			fprintf(stderr, "%s(): helper thread does not seem to be exiting, continuing shutdown behind its back.\n", __FUNCTION__);
			break;
		}
		jsleep(HZ / 4);
	}

	if ((r = pthread_mutex_destroy(&helper.mutex)) < 0)
	{
		fprintf(stderr, "%s(): pthread_mutex_destroy: %d\n", __FUNCTION__, r);
		return -1;
	}
	vector_destroy(helper.queue);
	memset(&helper, 0, sizeof(helper));
	return 0;
}
コード例 #4
0
ファイル: utils.cpp プロジェクト: dyne/MuSE
void gcb_exit(GtkWidget *w, GdkEvent *s)
{
	state=false;
	//leave time for threads to stop, otherwise SIGSEGV might sometimes
	jsleep(1,0); 
}
コード例 #5
0
ファイル: recmail.cpp プロジェクト: dromer/TBT
int main(int argc, char** argv)
{
  int key;
  bool quit = false;
  FILE *mailfd;
  char tbtfile[512];

  cmdline(argc, argv);

  if(!filename[0]) {
    error("no file supplied on the commandline, see usage instructions");
    exit(0);
  }

  func("composing mail in %s",filename);

  // initialize the text console
  if(! con.init() ) exit(-1);

  //  initialize the status line
  status.border = false;
  status.set_name("status box");
  if(! con.place(&status, 0, con.h-10, con.w, con.h) ) {
    error("error placing the status widget");
    exit(-1);
  }
  assert ( status.init() );
  
  //  set the status widget *** only after placing it! ***
  set_status(&status);
  

  // initialize the text canvas
  txt.set_name("editor");
  // txt.border = true;
  if(! con.place(&txt, 0, 0, con.w, con.h-11) ) { //  con.w, con.h-20) ) {
	  error("error placing the text widget");
	  exit(-1);
  }
  assert ( txt.init() );

  // focus the text canvas
  con.focused = &txt;
 

  // start the TBT engine
  if(! tbt.init() ) {
    con.close();
    error("fatal error: can't start the TBT engine");
    exit(0);
  }

  // write out to the status widget
  notice("TBT - console recording - press Ctrl-c when done ");



  // open message file read-write
  mailfd = fopen(filename,"r+");
  if(!mailfd)
    error("can't open file %s: %s", filename, strerror(errno) );
  else {

    // parse the headers from the input file
    char hdrp[1024];
    long pos;

    // go to the last header
    while( fgets(hdrp, 1024, mailfd) ) {
      if(hdrp[0] == '\n') {
	// final part fund
	pos = ftell(mailfd);
	fseek(mailfd, pos-1, SEEK_SET);
	break;
      }
      func("parsed header - %s", hdrp);
    }

    // append the attach header to the message
    snprintf(tbtfile,511,"Attach: %s.tbt\n",filename);
    fputs(tbtfile, mailfd);
    fclose(mailfd);

    // form the filename.tbt
    snprintf(tbtfile,511,"%s.tbt", filename);
  }
      
  while(!quit) {

    key = con.getkey();

    if(key) {

      // save the key and timestamp
      tbt.append(key);

      // display the key
      con.feed(key);

      }
    
    if( ! con.refresh() ) quit = true;

    jsleep(0,1);

  }

  notice("Save and quit");

  act("rendering %s in binary format", tbtfile);
  tbt.save_bin( tbtfile );

  con.refresh();

  con.close();

  exit(0);  
}
コード例 #6
0
ファイル: pipe.cpp プロジェクト: dyne/MuSE
int Pipe::write(int length, void *data) {
  int worklen, origlen, space_samples;
  int space_bytes, len, truelen, blk;
  int ttl = 0;

  if(write_blocking) ttl = write_blocking_time;

  lock();

  _SPACE(space_bytes);
  space_samples = (space_bytes / write_copy_cb->dst_samplesize);
  truelen = length;

  while(length > space_samples) {

    // timeout block mechanism
    if(write_blocking) {
      unlock();
      if(!ttl) {
		return -1; // block timeout
      }
	  jsleep(0,sleep_time*1000); ttl -= sleep_time;
      lock();
      // recalculate actual sizes
      _SPACE(space_bytes);
      space_samples = space_bytes
	/ write_copy_cb->dst_samplesize;

    } else { // non-block

      if(!space_bytes) {
	unlock();
	return 0; // nothing in the pipe
      } else
	// write what's available
	truelen = space_samples;
      break;
    }
  }
  
  origlen = worklen = truelen * write_copy_cb->dst_samplesize;

  while (worklen) {
    
    /* |buffer-----|end***********|start--------|bufferEnd
       |buffer*****|start---------|end**********|bufferEnd */
    len=MIN(worklen, space_bytes);
    
    blk = (char*)bufferEnd-(char*)end;
    blk = MIN(blk, len);
    
    /* fill */
    (*write_copy_cb->callback)
      (end, data,
       blk / write_copy_cb->dst_samplesize);

      end = &((char*)end)[blk]; // (char*)end += blk;
      len -= blk;
      data = &((char*)data)[blk]; // (char*)data += blk;
      worklen -= blk;
      if ((start!=buffer)
	  && (end==bufferEnd))
	end = buffer;
		
    if (len) { // short circuit		

      (*write_copy_cb->callback)
	(end, data,
	 len / write_copy_cb->dst_samplesize);

      data = &((char*)data)[len]; // (char*)data += len;
      end = &((char*)end)[len]; // (char*)end += len;
      worklen -= len;
      
      if ((start!=buffer)
	  && (end==bufferEnd))
	end = buffer;
    }
  }
  _SPACE(space_bytes);
  unlock();
  return ((origlen-worklen) / write_copy_cb->dst_samplesize);
}
コード例 #7
0
ファイル: pipe.cpp プロジェクト: dyne/MuSE
int Pipe::read(int length, void *data) {
  int worklen, origlen, truelen;
  int blk, len, buffered, buffered_bytes;
  int ttl = 0;
  
  if(read_blocking) ttl = read_blocking_time;

  lock();

  _SIZE(buffered_bytes);
  buffered = buffered_bytes 
    / read_copy_cb->src_samplesize;
  truelen = length;


  while(buffered<length) {
    
    /* if less than desired is in, then 
       (blocking) waits
       (non blocking) returns what's available */
    if(read_blocking) {
      unlock();
      if(!ttl) {
		return -1;
      }
	  jsleep(0,sleep_time*1000); ttl -= sleep_time;
      lock();
      _SIZE(buffered_bytes);
      buffered = buffered_bytes 
	/ read_copy_cb->src_samplesize;
    } else {
      // nothing in the pipe
      if(!buffered) {
	    unlock();
        return 0;
      } else
         truelen = buffered;
      break;
    }
  }
  
  origlen = worklen = truelen * read_copy_cb->src_samplesize;
  
  while (worklen) {
    
    /* |buffer*****|end-----------|start********|bufferEnd
       |buffer-----|start*********|end----------|bufferEnd */
    
    len = MIN(worklen,buffered_bytes);
    
    blk = ((char*)bufferEnd - (char*)start);
    
    blk=MIN(blk,len);
    
    /* fill */
    (*read_copy_cb->callback)
      (data, start,
       blk / read_copy_cb->src_samplesize);
    /* blank just copied bytes */
    //memset(start,0,blk / read_copy_cb->src_samplesize);
    
    start = &((char*)start)[blk]; // (char*)start += blk;
    len -= blk;
    data = &((char*)data)[blk]; // (char*)data += blk;
    worklen -= blk;
    if ((end!=buffer) && (start==bufferEnd))
      start = buffer;
    
    if (len) { /* short circuit */
      
      (*read_copy_cb->callback)
	(data, start,
	 len / read_copy_cb->src_samplesize);
      
    //  /* blank just copied bytes */
    //  memset(start,0,len / read_copy_cb->src_samplesize);
      data = &((char*)data)[len]; // (char*)data += len;
      start = &((char*)start)[len]; // (char*)start += len;
      worklen -= len;
      if ((end!=buffer) && (start==bufferEnd))
	start = buffer;
    }
  }
  if (start == end)  /* if this read emptied buffer */
	start = end = buffer; /* reset pointers to le _SIZE behave correctly */
  
  unlock();
  return ( (origlen-worklen)/read_copy_cb->src_samplesize );
}
コード例 #8
0
ファイル: gtk_ctrl.cpp プロジェクト: dewn49/FreeJ
void gtk_ctrl_quit() {
  env->quit = quit = true;
  jsleep(0,500);
  if(pthread_attr_destroy(&_attr) == -1)
    error("error destroying POSIX thread attribute");
}