aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PS3/PS3Extras/TLSStorage.cpp
blob: a3b09d6d13930a8068506251ea7390a7e5016215 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "stdafx.h"



TLSStoragePS3* TLSStoragePS3::m_pInstance = nullptr;

BOOL TLSStoragePS3::m_activeList[sc_maxSlots];
__thread LPVOID TLSStoragePS3::m_values[sc_maxSlots];



TLSStoragePS3::TLSStoragePS3()
{
	for(int i=0;i<sc_maxSlots; i++)
	{
		m_activeList[i] = false;
		m_values[i] = nullptr;
	}
}

TLSStoragePS3* TLSStoragePS3::Instance()
{
	if ( m_pInstance == 0 )			// Is this the first time?
	{
		m_pInstance = new TLSStoragePS3;		// Create the singleton instance.
	}
	return m_pInstance;
}


int TLSStoragePS3::Alloc()
{
	for(int i=0; i<sc_maxSlots; i++) 
	{
		if(m_activeList[i] == false)
		{
			m_activeList[i] = true;
			m_values[i] = nullptr;
			return i;
		}
	}
	assert(0);		// we've ran out of slots
	return -1;
}

BOOL TLSStoragePS3::Free( DWORD _index )
{
	if(m_activeList[_index] == false)
		return false; // not been allocated

	m_activeList[_index] = false;
	m_values[_index] = nullptr;
	return true;
}

BOOL TLSStoragePS3::SetValue( DWORD _index, LPVOID _val )
{
	if(m_activeList[_index] == false)
		return false;
	m_values[_index] = _val;
	return true;
}

LPVOID TLSStoragePS3::GetValue( DWORD _index )
{
	if(m_activeList[_index] == false)
		return nullptr;
	return m_values[_index];
}