Exemplo n.º 1
0
static void create_key_once(void)
{
    pthread_key_create(&g_key, NULL);
}
Exemplo n.º 2
0
 Deleter()
 {
     pthread_key_create(&pkey_, &ThreadLocalSingleton::destructor);
 }
Exemplo n.º 3
0
static void
make_key()
{
    (void) pthread_key_create(&tlsKey, NULL);
}
Exemplo n.º 4
0
int main (int argc, char *argv[])
{
	int ret=0;
	void * rval;
	pthread_t child;
	int i,j;

	output_init();

	scenar_init();

	for (j=0; j<3; j++)
	{
		ret = pthread_key_create(&tld[j], destructor);
		if (ret != 0)  {  UNRESOLVED(ret, "Failed to create a TLD key");  }
	}

	for (i=0; i < NSCENAR; i++)
	{
		if (scenarii[i].detached == 0)
		{
			#if VERBOSE > 0
			output("-----\n");
			output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr);
			#endif

			for (j=0; j<4; j++)
				tab[j]=0;
			global=0;

			ret = pthread_create(&child, &scenarii[i].ta, threaded, NULL);
			switch (scenarii[i].result)
			{
				case 0: /* Operation was expected to succeed */
					if (ret != 0)  {  UNRESOLVED(ret, "Failed to create this thread");  }
					break;

				case 1: /* Operation was expected to fail */
					if (ret == 0)  {  UNRESOLVED(-1, "An error was expected but the thread creation succeeded");  }
					break;

				case 2: /* We did not know the expected result */
				default:
					#if VERBOSE > 0
					if (ret == 0)
						{ output("Thread has been created successfully for this scenario\n"); }
					else
						{ output("Thread creation failed with the error: %s\n", strerror(ret)); }
					#endif
			}
			if (ret == 0) /* The new thread is running */
			{
				ret = pthread_join(child, &rval);
				if (ret != 0)  {  UNRESOLVED(ret, "Unable to join a thread");  }

				if (rval != (NULL+1))
				{
					FAILED("pthread_join() did not retrieve the pthread_exit() param");
				}

				for (j=0; j<3; j++)
				{
					if ((tab[j] != j+1) || (tab[3] != 9))
					{
						output("dump:\ntab[0]=%i\ntab[1]=%i\ntab[2]=%i\ntab[3]=%i\n", tab[0], tab[1], tab[2], tab[3]);
						FAILED("The cleanup handlers were not called as expected");
					}
				}
			}
		}
	}

	for (j=0; j<3; j++)
	{
		ret = pthread_key_delete(tld[j]);
		if (ret != 0)  {  UNRESOLVED(ret, "Failed to delete a TLD key");  }
	}

	scenar_fini();
	#if VERBOSE > 0
	output("-----\n");
	output("All test data destroyed\n");
	output("Test PASSED\n");
	#endif

	PASSED;
}
Exemplo n.º 5
0
static void icalerrno_key_alloc(void) {
  pthread_key_create(&icalerrno_key, icalerrno_destroy);
}
Exemplo n.º 6
0
void
l_random_setup(void)
{
    pthread_key_create(&key, l_random_key_destructor);
}
Exemplo n.º 7
0
static void
ecpg_actual_connection_init(void)
{
	pthread_key_create(&actual_connection_key, NULL);
}
Exemplo n.º 8
0
static __inline void emutls_init(void) {
  if (pthread_key_create(&emutls_pthread_key, emutls_key_destructor) != 0)
    abort();
  emutls_key_created = true;
}
Exemplo n.º 9
0
			ThreadLocal(bool destroy = true)
			{
				pthread_key_create(&m_key,
				        destroy ? &ThreadLocal::Destroy : &ThreadLocal::Empty);
			}
Exemplo n.º 10
0
static void thread_init(void)
{
  pthread_key_create(&__ph_thread_key, destroy_thread);
  ck_epoch_init(&misc_epoch);
}
Exemplo n.º 11
0
/*
 * TaskLib init function
 */
STATUS
taskLibInit(void)
{
    OS_TCB *tcb;
    struct sched_param param;
    int policy;
    char name[12];

    /* Determine the min and max allowable priorities */
#ifdef PTHREAD_MIN_PRIORITY
    rr_min_priority = PTHREAD_MIN_PRIORITY;
#else
    rr_min_priority = sched_get_priority_min (SCHED_RR);
#endif
#ifdef PTHREAD_MAX_PRIORITY
    rr_max_priority = PTHREAD_MAX_PRIORITY;
#else
    rr_max_priority = sched_get_priority_max (SCHED_RR);
#endif

    /* Create a thread specific key to access TCB */
    pthread_key_create(&taskControlBlock, NULL);

    /* allocate a TCB for main thread */
    tcb = (OS_TCB *)malloc(sizeof(OS_TCB));
    if (tcb == NULL) {
	return ERROR;
    }
    snprintf(name, sizeof(name), "tUnix%d", (int)getpid());
    tcb->name = strdup(name);
#ifdef HAVE_PTHREAD_ATTR_SETSCHEDPOLICY
    pthread_getschedparam(pthread_self(), &policy, &param);
#else
    policy = 0;
    param.sched_priority = rr_min_priority;
#endif
    tcb->policy = policy;
    tcb->priority = priorityPosixToVx(param.sched_priority);
    tcb->options = 0;
    tcb->entry = NULL;			/* implicit main() */
    tcb->errorStatus = errno;
    /* Process and thread ids */
    tcb->pid = getpid();
    tcb->tid = pthread_self();
    /* The tcb list is initially empty */
    tcb->next = NULL;
    /* Mark the TCB */
    tcb->magic = TASK_MAGIC;

    /* Register the TCB pointer in the thread-specific key */
#ifdef DEBUG
    fprintf(stderr, "registering task specific value %lu %lu\n",
	(unsigned long)tcb, (unsigned long)pthread_self());
#endif
    if (pthread_setspecific(taskControlBlock, (void *)tcb) != 0) {
	errnoSet(errno);
	return ERROR;
    }

    /* Initialize the global task List */
    taskList = tcb;

    return OK;
}
Exemplo n.º 12
0
void initThreadLocal(JNIEnv* env) {
	pthread_key_create(&gTlsKey, destroyThreadLocal);
}
Exemplo n.º 13
0
void x_init()
{
	pthread_key_create(&g_except_key, NULL);
	pthread_key_create(&g_error_key, NULL);
}
Exemplo n.º 14
0
static void
_xc_init_errbuf(void)
{
    pthread_key_create(&errbuf_pkey, _xc_clean_errbuf);
}
Exemplo n.º 15
0
Arquivo: thread.c Projeto: jpeach/zfsd
// NOTE: glibc used uint as pthread_key_t.
void
tsd_create(uint_t * key, void (*exit)(void *))
{
    VERIFY0(pthread_key_create(key, exit));
}
Exemplo n.º 16
0
			ThreadLocal()
			{
				pthread_key_create(&m_key, &ThreadLocal::Destroy);
			}
Exemplo n.º 17
0
static void
np_init_error_key()
{
	pthread_key_create(&error_key, np_destroy_error);
}
Exemplo n.º 18
0
int
ldap_pvt_thread_key_create( ldap_pvt_thread_key_t *key )
{
    return pthread_key_create( key, NULL );
}
Exemplo n.º 19
0
static void init_errno(void)
{
	pthread_key_create(&errno_key, free);
}
Exemplo n.º 20
0
/**
 * Allocates a thread-specific variable.
 * @param key where to store the thread-specific variable handle
 * @param destr a destruction callback. It is called whenever a thread exits
 * and the thread-specific variable has a non-NULL value.
 * @return 0 on success, a system error code otherwise. This function can
 * actually fail because there is a fixed limit on the number of
 * thread-specific variable in a process on most systems.
 */
int vlc_threadvar_create (vlc_threadvar_t *key, void (*destr) (void *))
{
    return pthread_key_create (key, destr);
}
Exemplo n.º 21
0
/* Create Key */
static void fr_strerror_make_key(void)
{
	pthread_key_create(&fr_strerror_key, NULL);
}
Exemplo n.º 22
0
static void g_uselocale_key_init() {
  pthread_key_create(&g_uselocale_key, NULL);
}
Exemplo n.º 23
0
static void
thread_init(void)
{
	pthread_key_create(&key, free);
}
Exemplo n.º 24
0
//static int init_complete;
void InitSyslog( int ignore_options )
{
#ifndef __STATIC_GLOBALS__
	if( syslog_local )
	{
#ifndef __NO_OPTIONS__
		if( !ignore_options )
			LoadOptions();
#endif
		return;
	}
	SimpleRegisterAndCreateGlobal( syslog_local );
 	
	if( !(*syslog_local).flags.bInitialized )
#endif
	{
		//logtype = SYSLOG_FILE;
		//(*syslog_local).file = stderr;
#if defined( WIN32 )
		(*syslog_local).next_lprintf_tls = TlsAlloc();
#elif defined( __LINUX__ )
		pthread_key_create( &((*syslog_local).next_lprintf_tls), NULL );
#endif
		(*syslog_local).flags.bLogThreadID = 1;
		hSock = INVALID_SOCKET;
		(*syslog_local).hSyslogdSock = INVALID_SOCKET;
		bCPUTickWorks = 1;
		nLogLevel = LOG_NOISE-1; // default log EVERYTHING
#ifdef __ANDROID__
		{
			logtype = SYSLOG_SYSTEM;
			nLogLevel = LOG_NOISE + 1000; // default log EVERYTHING
			(*syslog_local).flags.bLogSourceFile = 1;
			(*syslog_local).flags.bUseDeltaTime = 1;
			(*syslog_local).flags.bLogCPUTime = 1;
			(*syslog_local).flags.bLogThreadID = 1;
			(*syslog_local).flags.bLogProgram = 0;
			SystemLogTime( SYSLOG_TIME_HIGH );
		}
#else
#  if defined( _DEBUG ) || 1
		{
#    ifdef __LINUX__
			logtype = SYSLOG_SOCKET_SYSLOGD;
			(*syslog_local).flags.bLogProgram = 1;
			
#    else
			/* using SYSLOG_AUTO_FILE option does not require this to be open.
			* it is opened on demand.
			*/

			logtype = SYSLOG_AUTO_FILE;
			(*syslog_local).flags.bLogOpenBackup = 1;
			(*syslog_local).flags.bUseDeltaTime = 1;
			(*syslog_local).flags.bLogCPUTime = 1;
			(*syslog_local).flags.bUseDeltaTime = 1;
			(*syslog_local).flags.bLogCPUTime = 1;
			(*syslog_local).flags.bLogProgram = 0;
			SystemLogTime( SYSLOG_TIME_HIGH );
#    endif
			nLogLevel = LOG_NOISE + 1000; // default log EVERYTHING
			(*syslog_local).flags.bLogOpenAppend = 0;
			(*syslog_local).flags.bLogSourceFile = 1;
			(*syslog_local).flags.bLogThreadID = 1;
			//SetDefaultName( NULL, NULL, NULL );
			//lprintf( WIDE("Syslog Initializing, debug mode, startup programname.log\n") );
		}
#  else
		// stderr?
		logtype = SYSLOG_NONE;
		(*syslog_local).file = NULL;
#  endif
#endif

		(*syslog_local).flags.bInitialized = 1;
	}
#ifndef __NO_OPTIONS__
	if( !ignore_options )
		LoadOptions();
#else
	(*syslog_local).flags.bOptionsLoaded = 1;
#  ifndef __ANDROID__
	SetDefaultName( NULL, NULL, NULL );
#  endif
#endif
}
Exemplo n.º 25
0
/* Thread context management */
static void init_keys( void )
{
    pthread_key_create( &thread_key, NULL );
}                               /* init_keys */
Exemplo n.º 26
0
int start_async(struct async *async)
{
	int need_in, need_out;
	int fdin[2], fdout[2];
	int proc_in, proc_out;

	need_in = async->in < 0;
	if (need_in) {
		if (pipe(fdin) < 0) {
			if (async->out > 0)
				close(async->out);
			return error("cannot create pipe: %s", strerror(errno));
		}
		async->in = fdin[1];
	}

	need_out = async->out < 0;
	if (need_out) {
		if (pipe(fdout) < 0) {
			if (need_in)
				close_pair(fdin);
			else if (async->in)
				close(async->in);
			return error("cannot create pipe: %s", strerror(errno));
		}
		async->out = fdout[0];
	}

	if (need_in)
		proc_in = fdin[0];
	else if (async->in)
		proc_in = async->in;
	else
		proc_in = -1;

	if (need_out)
		proc_out = fdout[1];
	else if (async->out)
		proc_out = async->out;
	else
		proc_out = -1;

#ifdef NO_PTHREADS
	/* Flush stdio before fork() to avoid cloning buffers */
	fflush(NULL);

	async->pid = fork();
	if (async->pid < 0) {
		error("fork (async) failed: %s", strerror(errno));
		goto error;
	}
	if (!async->pid) {
		if (need_in)
			close(fdin[1]);
		if (need_out)
			close(fdout[0]);
		git_atexit_clear();
		process_is_async = 1;
		exit(!!async->proc(proc_in, proc_out, async->data));
	}

	mark_child_for_cleanup(async->pid);

	if (need_in)
		close(fdin[0]);
	else if (async->in)
		close(async->in);

	if (need_out)
		close(fdout[1]);
	else if (async->out)
		close(async->out);
#else
	if (!main_thread_set) {
		/*
		 * We assume that the first time that start_async is called
		 * it is from the main thread.
		 */
		main_thread_set = 1;
		main_thread = pthread_self();
		pthread_key_create(&async_key, NULL);
		pthread_key_create(&async_die_counter, NULL);
		set_die_routine(die_async);
		set_die_is_recursing_routine(async_die_is_recursing);
	}

	if (proc_in >= 0)
		set_cloexec(proc_in);
	if (proc_out >= 0)
		set_cloexec(proc_out);
	async->proc_in = proc_in;
	async->proc_out = proc_out;
	{
		int err = pthread_create(&async->tid, NULL, run_thread, async);
		if (err) {
			error("cannot create thread: %s", strerror(err));
			goto error;
		}
	}
#endif
	return 0;

error:
	if (need_in)
		close_pair(fdin);
	else if (async->in)
		close(async->in);

	if (need_out)
		close_pair(fdout);
	else if (async->out)
		close(async->out);
	return -1;
}
Exemplo n.º 27
0
static void
initialize_key (void)
{
    pthread_key_create (&sfi_key, free);
}
Exemplo n.º 28
0
Arquivo: mem.c Projeto: kingdwd/amino
static void local_region_make_key(void)
{
    pthread_key_create( &local_region_key, local_region_destroy );
}
Exemplo n.º 29
0
static void createThreadLocalKey() {
    (void)pthread_key_create( &static_key, NULL);
}
Exemplo n.º 30
0
static void mqueue_once_init(void)
{
	pthread_key_create(&mqueue_key, mqueue_destructor);
}