OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkTLS.h" | 8 #include "SkTLS.h" |
9 | 9 |
10 // enable to help debug TLS storage | 10 // enable to help debug TLS storage |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 | 49 |
50 SkTLSRec* rec = (SkTLSRec*)ptr; | 50 SkTLSRec* rec = (SkTLSRec*)ptr; |
51 do { | 51 do { |
52 SkTLSRec* next = rec->fNext; | 52 SkTLSRec* next = rec->fNext; |
53 delete rec; | 53 delete rec; |
54 rec = next; | 54 rec = next; |
55 } while (rec); | 55 } while (rec); |
56 } | 56 } |
57 | 57 |
58 void* SkTLS::Get(CreateProc createProc, DeleteProc deleteProc) { | 58 void* SkTLS::Get(CreateProc createProc, DeleteProc deleteProc) { |
59 if (NULL == createProc) { | 59 if (nullptr == createProc) { |
60 return NULL; | 60 return nullptr; |
61 } | 61 } |
62 | 62 |
63 void* ptr = SkTLS::PlatformGetSpecific(true); | 63 void* ptr = SkTLS::PlatformGetSpecific(true); |
64 | 64 |
65 if (ptr) { | 65 if (ptr) { |
66 const SkTLSRec* rec = (const SkTLSRec*)ptr; | 66 const SkTLSRec* rec = (const SkTLSRec*)ptr; |
67 do { | 67 do { |
68 if (rec->fCreateProc == createProc) { | 68 if (rec->fCreateProc == createProc) { |
69 SkASSERT(rec->fDeleteProc == deleteProc); | 69 SkASSERT(rec->fDeleteProc == deleteProc); |
70 return rec->fData; | 70 return rec->fData; |
71 } | 71 } |
72 } while ((rec = rec->fNext) != NULL); | 72 } while ((rec = rec->fNext) != nullptr); |
73 // not found, so create a new one | 73 // not found, so create a new one |
74 } | 74 } |
75 | 75 |
76 // add a new head of our change | 76 // add a new head of our change |
77 SkTLSRec* rec = new SkTLSRec; | 77 SkTLSRec* rec = new SkTLSRec; |
78 rec->fNext = (SkTLSRec*)ptr; | 78 rec->fNext = (SkTLSRec*)ptr; |
79 | 79 |
80 SkTLS::PlatformSetSpecific(rec); | 80 SkTLS::PlatformSetSpecific(rec); |
81 | 81 |
82 rec->fData = createProc(); | 82 rec->fData = createProc(); |
83 rec->fCreateProc = createProc; | 83 rec->fCreateProc = createProc; |
84 rec->fDeleteProc = deleteProc; | 84 rec->fDeleteProc = deleteProc; |
85 return rec->fData; | 85 return rec->fData; |
86 } | 86 } |
87 | 87 |
88 void* SkTLS::Find(CreateProc createProc) { | 88 void* SkTLS::Find(CreateProc createProc) { |
89 if (NULL == createProc) { | 89 if (nullptr == createProc) { |
90 return NULL; | 90 return nullptr; |
91 } | 91 } |
92 | 92 |
93 void* ptr = SkTLS::PlatformGetSpecific(false); | 93 void* ptr = SkTLS::PlatformGetSpecific(false); |
94 | 94 |
95 if (ptr) { | 95 if (ptr) { |
96 const SkTLSRec* rec = (const SkTLSRec*)ptr; | 96 const SkTLSRec* rec = (const SkTLSRec*)ptr; |
97 do { | 97 do { |
98 if (rec->fCreateProc == createProc) { | 98 if (rec->fCreateProc == createProc) { |
99 return rec->fData; | 99 return rec->fData; |
100 } | 100 } |
101 } while ((rec = rec->fNext) != NULL); | 101 } while ((rec = rec->fNext) != nullptr); |
102 } | 102 } |
103 return NULL; | 103 return nullptr; |
104 } | 104 } |
105 | 105 |
106 void SkTLS::Delete(CreateProc createProc) { | 106 void SkTLS::Delete(CreateProc createProc) { |
107 if (NULL == createProc) { | 107 if (nullptr == createProc) { |
108 return; | 108 return; |
109 } | 109 } |
110 | 110 |
111 void* ptr = SkTLS::PlatformGetSpecific(false); | 111 void* ptr = SkTLS::PlatformGetSpecific(false); |
112 | 112 |
113 SkTLSRec* curr = (SkTLSRec*)ptr; | 113 SkTLSRec* curr = (SkTLSRec*)ptr; |
114 SkTLSRec* prev = NULL; | 114 SkTLSRec* prev = nullptr; |
115 while (curr) { | 115 while (curr) { |
116 SkTLSRec* next = curr->fNext; | 116 SkTLSRec* next = curr->fNext; |
117 if (curr->fCreateProc == createProc) { | 117 if (curr->fCreateProc == createProc) { |
118 if (prev) { | 118 if (prev) { |
119 prev->fNext = next; | 119 prev->fNext = next; |
120 } else { | 120 } else { |
121 // we have a new head of our chain | 121 // we have a new head of our chain |
122 SkTLS::PlatformSetSpecific(next); | 122 SkTLS::PlatformSetSpecific(next); |
123 } | 123 } |
124 delete curr; | 124 delete curr; |
125 break; | 125 break; |
126 } | 126 } |
127 prev = curr; | 127 prev = curr; |
128 curr = next; | 128 curr = next; |
129 } | 129 } |
130 } | 130 } |
OLD | NEW |