@@ -169,14 +169,18 @@ private function getMaps(): array
169169 $ this ->mapInputNameToFactory
170170 ) {
171171 $ lock = $ this ->lockFactory ->createLock ('buildmap_ ' .$ this ->namespace , 5 );
172- if ($ lock ->isAcquired ()) {
172+ if (! $ lock ->acquire ()) {
173173 // Lock is being held right now. Generation is happening.
174174 // Let's wait and fetch the result from the cache.
175175 $ lock ->acquire (true );
176176 $ lock ->release ();
177177 return $ this ->getMaps ();
178178 }
179- $ this ->lockAndBuildMap ($ lock );
179+ try {
180+ $ this ->buildMap ();
181+ } finally {
182+ $ lock ->release ();
183+ }
180184 // This is a very short lived cache. Useful to avoid overloading a server in case of heavy load.
181185 // Defaults to 2 seconds.
182186 $ this ->cache ->set ($ keyClassCache , $ this ->mapClassToTypeArray , $ this ->globTtl );
@@ -222,15 +226,19 @@ private function getMapClassToExtendTypeArray(): array
222226 $ this ->mapClassToExtendTypeArray = $ this ->cache ->get ($ keyExtendClassCache );
223227 if ($ this ->mapClassToExtendTypeArray === null ) {
224228 $ lock = $ this ->lockFactory ->createLock ('buildmapclassextend_ ' .$ this ->namespace , 5 );
225- if ($ lock ->isAcquired ()) {
229+ if (! $ lock ->acquire ()) {
226230 // Lock is being held right now. Generation is happening.
227231 // Let's wait and fetch the result from the cache.
228232 $ lock ->acquire (true );
229233 $ lock ->release ();
230234 return $ this ->getMapClassToExtendTypeArray ();
231235 }
232-
233- $ this ->buildMapClassToExtendTypeArray ($ lock );
236+ $ lock ->acquire (true );
237+ try {
238+ $ this ->buildMapClassToExtendTypeArray ($ lock );
239+ } finally {
240+ $ lock ->release ();
241+ }
234242 // This is a very short lived cache. Useful to avoid overloading a server in case of heavy load.
235243 // Defaults to 2 seconds.
236244 $ this ->cache ->set ($ keyExtendClassCache , $ this ->mapClassToExtendTypeArray , $ this ->globTtl );
@@ -248,15 +256,19 @@ private function getMapNameToExtendType(RecursiveTypeMapperInterface $recursiveT
248256 $ this ->mapNameToExtendType = $ this ->cache ->get ($ keyExtendNameCache );
249257 if ($ this ->mapNameToExtendType === null ) {
250258 $ lock = $ this ->lockFactory ->createLock ('buildmapnameextend_ ' .$ this ->namespace , 5 );
251- if ($ lock ->isAcquired ()) {
259+ if (! $ lock ->acquire ()) {
252260 // Lock is being held right now. Generation is happening.
253261 // Let's wait and fetch the result from the cache.
254262 $ lock ->acquire (true );
255263 $ lock ->release ();
256264 return $ this ->getMapNameToExtendType ($ recursiveTypeMapper );
257265 }
258-
259- $ this ->buildMapNameToExtendTypeArray ($ lock , $ recursiveTypeMapper );
266+ $ lock ->acquire (true );
267+ try {
268+ $ this ->buildMapNameToExtendTypeArray ($ recursiveTypeMapper );
269+ } finally {
270+ $ lock ->release ();
271+ }
260272 // This is a very short lived cache. Useful to avoid overloading a server in case of heavy load.
261273 // Defaults to 2 seconds.
262274 $ this ->cache ->set ($ keyExtendNameCache , $ this ->mapNameToExtendType , $ this ->globTtl );
@@ -292,16 +304,6 @@ private function getClassList(): array
292304 return $ this ->classes ;
293305 }
294306
295- private function lockAndBuildMap (Lock $ lock ): void
296- {
297- $ lock ->acquire (true );
298- try {
299- $ this ->buildMap ();
300- } finally {
301- $ lock ->release ();
302- }
303- }
304-
305307 private function buildMap (): void
306308 {
307309 $ this ->mapClassToTypeArray = [];
@@ -363,21 +365,16 @@ private function buildMapClassToExtendTypeArray(Lock $lock): void
363365 }
364366 }
365367
366- private function buildMapNameToExtendTypeArray (Lock $ lock , RecursiveTypeMapperInterface $ recursiveTypeMapper ): void
368+ private function buildMapNameToExtendTypeArray (RecursiveTypeMapperInterface $ recursiveTypeMapper ): void
367369 {
368- $ lock ->acquire (true );
369- try {
370- $ this ->mapNameToExtendType = [];
371- $ classes = $ this ->getClassList ();
372- foreach ($ classes as $ className => $ refClass ) {
373- $ extendType = $ this ->annotationReader ->getExtendTypeAnnotation ($ refClass );
370+ $ this ->mapNameToExtendType = [];
371+ $ classes = $ this ->getClassList ();
372+ foreach ($ classes as $ className => $ refClass ) {
373+ $ extendType = $ this ->annotationReader ->getExtendTypeAnnotation ($ refClass );
374374
375- if ($ extendType !== null ) {
376- $ this ->storeExtendTypeMapperByNameInCache ($ className , $ extendType , $ refClass ->getFileName (), $ recursiveTypeMapper );
377- }
375+ if ($ extendType !== null ) {
376+ $ this ->storeExtendTypeMapperByNameInCache ($ className , $ extendType , $ refClass ->getFileName (), $ recursiveTypeMapper );
378377 }
379- } finally {
380- $ lock ->release ();
381378 }
382379 }
383380
0 commit comments