Пример #1
0
/* init/reset function, call from stream_init() */
static void init_fragment_hash( void ) {
    if( fragment_hash != NULL ) {
	g_hash_table_destroy( fragment_hash );
	fragment_hash = NULL;
    }

    if( fragment_vals != NULL ) {
	g_mem_chunk_destroy( fragment_vals );
	fragment_vals = NULL;
    }

    if( fragment_keys != NULL ) {
	g_mem_chunk_destroy( fragment_keys );
	fragment_keys = NULL;
    }

    fragment_keys = g_mem_chunk_create(fragment_key_t,
				       MEMCHUNK_FRAGMENT_COUNT,
				       G_ALLOC_ONLY);
    
    fragment_vals = g_mem_chunk_create(stream_pdu_fragment_t,
				       MEMCHUNK_FRAGMENT_COUNT,
				       G_ALLOC_ONLY);

    fragment_hash = g_hash_table_new(fragment_hash_func,
				     fragment_compare_func);
}
Пример #2
0
/* init/reset function, call from stream_init() */
static void init_stream_hash( void ) {
    if( stream_hash != NULL ) {
	g_hash_table_destroy( stream_hash );
	stream_hash = NULL;
    }

    if( stream_keys != NULL ) {
	g_mem_chunk_destroy( stream_keys );
	stream_keys = NULL;
    }

    if( streams != NULL ) {
	g_mem_chunk_destroy( streams );
	streams = NULL;
    }

    streams = g_mem_chunk_create(stream_t,
				 MEMCHUNK_STREAM_COUNT,
				 G_ALLOC_ONLY);

    stream_keys = g_mem_chunk_create(stream_key_t,
				     MEMCHUNK_STREAM_COUNT,
				     G_ALLOC_ONLY);

    stream_hash = g_hash_table_new(stream_hash_func,
				   stream_compare_func);
}
Пример #3
0
static AranSolver3d *_solver3d_alloc ()
{
  AranSolver3d *solver;

  if (!aran_solver3d_mem_chunk)
    {
      aran_solver3d_mem_chunk = g_mem_chunk_create (AranSolver3d,
						    ARAN_SOLVER3D_PREALLOC,
						    G_ALLOC_ONLY);
    }

  aran_solver3d_instances_count ++;

  solver = g_chunk_new (AranSolver3d, aran_solver3d_mem_chunk);

  solver->devel = NULL;
  solver->zero = NULL;

  solver->p2p = NULL;

  solver->p2m = NULL;
  solver->m2m = NULL;
  solver->m2l = NULL;
  solver->l2l = NULL;
  solver->l2p = NULL;

  return solver;
}
Пример #4
0
DictionaryWord *
dictionary_add_word (const char      *word,
                     Phoneme         *decomp)
{
    DictionaryWord *dword;
    char *query_word;

    g_return_val_if_fail (word != NULL, NULL);

    g_static_rec_mutex_lock (&dict_mutex);

    if (dictionary == NULL) {
        dictionary = g_hash_table_new (g_str_hash, g_str_equal);
    }

    query_word = g_ascii_strdown (word, -1);
    g_strstrip (query_word);
    dword = g_hash_table_lookup (dictionary, query_word);

    if (dword == NULL || (decomp != NULL && dword->decomp == NULL)) {

        gboolean add_word = FALSE;
        const char *w;

        if (dword == NULL) {

            if (dict_chunks == NULL) {
                dict_chunks = g_mem_chunk_create (DictionaryWord,
                                                  1000,
                                                  G_ALLOC_ONLY);
            }

            dword = g_chunk_new0 (DictionaryWord, dict_chunks);

            dword->word = query_word;

            /* pre-compute a hash key */
            dword->hash = 0xdeadbeef;
            for (w = word; *w; ++w)
                dword->hash = 17 * dword->hash + (long)*w;

            add_word = TRUE;
        } else {
            g_free (query_word);
        }
    
        dword->decomp = decomp;
        if (decomp)
            rhyme_index_word (dword);

        if (add_word)
            g_hash_table_insert (dictionary, dword->word, dword);
    }

    g_static_rec_mutex_unlock (&dict_mutex);

    return dword;
}
Пример #5
0
Token *
token_lookup (const char *raw)
{
    Token *tok;

    g_static_mutex_lock (&token_mutex);

    if (token_table == NULL)
        token_table = g_hash_table_new (g_str_hash, g_str_equal);

    tok = g_hash_table_lookup (token_table, raw);
    if (tok == NULL) {

        static GMemChunk *token_chunks = NULL;

        if (token_chunks == NULL)
            token_chunks = g_mem_chunk_create (Token, 1000, G_ALLOC_ONLY);


        tok = g_chunk_new0 (Token, token_chunks);
        tok->raw = g_strdup (raw);
        tok->syllables = -1;
        tok->word_count = -1;

        if (! strcmp (raw, "*break*")) {
            tok->is_break = TRUE;
            tok->syllables = 0;
        } else if (! strncmp (raw, "*punct*", 7)) {
            tok->word = g_strdup (raw+8);
            tok->is_punctuation = TRUE;
            tok->left_glue = TRUE; /* FIXME */
            tok->syllables = 0;
            tok->word_count = 0;
        } else if (! strcmp (raw, "*wildcard*")) {
            tok->word = g_strdup (raw);
            tok->is_wildcard = TRUE;
        } else {
            DictionaryWord *dword;
            tok->word = g_strdup (raw);
            dword = dictionary_get_word (tok->word);
            if (dword != NULL) {
                tok->dict = dword;
                tok->syllables = syllable_count_from_decomp (dword->decomp);
                tok->meter = meter_from_phoneme_decomp (dword->decomp);
            } else {
                tok->syllables = syllable_count_approximate (tok->word);
            }
            tok->word_count = str_word_count (tok->word);
        }

        g_hash_table_insert (token_table, tok->raw, tok);
    }

    g_static_mutex_unlock (&token_mutex);

    return tok;
}
Пример #6
0
static gpointer
gsk_ftp_message_alloc ()
{
  gpointer rv;
  G_LOCK (ftp_message_chunk)
  if (ftp_msg_chunk == NULL)
    ftp_msg_chunk = g_mem_chunk_create (_GskFtpMessage, 16, G_ALLOC_AND_FREE);
  rv = g_mem_chunk_alloc (ftp_msg_chunk);
  G_UNLOCK (ftp_message_chunk);
  return rv;
}
Пример #7
0
static void stream_init_pdu_data(void)
{
    if( pdus != NULL ) {
	g_mem_chunk_destroy( pdus );
	pdus = NULL;
    }

    pdus = g_mem_chunk_create(stream_pdu_t,
			      MEMCHUNK_PDU_COUNT,
			      G_ALLOC_ONLY);
    pdu_counter = 0;
}
Пример #8
0
Файл: .c Проект: pigay/vsg
static VsgQuaternion@t@ *_quaternion@t@_alloc ()
{
  if (!vsg_quaternion@t@_mem_chunk)
    {
      vsg_quaternion@t@_mem_chunk = g_mem_chunk_create (VsgQuaternion@t@,
                                                        VSG_QUATERNION@T@_PREALLOC,
                                                        G_ALLOC_ONLY);
    }

  vsg_quaternion@t@_instances_count ++;

  return g_chunk_new (VsgQuaternion@t@, vsg_quaternion@t@_mem_chunk);
}
Пример #9
0
static VsgMatrix3@t@ *_matrix3@t@_alloc ()
{
  if (!vsg_matrix3@t@_mem_chunk)
    {
      vsg_matrix3@t@_mem_chunk = g_mem_chunk_create (VsgMatrix3@t@,
                                                        VSG_MATRIX3@T@_PREALLOC,
                                                        G_ALLOC_ONLY);
    }

  vsg_matrix3@t@_instances_count ++;

  return g_chunk_new (VsgMatrix3@t@, vsg_matrix3@t@_mem_chunk);
}
Пример #10
0
static VsgVector3@t@ *_vector3@t@_alloc ()
{
  if (!vsg_vector3@t@_mem_chunk)
    {
      vsg_vector3@t@_mem_chunk = g_mem_chunk_create (VsgVector3@t@,
                                                     VSG_VECTOR3@T@_PREALLOC,
                                                     G_ALLOC_ONLY);
    }

  vsg_vector3@t@_instances_count ++;

  return g_chunk_new (VsgVector3@t@, vsg_vector3@t@_mem_chunk);
}
Пример #11
0
static RhymeTreeNode *
node_new (PhonemeCode code)
{
    RhymeTreeNode *node;
  
    if (rhyme_node_chunks == NULL) {
        rhyme_node_chunks = g_mem_chunk_create (RhymeTreeNode,
                                                1000,
                                                G_ALLOC_ONLY);
    }
    node = g_chunk_new0 (RhymeTreeNode, rhyme_node_chunks);
    node->code = code;
    return node;
}
Пример #12
0
/* Make a new hash table.  If one already exists, free it and
   reinitialize it to be empty.  Note that a null pointer for a bucket
   means an empty bucket, we'll initialize the bucket only if we have
   something to put in it.
 */
void hash_create()
{
        if(!entry_pool)
                entry_pool = g_mem_chunk_create(HashEntry, 1024, G_ALLOC_ONLY);
        g_assert(entry_pool);
        if(hash_table) {
                hash_destroy();
        }
        hash_table = g_new0(HashBucket, hash_size);
#if GATHER_HASH_STATISTICS
        hash_entries = 0;
        hash_collisions = 0;
#endif
        return;
}
/* HOLDS: main_loop_lock */
static void 
g_main_add_poll_unlocked (gint     priority,
			  GPollFD *fd)
{
  GPollRec *lastrec, *pollrec, *newrec;

  if (!poll_chunk)
    poll_chunk = g_mem_chunk_create (GPollRec, 32, G_ALLOC_ONLY);

  if (poll_free_list)
    {
      newrec = poll_free_list;
      poll_free_list = newrec->next;
    }
  else
    newrec = g_chunk_new (GPollRec, poll_chunk);

  /* This file descriptor may be checked before we ever poll */
  fd->revents = 0;
  newrec->fd = fd;
  newrec->priority = priority;

  lastrec = NULL;
  pollrec = poll_records;
  while (pollrec && priority >= pollrec->priority)
    {
      lastrec = pollrec;
      pollrec = pollrec->next;
    }
  
  if (lastrec)
    lastrec->next = newrec;
  else
    poll_records = newrec;

  newrec->next = pollrec;

  n_poll_records++;

#ifdef G_THREADS_ENABLED
  poll_changed = TRUE;

  /* Now wake up the main loop if it is waiting in the poll() */
  g_main_wakeup ();
#endif
}