示例#1
0
static GRealThreadPool*
g_thread_pool_wait_for_new_pool (void)
{
  GRealThreadPool *pool;
  gint local_wakeup_thread_serial;
  guint local_max_unused_threads;
  gint local_max_idle_time;
  gint last_wakeup_thread_serial;
  gboolean have_relayed_thread_marker = FALSE;

  local_max_unused_threads = g_atomic_int_get (&max_unused_threads);
  local_max_idle_time = g_atomic_int_get (&max_idle_time);
  last_wakeup_thread_serial = g_atomic_int_get (&wakeup_thread_serial);

  g_atomic_int_inc (&unused_threads);

  do
    {
      if (g_atomic_int_get (&unused_threads) >= local_max_unused_threads)
        {
          /* If this is a superfluous thread, stop it. */
          pool = NULL;
        }
      else if (local_max_idle_time > 0)
        {
          /* If a maximal idle time is given, wait for the given time. */
          DEBUG_MSG (("thread %p waiting in global pool for %f seconds.",
                      g_thread_self (), local_max_idle_time / 1000.0));

          pool = g_async_queue_timeout_pop (unused_thread_queue,
					    local_max_idle_time * 1000);
        }
      else
        {
          /* If no maximal idle time is given, wait indefinitely. */
          DEBUG_MSG (("thread %p waiting in global pool.", g_thread_self ()));
          pool = g_async_queue_pop (unused_thread_queue);
        }

      if (pool == wakeup_thread_marker)
        {
          local_wakeup_thread_serial = g_atomic_int_get (&wakeup_thread_serial);
          if (last_wakeup_thread_serial == local_wakeup_thread_serial)
            {
              if (!have_relayed_thread_marker)
              {
                /* If this wakeup marker has been received for
                 * the second time, relay it.
                 */
                DEBUG_MSG (("thread %p relaying wakeup message to "
                            "waiting thread with lower serial.",
                            g_thread_self ()));

                g_async_queue_push (unused_thread_queue, wakeup_thread_marker);
                have_relayed_thread_marker = TRUE;

                /* If a wakeup marker has been relayed, this thread
                 * will get out of the way for 100 microseconds to
                 * avoid receiving this marker again.
                 */
                g_usleep (100);
              }
            }
          else
            {
              if (g_atomic_int_add (&kill_unused_threads, -1) > 0)
                {
                  pool = NULL;
                  break;
                }

              DEBUG_MSG (("thread %p updating to new limits.",
                          g_thread_self ()));

              local_max_unused_threads = g_atomic_int_get (&max_unused_threads);
              local_max_idle_time = g_atomic_int_get (&max_idle_time);
              last_wakeup_thread_serial = local_wakeup_thread_serial;

              have_relayed_thread_marker = FALSE;
            }
        }
    }
  while (pool == wakeup_thread_marker);

  g_atomic_int_add (&unused_threads, -1);

  return pool;
}
示例#2
0
void sig_usr1(int sig) {
  int *x;
  x=malloc(sizeof(int));
  printf("Signal USR1\n");
  g_async_queue_push(queue1, x);
}
/*
 * Construct new bufferpool and allocate buffers from driver
 *
 * @elem      the parent element that owns this buffer
 * @fd        the file descriptor of the device file
 * @count     the requested number of buffers in the pool
 * @caps      the requested buffer caps
 * @return the bufferpool or <code>NULL</code> if error
 */
GstBufferClassBufferPool *
gst_buffer_manager_new (GstElement * elem, int fd, int count, GstCaps * caps)
{
  GstBufferClassBufferPool *pool = NULL;
  GstVideoFormat format;
  gint width, height ;
  void          *vidStreamBufVa;
  unsigned long vidStreamBufPa;
  int n, i;
  gst_initpacket pack_info;
  if (gst_video_format_parse_caps(caps, &format, &width, &height)) {
    bc_buf_params_t param;

/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
    CMEM_init();

    vidStreamBufVa = CMEM_alloc((width*height*2*MAX_FCOUNT), &cmem_params);
    if (!vidStreamBufVa)
    {
        printf ("CMEM_alloc for Video Stream buffer returned NULL \n");
        return NULL; 
    }

    vidStreamBufPa = CMEM_getPhys(vidStreamBufVa);
    for (i = 0; i < count; i++)
    {
        TextureBufsPa[i] = vidStreamBufPa + (width*height*2*i);
    }
/****************************************************************************/
/****************************************************************************/
/****************************************************************************/
    param.count = count;
    param.width = width;     /* width should be multiple of 32 */
    param.height = height;
    
    switch(format)
    {
        case 3 :   param.fourcc = BC_PIX_FMT_YUYV;
                   break;

	case 22:   param.fourcc = BC_PIX_FMT_NV12;
		   break;

	case 4 :    param.fourcc = BC_PIX_FMT_UYVY;
                   break;

	default:   /* Uknown Format */
                   return -1;

    }
    param.type = BC_MEMORY_USERPTR;

    pack_info.params = param;
    pack_info.phyaddr = vidStreamBufPa;

    n = write(fd_bcinit_fifo, &pack_info, sizeof(gst_initpacket));

   if(n != sizeof(gst_initpacket))
   {
	printf("Error in writing to queue\n");
   }
	
  /* We no longer need this pipe */
   close(fd_bcinit_fifo);

    /* construct bufferpool */
    pool = (GstBufferClassBufferPool *)
        gst_mini_object_new (GST_TYPE_BCBUFFERPOOL);

//TODO: Remove fd from pool -not required any more.
    pool->fd = -1;
    pool->elem = elem;
    pool->num_buffers = param.count;


    GST_DEBUG_OBJECT (pool->elem, "orig caps: %" GST_PTR_FORMAT, caps);
    GST_DEBUG_OBJECT (pool->elem, "requested %d buffers, got %d buffers", count,
        param.count);
    
    pool->caps = caps;

    /* and allocate buffers:
     */
    pool->num_buffers = param.count;
    pool->buffers = g_new0 (GstBufferClassBuffer *, param.count);
    pool->avail_buffers = g_async_queue_new_full (
        (GDestroyNotify) gst_mini_object_unref);

    for (i = 0; i < param.count; i++) {
     // TODO: Find correct size here
      GstBufferClassBuffer *buf = gst_bcbuffer_new (pool, i, param.width*param.height*2, TextureBufsPa[i]);
  GST_BUFFER_DATA (buf) = (vidStreamBufVa +  param.width*param.height*2*i);
  GST_BUFFER_SIZE (buf) = param.width*param.height*2;

      if (G_UNLIKELY (!buf)) {
        GST_WARNING_OBJECT (pool->elem, "Buffer %d allocation failed", i);
        goto fail;
      }
      gst_buffer_set_caps (GST_BUFFER (buf), caps);
      pool->buffers[i] = buf;
      g_async_queue_push (pool->avail_buffers, buf);
    }

    return pool;
  } else {
/* thread safe */
void
dropbox_command_client_request(DropboxCommandClient *dcc, DropboxCommand *dc) {
    g_async_queue_push(dcc->command_queue, dc);
}
示例#5
0
文件: client_mngr.c 项目: regit/nufw
/**
 * Ask each client of global_msg address set to send their new connections
 * (connections in stage "SYN SENT").
 *
 * \param global_msg Address set of clients
 * \return Returns 0 on error, 1 otherwise
 */
char warn_clients(struct msg_addr_set *global_msg,
		  user_session_check_t *scheck,
		  gpointer data)
{
	ip_sessions_t *ipsessions = NULL;
	GSList *ipsockets = NULL;
	struct timeval timestamp;
	struct timeval interval;
#if DEBUG_ENABLE
	if (DEBUG_OR_NOT(DEBUG_LEVEL_VERBOSE_DEBUG, DEBUG_AREA_USER)) {
		char addr_ascii[INET6_ADDRSTRLEN];
		format_ipv6(&global_msg->addr, addr_ascii, INET6_ADDRSTRLEN, NULL);
		g_message("Warn client(s) on IP %s", addr_ascii);
	}
#endif

	lock_client_datas();
	ipsessions = g_hash_table_lookup(client_ip_hash, &global_msg->addr);
	if (ipsessions) {
		global_msg->found = TRUE;
		/* if data or scheck is not NULL we need to send the message and thus
		we do not enter the delay code */
		if ((!(data || scheck)) && ipsessions->proto_version >= PROTO_VERSION_V22_1) {
			gettimeofday(&timestamp, NULL);
			timeval_substract(&interval, &timestamp, &(ipsessions->last_message));
			if ((interval.tv_sec == 0) && ((unsigned)interval.tv_usec < nuauthconf->push_delay)) {
				unlock_client_datas();
				return 1;
			} else {
				ipsessions->last_message.tv_sec = timestamp.tv_sec;
				ipsessions->last_message.tv_usec = timestamp.tv_usec;
			}
		}
		for (ipsockets = ipsessions->sessions; ipsockets; ipsockets = ipsockets->next) {
			user_session_t *session = (user_session_t *)ipsockets->data;

			if ((!scheck) || scheck(session, data)) {
				struct msg_addr_set *gmsg = g_memdup(global_msg, sizeof(*global_msg));
				gmsg->msg = g_memdup(global_msg->msg,
						     ntohs(global_msg->msg->length));
#if DEBUG_ENABLE
				if (DEBUG_OR_NOT(DEBUG_LEVEL_VERBOSE_DEBUG, DEBUG_AREA_USER)) {
					char addr_ascii[INET6_ADDRSTRLEN];
					format_ipv6(&global_msg->addr, addr_ascii, INET6_ADDRSTRLEN, NULL);
					g_message("Queuing message for %s (%d)",
						  addr_ascii,
						  session->socket);
				}
#endif
				g_async_queue_push(session->workunits_queue, gmsg);
				if (session->activated) {
					session->activated = FALSE;
					g_async_queue_push(writer_queue,
							   GINT_TO_POINTER(session->socket));
					ev_async_send(session->srv_context->loop,
							&session->srv_context->client_writer_signal);
				}
			}
		}

		unlock_client_datas();
		return 1;
	} else {
		global_msg->found = FALSE;
		unlock_client_datas();
		return 0;
	}
}
示例#6
0
/*!
  \brief set_offline_mode() is called when the "Offline Mode" button is clicked
  in the general tab and is used to present the user with list of firmware 
  choices to select one for loading to work in offline mode (no connection to
  an ECU)
  */
G_MODULE_EXPORT gboolean set_offline_mode(void)
{
	GtkWidget * widget = NULL;
	gchar * filename = NULL;
	gboolean tmp = TRUE;
	GArray *pfuncs = NULL;
	PostFunction *pf = NULL;
	GAsyncQueue *io_repair_queue = NULL;
	Firmware_Details *firmware = NULL;
	void (*load_firmware_details)(void *,const gchar *) = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	io_repair_queue = (GAsyncQueue *)DATA_GET(global_data,"io_repair_queue");

	/* Cause Serial Searcher thread to abort.... */
	if (io_repair_queue)
		g_async_queue_push(io_repair_queue,&tmp);

	filename = present_firmware_choices();
	if (!filename)
	{
		DATA_SET(global_data,"offline",GINT_TO_POINTER(FALSE));
		DATA_SET(global_data,"interrogated",GINT_TO_POINTER(FALSE));
		widget = lookup_widget("interrogate_button");
		if (GTK_IS_WIDGET(widget))
			gtk_widget_set_sensitive(GTK_WIDGET(widget),TRUE);
		widget = lookup_widget("offline_button");
		if (GTK_IS_WIDGET(widget))
			gtk_widget_set_sensitive(GTK_WIDGET(widget),TRUE);
		plugins_shutdown();
		/* Does this need a delay? */
		personality_choice();

		EXIT();
		return FALSE;
	}

	DATA_SET_FULL(global_data,"last_offline_profile",g_strdup(filename),g_free);
	DATA_SET(global_data,"offline",GINT_TO_POINTER(TRUE));
	DATA_SET(global_data,"interrogated",GINT_TO_POINTER(TRUE));

	/* Disable interrogation button */
	widget = lookup_widget("interrogate_button");
	if (GTK_IS_WIDGET(widget))
		gtk_widget_set_sensitive(GTK_WIDGET(widget),FALSE);

	widget = lookup_widget("netaccess_table");
	if (GTK_IS_WIDGET(widget))
		gtk_widget_set_sensitive(GTK_WIDGET(widget),FALSE);

	queue_function("kill_conn_warning");

	if (!firmware)
	{
		firmware = g_new0(Firmware_Details,1);
		DATA_SET(global_data,"firmware",firmware);
	}
	if (get_symbol("load_firmware_details",(void **)&load_firmware_details))
	{
		load_firmware_details(firmware,filename);
	}
	else
		printf("Unable to load firmware details!\n");

	pfuncs = g_array_new(FALSE,TRUE,sizeof(PostFunction *));

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("update_interrogation_gui_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("load_realtime_map_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("initialize_dashboards_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("load_status_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("load_rt_text_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("load_gui_tabs_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("start_statuscounts_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("disable_burner_buttons_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	/* BUG, causes deadlock
	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("offline_ecu_restore_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);
	*/

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("setup_menu_handlers_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("enable_3d_buttons_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("ready_msg_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("cleanup_pf");
	get_symbol(pf->name,(void **)&pf->function_w_arg);
	pf->w_arg = TRUE;
	pfuncs = g_array_append_val(pfuncs,pf);

	io_cmd(NULL,pfuncs);

	/*
	   io_cmd(firmware->get_all_command,NULL);
	 */

	widget = lookup_widget("binary_logging_frame");
	if (GTK_IS_WIDGET(widget))
		gtk_widget_set_sensitive(GTK_WIDGET(widget),FALSE);
	widget = lookup_widget("interrogate_button");
	if (GTK_IS_WIDGET(widget))
		gtk_widget_set_sensitive(GTK_WIDGET(widget),FALSE);
	widget = lookup_widget("offline_button");
	if (GTK_IS_WIDGET(widget))
		gtk_widget_set_sensitive(GTK_WIDGET(widget),FALSE);
	g_list_foreach(get_list("get_data_buttons"),set_widget_sensitive,GINT_TO_POINTER(FALSE));

	pfuncs = g_array_new(FALSE,TRUE,sizeof(PostFunction *));

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("reset_temps_pf");
	get_symbol(pf->name,(void **)&pf->function);
	pf->w_arg = FALSE;
	pfuncs = g_array_append_val(pfuncs,pf);

	pf = g_new0(PostFunction,1);
	pf->name = g_strdup("cleanup_pf");
	get_symbol(pf->name,(void **)&pf->function_w_arg);
	pf->w_arg = TRUE;
	pfuncs = g_array_append_val(pfuncs,pf);
	io_cmd(NULL,pfuncs);
	EXIT();
	return FALSE;
}