Beispiel #1
0
/*	===== tls_exiting_procs ========================================================
	PUBLIC. 
	================================================================================	*/
status_t tls_exiting_procs () 
	{
	thread_id id = find_thread (NULL) ;
	_tls_thread_entry_t* e = NULL ;
	status_t status ;

	//	Search for the thread entry. 
	if ((status = tls_entries_mutex_p ()) == B_NO_ERROR)
		{
		status = tls_get_entry (id, &e) ;
		tls_entries_mutex_v () ;
		}

	//	If the thread has no entry, then we should not call its exit procs.
	if (status == B_NAME_NOT_FOUND) return B_NO_ERROR ;

	//	Other errors are... errors.
	if (status != B_NO_ERROR) return status ;

	//	Free the entry structure (avoid monitoring thread to have to do this at
	//	a bad time, in a bad thread). The entry deletion function will automatically 
	//	call exiting procs.
	if ((status = tls_entries_mutex_p ()) == B_NO_ERROR)
		{
		status = tls_delete_entry (e) ;
		tls_entries_mutex_v () ;
		}

	//	Finish.
	return status ;
	}
Beispiel #2
0
/*	===== tls_delete_entry_thread_id ===============================================
	PRIVATE. 
	================================================================================	*/
status_t tls_delete_entry_thread_id (thread_id id)
	{
	_tls_thread_entry_t* pEntry = NULL ;
	status_t status ;

	if ((status = tls_get_entry (id, &pEntry)) != B_NO_ERROR) return status ;
	return tls_delete_entry (pEntry) ;
	}
Beispiel #3
0
/*	===== tls_get ==================================================================
	PUBLIC. Get a TLS data at an index.
	================================================================================	*/
status_t tls_get (int index, tls_data_t* pData) 
	{
	int indexOk ;
	_tls_thread_entry_t* e = NULL ;
	thread_id id ;
	status_t status ;

	//	Check parameter.
	assert (pData != NULL) ;
	if (pData == NULL) return B_BAD_VALUE ;
	*pData = TLS_INVALID_DATA ;
	assert (index >= 0) ;
	if (index < 0) return B_BAD_VALUE ;

	//	Check index value (verify index has been allocated).
	if ((status = tls_index_mutex_p ()) == B_NO_ERROR)
		{
		indexOk = tls_check_index (index) ;
		tls_index_mutex_v () ;
		}
	else
		return status ;
	if (!indexOk) return B_BAD_INDEX ;

	//	Get the entry for the thread.
	id = find_thread (NULL) ;
	if ((status = tls_entries_mutex_p ()) == B_NO_ERROR)
		{
		if ((status = tls_get_entry (id, &e)) != B_NO_ERROR)
			status = tls_create_entry (id, &e) ;
		tls_entries_mutex_v () ;
		}
	
	//	Get it using the get_inproc function.
	if (status == B_NO_ERROR)
		return tls_get_inproc (index, pData, e) ;
	else
		return status ;
	}
Beispiel #4
0
/*	===== tls_entering_procs =======================================================
	PUBLIC. 
	================================================================================	*/
status_t tls_entering_procs ()
	{
	thread_id id = find_thread (NULL) ;
	_tls_thread_entry_t* e = NULL ;
	status_t status ;
	bool newlyCreated = false ;

	//	Search for the thread entry.
	//	If not founded, create it and dont call entry procs because tls_create_entry
	//	automatically call them.
	//	If founded, call entry procs.
	if ((status = tls_entries_mutex_p ()) == B_NO_ERROR)
		{
		if ((status = tls_get_entry (id, &e)) != B_NO_ERROR)
			status = tls_create_entry (id, &e) ;
		else
			tls_call_entry_exit (id, PROC_ENTRY, e) ;
		tls_entries_mutex_v () ;
		}
	if (status != B_NO_ERROR) return status ;
	
	//	Finish
	return B_NO_ERROR ;
	}