Ejemplo n.º 1
0
static void* thread_startup( void *idx)
{
	/* first set the thread id (index) */
	set_tsd( thread_id, (int)(long)idx );

	if (pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, NULL) ) {
		LM_ERR("failed to enable CANCEL\n");
		goto failed;
	}
	if (pthread_setcanceltype( PTHREAD_CANCEL_ASYNCHRONOUS, NULL) ) {
		LM_ERR("failed to set the CANCEL state\n");
		goto failed;
	}

	(void)tt[(long)idx].thread_routine( tt[(long)idx].thread_arg );

	/* if we get here, it means the thread failed to init or the thread
	 * ended - which should not happen */
failed:
	/* mark our thread as done */
	tt[(long)idx].id = 0;
	/* trigger shutdown */
	kill(getpid(), SIGTERM);
	return NULL;
}
Ejemplo n.º 2
0
PRIVATE void MPII_Local_attrib_init ()
{
    DynamicId *did = mymalloc (1, DynamicId);
    set_tsd (MPII_attrib_did_key, did);
    /*
    DID_Init (MPII_Attrib, ATTRIB_BLOCK_SIZE, MPII_NUM_BUILTIN_ATTRIBS);

    DID (MPII_Attrib, MPII_TOPOLOGY_ATTRIB).copy = MPI_NULL_FN;
    DID (MPII_Attrib, MPII_TOPOLOGY_ATTRIB).delete = MPI_NULL_FN;
    DID (MPII_Attrib, MPII_TOPOLOGY_ATTRIB).extra_state = NULL;
    DID (MPII_Attrib, MPII_TOPOLOGY_ATTRIB).nref =
        DID (MPII_Attrib, MPII_TOPOLOGY_ATTRIB).freed = 0;
    */
}
Ejemplo n.º 3
0
/* You can *only* call this when either:
 *    - you have called MPII_Get_global_init() at least once
 *    - there is only one thread that could possibly call it at once
 */
void *MPII_Get_global (Key **key, int size, void *init)
{
  void *ptr;
  
  if (*key == (Key *) 0)
  {
    int mpi_init;
    MPI_Initialized (&mpi_init);
    if (mpi_init)
    {
      if (!initialized)
      {
        new_mutex (mutex);
        initialized++;
      }
      lock (mutex);
    }
    if (*key == (Key *) 0) /* still */
    {
      *key = (Key *) malloc (sizeof (Key));
      new_tsd (**key);
    }
    if (mpi_init)
      unlock (mutex);
  }

  ptr = get_tsd (**key);
  if (ptr == (void *) 0)
  {
    ptr = (void *) malloc (size);
    if (ptr == (void *) 0)
    {
      perror ("g2tsd: MPII_Get_global: malloc failed");
      exit (1);
    }
    memcpy (ptr, init, size);
    set_tsd (**key, ptr);
  }
  
  return ptr;
}
Ejemplo n.º 4
0
int init_main_thread(char *name)
{
	/* alloca a new entry for it in the thread table - it will have
	 * IDX 0 all the time */
	tt = (struct thread_info*)shm_malloc( sizeof(struct thread_info) );
	if (tt==NULL) {
		LM_ERR("no more shared memory\n");
		return -1;
	}
	memset( tt, 0, sizeof(struct thread_info));

	/* fill in the thread info */
	strncpy( tt[0].name, name, MAX_TT_NAME-1);
	tt[0].id = pthread_self();

	/* set the thread id (index) */
	set_tsd( thread_id, (int)(long)0 );

	threads_counter ++;

	return 0;
}
Ejemplo n.º 5
0
PRIVATE void MPII_Set_initialized ()
{
  MPII_Initialized_init ();
  set_tsd (MPII_init_key, (void *) 1);
}