Пример #1
0
/**
 * init a connection pool
 */
network_connection_pool *network_connection_pool_new(void) {
	network_connection_pool *pool;

	pool = g_new0(network_connection_pool, 1);

	g_mutex_init(&(pool->connection_pool_mutex));
	g_mutex_lock(&(pool->connection_pool_mutex));
	pool->users = g_hash_table_new_full(g_hash_table_string_hash, g_hash_table_string_equal, g_hash_table_string_free, g_queue_free_all);
	g_mutex_unlock(&(pool->connection_pool_mutex));

	/**
	 * added by jinxuan hou, 2013/04/11
	 * initialize statistical information of the conn pool
	 *
	 * @@jinxuanhou
	 */
	
	pool->conn_pool_status = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_hash_pool_status_free);
	//初始化读写锁
	g_rw_lock_init (&pool->pool_status_lock);
	//	pool->conn_num_in_use = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_hash_table_int_free);
	//	pool->conn_pending = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_hash_table_int_free);

	pool->garbage_connection_pool = garbage_connection_pool_new();

	return pool;
}
static void gst_scream_queue_init(GstScreamQueue *self)
{
    self->sink_pad = gst_pad_new_from_static_template(&sink_template, "sink");
    gst_pad_set_chain_function(self->sink_pad, GST_DEBUG_FUNCPTR(gst_scream_queue_sink_chain));
    gst_pad_set_event_function(self->sink_pad, GST_DEBUG_FUNCPTR(gst_scream_queue_sink_event));
    GST_PAD_SET_PROXY_CAPS(self->sink_pad);
    gst_element_add_pad(GST_ELEMENT(self), self->sink_pad);

    self->src_pad = gst_pad_new_from_static_template(&src_template, "src");
    gst_pad_set_event_function(self->src_pad, GST_DEBUG_FUNCPTR(gst_scream_queue_src_event));
    GST_PAD_SET_PROXY_CAPS(self->src_pad);
    gst_element_add_pad(GST_ELEMENT(self), self->src_pad);

    g_rw_lock_init(&self->lock);
    self->streams = g_hash_table_new_full(NULL, NULL, NULL, (GDestroyNotify) destroy_stream);
    self->adapted_stream_ids = g_hash_table_new(NULL, NULL);
    self->ignored_stream_ids = g_hash_table_new(NULL, NULL);

    self->scream_controller_id = DEFAULT_GST_SCREAM_CONTROLLER_ID;
    self->scream_controller = NULL;
    self->approved_packets = gst_data_queue_new(
        (GstDataQueueCheckFullFunction)fake_queue_check_full_cb,
        NULL, NULL, self);

    self->incoming_packets = g_async_queue_new();

    self->priority = DEFAULT_PRIORITY;
    self->pass_through = DEFAULT_PASS_THROUGH;
    self->next_approve_time = 0;
}
Пример #3
0
void
srvtimer_init(void)
{
	INFO("timers initialization done");
	memset(&rw_lock, 0, sizeof(rw_lock));
	g_rw_lock_init(&rw_lock);
}
Пример #4
0
static int
VideoGainOffsetFilter_init( py_obj_VideoGainOffsetFilter *self, PyObject *args, PyObject *kwds ) {
    PyObject *source;
    framefunc_init( &self->gain_func, 1.0, 0.0, 0.0, 0.0 );
    framefunc_init( &self->offset_func, 0.0, 0.0, 0.0, 0.0 );

    PyObject *gain_obj = NULL, *offset_obj = NULL;

    static char *kwlist[] = { "source", "gain", "offset", NULL };

    if( !PyArg_ParseTupleAndKeywords( args, kwds, "O|OO", kwlist,
            &source, &gain_obj, &offset_obj ) )
        return -1;

    if( !py_video_take_source( source, &self->source ) )
        return -1;

    if( gain_obj && !py_framefunc_take_source( gain_obj, &self->gain_func ) ) {
        py_video_take_source( NULL, &self->source );
        return -1;
    }

    if( offset_obj && !py_framefunc_take_source( offset_obj, &self->offset_func ) ) {
        py_video_take_source( NULL, &self->source );
        py_framefunc_take_source( NULL, &self->gain_func );
        return -1;
    }

    g_rw_lock_init( &self->rwlock );

    return 0;
}
Пример #5
0
/*
 * view_new
 */
view *
view_new ( store *store,
           gdouble length,
           gdouble precision )
{
  view *v;

  v = (view *) g_malloc ( sizeof(view) );

  v->store = store;

  v->nb_cols = store->nb_cols;
  v->cols = NULL; /*todo : allow customization and use GList_alloc ( ); */

  v->current_line = g_malloc ( v->nb_cols * sizeof(gdouble) );
  v->current_line_most_recent_data = g_malloc ( v->nb_cols * sizeof(gdouble) );

  v->most_recent_entry = 0;

  v->length = length;
  v->precision = precision;

  /*expected number of entries : v->nb_entries = 1 + (guint) ceil(length/precision);*/

  v->blocks_head = vblock_new ( v->nb_cols );
  v->blocks_tail = v->blocks_head;

  g_rw_lock_init ( &(v->lock) );

  return v;
}
Пример #6
0
static void
test_rwlock (void)
{
  GRWLock lock;

  g_rw_lock_init (&lock);
  g_rw_lock_clear (&lock);
}
/**
 * user_db_sql_rule_table 构造函数
 * @return user_db_sql_rule_table变量指针
 */
user_db_sql_rule_table *user_db_sql_rule_table_new() {
	user_db_sql_rule_table *table = g_new0(user_db_sql_rule_table, 1);
	table->user_db_sql_rule[SQL_SINGLE] = g_hash_table_new_full(g_hash_table_string_hash,
			g_hash_table_string_equal,
			g_hash_table_string_free,
			g_hash_table_db_rule_table_free);

	table->user_db_sql_rule[SQL_TEMPLATE] = g_hash_table_new_full(g_hash_table_string_hash,
				g_hash_table_string_equal,
				g_hash_table_string_free,
				g_hash_table_db_rule_table_free);

	g_rw_lock_init(&table->table_lock[SQL_SINGLE]);
	g_rw_lock_init(&table->table_lock[SQL_TEMPLATE]);

	return table;
}
Пример #8
0
static void
fu_mutex_init (FuMutex *self)
{
	g_rw_lock_init (&self->rw_lock);
#ifdef FU_MUTEX_DEBUG
	self->reader = g_string_new (NULL);
	self->writer = g_string_new (NULL);
#endif
}
Пример #9
0
void
_priv_gst_meta_initialize (void)
{
  g_rw_lock_init (&lock);
  metainfo = g_hash_table_new (g_str_hash, g_str_equal);

  _gst_meta_transform_copy = g_quark_from_static_string ("gst-copy");
  _gst_meta_tag_memory = g_quark_from_static_string ("memory");
}
/**
 * sql_rule_table 构造函数
 * @return 构造的新的规则表实例
 */
sql_rule_table *sql_rule_table_new() {
	sql_rule_table *table = g_new0(sql_rule_table, 1);
	table->sql_rule = g_hash_table_new_full(g_hash_table_string_hash,
			g_hash_table_string_equal,
			g_hash_table_string_free,
			g_hash_table_sql_rule_free);

	g_rw_lock_init(&table->table_lock);
	return table;
}
Пример #11
0
int init_freeqd_state(struct freeq_ctx *freeqctx, struct freeqd_state *s)
{
        freeq_generation_t *fgen;
        if (freeq_generation_new(&fgen))
        {
                dbg(freeqctx, "unable to allocate generation\n");
                return FREEQ_ERR;
        }
        g_rw_lock_init(&(s->rw_lock));
        s->current = fgen;
        return 0;
}
Пример #12
0
static void
test_rwlock1 (void)
{
  GRWLock lock;

  g_rw_lock_init (&lock);
  g_rw_lock_writer_lock (&lock);
  g_rw_lock_writer_unlock (&lock);
  g_rw_lock_writer_lock (&lock);
  g_rw_lock_writer_unlock (&lock);
  g_rw_lock_clear (&lock);
}
Пример #13
0
/**
 * create the data structure for a new event-thread
 */
chassis_event_thread_t *chassis_event_thread_new(guint index) {
    chassis_event_thread_t *thread = g_new0(chassis_event_thread_t, 1);

    thread->index = index;

    thread->event_queue = g_async_queue_new();

    g_rw_lock_init(&thread->connection_lock);
    thread->connection_list = NULL;

    thread->exit_phase = EVENT_THREAD_NORMAL;
    return thread;
}
Пример #14
0
/* Definition of filter */
sql_filter *
sql_filter_new(int flag)
{
    sql_filter *filter = g_new0(sql_filter, 1);
    filter->blacklist = g_hash_table_new_full((GHashFunc)g_str_hash,
                                    (GEqualFunc)sql_filter_equal_func,
                                    g_free,
                                    (GDestroyNotify) sql_filter_hval_free);
    filter->auto_filter_flag = 0;
    filter->manual_filter_flag = 0;
    g_rw_lock_init(&filter->sql_filter_lock);

    return filter;
}
Пример #15
0
struct meta0_backend_s *
meta0_backend_init(const gchar *ns, const gchar *id,
		struct sqlx_repository_s *repo)
{
	struct meta0_backend_s *m0 = g_malloc0(sizeof(*m0));
	g_rw_lock_init(&(m0->rwlock));
	m0->id = g_strdup(id);
	m0->ns = g_strdup(ns);
	m0->array_by_prefix = NULL;
	m0->array_meta1_ref = NULL;
	m0->repository = repo;
	m0->reload_requested = FALSE;

	return m0;
}
Пример #16
0
Файл: drew.c Проект: bk2204/drew
DrewLoader *drew_loader_new(void)
{
    DrewLoader *ldr;

    if (!(ldr = g_slice_new(DrewLoader)))
        return NULL;

    memset(ldr, 0, sizeof(*ldr));

    ldr->ref_count = 1;

    // This protects everything except the reference count, which is atomic.
    g_rw_lock_init(&ldr->lock);

    return ldr;
}
Пример #17
0
static void _shadowtorpreload_cryptoSetup(int numLocks) {
    G_LOCK(shadowtorpreloadPrimaryLock);

    if(!shadowtorpreloadGlobalState.initialized) {
        shadowtorpreloadGlobalState.numCryptoThreadLocks = numLocks;

        shadowtorpreloadGlobalState.cryptoThreadLocks = g_new0(GRWLock, numLocks);
        for(gint i = 0; i < numLocks; i++) {
            g_rw_lock_init(&(shadowtorpreloadGlobalState.cryptoThreadLocks[i]));
        }

        shadowtorpreloadGlobalState.initialized = TRUE;
    }

    shadowtorpreloadGlobalState.nThreads++;

    G_UNLOCK(shadowtorpreloadPrimaryLock);
}
Пример #18
0
/*
 * refstore_new
 */
refstore *
refstore_new ( gchar *path )
{
  refstore *rs;
  rs = (refstore *) g_malloc ( sizeof(refstore) );

  rs->path = g_strdup ( path );

  rs->epoch = time ( NULL );

  rs->nb_entries = 0;
  rs->blocks_head = NULL;
  rs->blocks_tail = NULL;

  g_rw_lock_init ( &(rs->lock) );

  return rs;
}
Пример #19
0
slow_query_log_config_t *slow_query_log_config_t_new(void) {
	slow_query_log_config_t *config = NULL;
	config = g_new0(slow_query_log_config_t, 1);
	if (config != NULL) {
		g_rw_lock_init ( &(config->rwlock) );
		g_rw_lock_writer_lock ( &(config->rwlock) );
		config->is_enabled = FALSE;
		config->log_file = slow_query_log_file_t_new();
		config->filter = slow_query_log_filter_t_new();
		if (config->log_file == NULL || config->filter == NULL) {
			g_rw_lock_writer_unlock ( &(config->rwlock) );
			slow_query_log_config_t_free(config);
			config = NULL;
		} else {
			g_rw_lock_writer_unlock ( &(config->rwlock) );
		}
	}
	return config;
}
Пример #20
0
/* Definition of reserved_query */
sql_reserved_query *
sql_reserved_query_new(void)
{
    sql_reserved_query *srq = g_new0(sql_reserved_query, 1);

    srq->ht_reserved_query = g_hash_table_new_full((GHashFunc)g_str_hash,
                                    (GEqualFunc)sql_filter_equal_func,
                                    g_free,
                                    (GDestroyNotify) reserved_query_item_free);

    srq->gq_reserved_long_query =  g_queue_new();
    srq->gq_reserved_short_query = g_queue_new();

    srq->freq_time_window = 0;

    g_rw_lock_init(&srq->rq_lock);

    return srq;
}
Пример #21
0
JS_EXPORT_API
void dock_emit_webview_ok()
{
    static gboolean inited = FALSE;
    if (!inited) {
        if (!is_compiz_plugin_valid()) {
            gtk_widget_hide(container);
            GtkWidget* dialog = gtk_message_dialog_new(NULL, GTK_DIALOG_MODAL,
                                                       GTK_MESSAGE_ERROR,
                                                       GTK_BUTTONS_OK,
                                                       _("Dock failed to start"
                                                         ", because "
                                                         "Compiz is not "
                                                         "enabled."));
            gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
            exit(2);
        }

        inited = TRUE;
        init_config();
    }

    g_warning("[%s]", __func__);

    GRWLock lock;
    g_rw_lock_init(&lock);  // non-static GRWLock must init and clear.
    g_rw_lock_writer_lock(&lock);
    update_primary_info(&dock);
    g_rw_lock_writer_unlock(&lock);
    g_rw_lock_clear(&lock);

    _update_dock_size(dock.x, dock.y, dock.width, dock.height);
    gtk_widget_show_all(container);

    GD.is_webview_loaded = TRUE;

    if (GD.config.hide_mode == ALWAYS_HIDE_MODE) {
        // dock_hide_now();
    } else {
    }
    dde_session_register();
}
Пример #22
0
static void
test_rwlock7 (void)
{
  gint i;
  GThread *threads[THREADS];

  for (i = 0; i < LOCKS; i++)
    g_rw_lock_init (&locks[i]);

  for (i = 0; i < THREADS; i++)
    threads[i] = g_thread_new ("test", thread_func, NULL);

  for (i = 0; i < THREADS; i++)
    g_thread_join (threads[i]);

  for (i = 0; i < LOCKS; i++)
    g_rw_lock_clear (&locks[i]);

  for (i = 0; i < LOCKS; i++)
    g_assert (owners[i] == NULL);
}
Пример #23
0
void
_priv_gst_memory_initialize (void)
{
  g_rw_lock_init (&lock);
  allocators = g_hash_table_new (g_str_hash, g_str_equal);

#ifdef HAVE_GETPAGESIZE
#ifdef MEMORY_ALIGNMENT_PAGESIZE
  gst_memory_alignment = getpagesize () - 1;
#endif
#endif

  GST_CAT_DEBUG (GST_CAT_MEMORY, "memory alignment: %" G_GSIZE_FORMAT,
      gst_memory_alignment);

  _sysmem_allocator = g_object_new (gst_allocator_sysmem_get_type (), NULL);

  gst_allocator_register (GST_ALLOCATOR_SYSMEM,
      gst_object_ref (_sysmem_allocator));

  _default_allocator = gst_object_ref (_sysmem_allocator);
}
SchedulerPolicy* schedulerpolicyhoststeal_new() {
    HostStealPolicyData* data = g_new0(HostStealPolicyData, 1);
    data->threadList = g_array_new(FALSE, FALSE, sizeof(HostStealThreadData*));
    data->hostToQueueDataMap = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_hoststealqueuedata_free);
    data->threadToThreadDataMap = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)_hoststealthreaddata_free);
    data->hostToThreadMap = g_hash_table_new(g_direct_hash, g_direct_equal);
    g_rw_lock_init(&data->lock);

    SchedulerPolicy* policy = g_new0(SchedulerPolicy, 1);
    MAGIC_INIT(policy);
    policy->addHost = _schedulerpolicyhoststeal_addHost;
    policy->getAssignedHosts = _schedulerpolicyhoststeal_getHosts;
    policy->push = _schedulerpolicyhoststeal_push;
    policy->pop = _schedulerpolicyhoststeal_pop;
    policy->getNextTime = _schedulerpolicyhoststeal_getNextTime;
    policy->free = _schedulerpolicyhoststeal_free;

    policy->type = SP_PARALLEL_HOST_STEAL;
    policy->data = data;
    policy->referenceCount = 1;

    return policy;
}
Пример #25
0
/* This test has 2 writers and 10 readers.
 * The writers modify an integer multiple times,
 * but always leave it with an even value.
 * The readers verify that they can only observe
 * even values
 */
static void
test_rwlock8 (void)
{
  gint i;

  even = 0;
  g_rw_lock_init (&even_lock);

  for (i = 0; i < 2; i++)
    writers[i] = g_thread_new ("a", writer_func, GINT_TO_POINTER (i));

  for (i = 0; i < 10; i++)
    readers[i] = g_thread_new ("b", reader_func, NULL);

  for (i = 0; i < 2; i++)
    g_thread_join (writers[i]);

  for (i = 0; i < 10; i++)
    g_thread_join (readers[i]);

  g_assert (even % 2 == 0);

  g_rw_lock_clear (&even_lock);
}
Пример #26
0
DupinAttachmentDB *
dupin_attachment_db_connect (Dupin * d, gchar * name, gchar * path,
			     DupinSQLiteOpenType mode,
			     GError ** error)
{
  gchar *query;
  gchar *errmsg;
  DupinAttachmentDB *attachment_db;

  attachment_db = g_malloc0 (sizeof (DupinAttachmentDB));

  attachment_db->d = d;

  attachment_db->name = g_strdup (name);
  attachment_db->path = g_strdup (path);

  attachment_db->rwlock = g_new0 (GRWLock, 1);
  g_rw_lock_init (attachment_db->rwlock);

  if (sqlite3_open_v2 (attachment_db->path, &attachment_db->db, dupin_util_dupin_mode_to_sqlite_mode (mode), NULL) != SQLITE_OK)
    {
      if (error != NULL && *error != NULL)
        g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN,
		   "Attachment DB error.");
      dupin_attachment_db_disconnect (attachment_db);
      return NULL;
    }

  sqlite3_busy_timeout (attachment_db->db, DUPIN_SQLITE_TIMEOUT);

  if (mode == DP_SQLITE_OPEN_CREATE)
    {
      if (sqlite3_exec (attachment_db->db, "PRAGMA journal_mode = WAL", NULL, NULL, &errmsg) != SQLITE_OK
          || sqlite3_exec (attachment_db->db, "PRAGMA encoding = \"UTF-8\"", NULL, NULL, &errmsg) != SQLITE_OK)
        {
          if (error != NULL && *error != NULL)
            g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "Cannot set pragma journal_mode or encoding: %s",
		   errmsg);
          sqlite3_free (errmsg);
          dupin_attachment_db_disconnect (attachment_db);
          return NULL;
        }

      if (dupin_attachment_db_begin_transaction (attachment_db, error) < 0)
        {
          dupin_attachment_db_disconnect (attachment_db);
          return NULL;
        }

      if (sqlite3_exec (attachment_db->db, DUPIN_ATTACHMENT_DB_SQL_MAIN_CREATE, NULL, NULL, &errmsg) != SQLITE_OK
          || sqlite3_exec (attachment_db->db, DUPIN_ATTACHMENT_DB_SQL_DESC_CREATE, NULL, NULL, &errmsg) != SQLITE_OK
          || sqlite3_exec (attachment_db->db, DUPIN_ATTACHMENT_DB_SQL_CREATE_INDEX, NULL, NULL, &errmsg) != SQLITE_OK)
        {
          if (error != NULL && *error != NULL)
            g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "%s",
		   errmsg);
          sqlite3_free (errmsg);
	  dupin_attachment_db_rollback_transaction (attachment_db, error);
          dupin_attachment_db_disconnect (attachment_db);
          return NULL;
        }

      if (dupin_attachment_db_commit_transaction (attachment_db, error) < 0)
        {
          dupin_attachment_db_disconnect (attachment_db);
          return NULL;
        }
    }

  /* check attachment_db version */
  gint user_version = 0;

  if (sqlite3_exec (attachment_db->db, "PRAGMA user_version", dupin_attachment_db_get_user_version_cb, &user_version, &errmsg) != SQLITE_OK)
    {
      /* default to 1 if not found or error - TODO check not SQLITE_OK error only */
      user_version = 1;
    }

  if (user_version > DUPIN_SQLITE_MAX_USER_VERSION)
    {
      if (error != NULL && *error != NULL) 
        g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "SQLite attachment db user version (%d) is newer than I know how to work with (%d).",
				user_version, DUPIN_SQLITE_MAX_USER_VERSION);
      sqlite3_free (errmsg);
      dupin_attachment_db_disconnect (attachment_db);
      return NULL;
    }

  if (user_version <= 1)
    {
      if (sqlite3_exec (attachment_db->db, DUPIN_ATTACHMENT_DB_SQL_DESC_UPGRADE_FROM_VERSION_1, NULL, NULL, &errmsg) != SQLITE_OK)
        {
          if (error != NULL && *error != NULL)
            g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "%s",
                   errmsg);
          sqlite3_free (errmsg);
          dupin_attachment_db_disconnect (attachment_db);
          return NULL;
        }
    }

  gchar * cache_size = g_strdup_printf ("PRAGMA cache_size = %d", DUPIN_SQLITE_CACHE_SIZE); 
  if (sqlite3_exec (attachment_db->db, "PRAGMA temp_store = memory", NULL, NULL, &errmsg) != SQLITE_OK
      || sqlite3_exec (attachment_db->db, cache_size, NULL, NULL, &errmsg) != SQLITE_OK)
    {   
      if (error != NULL && *error != NULL)
        g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "Cannot set pragma temp_store: %s",
                   errmsg);
      sqlite3_free (errmsg);
      if (cache_size)
        g_free (cache_size); 
      dupin_attachment_db_disconnect (attachment_db);
      return NULL;
    }

  if (cache_size)
    g_free (cache_size);

  /*
   TODO - check if the below can be optimized using NORMAL or OFF and use separated syncing thread
          see also http://www.sqlite.org/pragma.html#pragma_synchronous
   */

  if (sqlite3_exec (attachment_db->db, "PRAGMA synchronous = NORMAL", NULL, NULL, &errmsg) != SQLITE_OK)
    {   
      if (error != NULL && *error != NULL)
        g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "Cannot set pragma synchronous: %s",
                   errmsg);
      sqlite3_free (errmsg);
      dupin_attachment_db_disconnect (attachment_db);
      return NULL;
    }

  query =
    "SELECT parent FROM DupinAttachmentDB LIMIT 1";

  if (sqlite3_exec (attachment_db->db, query, dupin_attachment_db_connect_cb, attachment_db, &errmsg) !=
      SQLITE_OK)
    {
      if (error != NULL && *error != NULL)
        g_set_error (error, dupin_error_quark (), DUPIN_ERROR_OPEN, "%s",
		   errmsg);
      sqlite3_free (errmsg);
      dupin_attachment_db_disconnect (attachment_db);
    }

  return attachment_db;
}