@@ -353,6 +353,31 @@ default void writeUnlock(long stamp) {
353353 }
354354 }
355355
356+ /**
357+ * Execute a function to get some result under {@link #readLock()} block.
358+ *
359+ * @param first the first argument for the function.
360+ * @param second the second argument for the function.
361+ * @param function the function.
362+ * @param <A> the first argument's type.
363+ * @param <T> the second argument's type.
364+ * @param <R> the result's type.
365+ * @return the result from the function.
366+ * @since 9.9.0
367+ */
368+ default <A , T , R > @ Nullable R getInReadLock (
369+ @ NotNull A first ,
370+ @ NotNull T second ,
371+ @ NotNull NotNullNullableTripleFunction <ConcurrentArray <E >, A , T , R > function
372+ ) {
373+ var stamp = readLock ();
374+ try {
375+ return function .apply (this , first , second );
376+ } finally {
377+ readUnlock (stamp );
378+ }
379+ }
380+
356381 /**
357382 * Execute a function to get some result under {@link #writeLock()} block.
358383 *
@@ -391,6 +416,31 @@ default void writeUnlock(long stamp) {
391416 }
392417 }
393418
419+ /**
420+ * Execute a function to get some result under {@link #writeLock()} block.
421+ *
422+ * @param first the first argument for the function.
423+ * @param second the second argument for the function.
424+ * @param function the function.
425+ * @param <A> the first argument's type.
426+ * @param <T> the second argument's type.
427+ * @param <R> the result's type.
428+ * @return the result from the function.
429+ * @since 9.9.0
430+ */
431+ default <A , T , R > @ Nullable R getInWriteLock (
432+ @ NotNull A first ,
433+ @ NotNull T second ,
434+ @ NotNull NotNullNullableTripleFunction <ConcurrentArray <E >, A , T , R > function
435+ ) {
436+ var stamp = writeLock ();
437+ try {
438+ return function .apply (this , first , second );
439+ } finally {
440+ writeUnlock (stamp );
441+ }
442+ }
443+
394444 /**
395445 * Execute a function under {@link #readLock()} block.
396446 *
@@ -433,6 +483,33 @@ default void writeUnlock(long stamp) {
433483 return this ;
434484 }
435485
486+ /**
487+ * Execute a function under {@link #readLock()} block.
488+ *
489+ * @param <A> the first argument's type.
490+ * @param <T> the second argument's type.
491+ * @param first the first argument.
492+ * @param second the second argument.
493+ * @param function the function.
494+ * @return this array.
495+ * @since 9.9.0
496+ */
497+ default <A , T > @ NotNull ConcurrentArray <E > runInReadLock (
498+ @ NotNull A first ,
499+ @ NotNull T second ,
500+ @ NotNull NotNullTripleConsumer <ConcurrentArray <E >, A , T > function
501+ ) {
502+
503+ var stamp = readLock ();
504+ try {
505+ function .accept (this , first , second );
506+ } finally {
507+ readUnlock (stamp );
508+ }
509+
510+ return this ;
511+ }
512+
436513 /**
437514 * Execute a function under {@link #writeLock()} block.
438515 *
@@ -474,6 +551,31 @@ default void writeUnlock(long stamp) {
474551 return this ;
475552 }
476553
554+ /**
555+ * Execute a function under {@link #writeLock()} block.
556+ *
557+ * @param first the first argument for the function.
558+ * @param second the second argument for the function.
559+ * @param function the function.
560+ * @param <A> the first argument's type.
561+ * @param <T> the second argument's type.
562+ * @return this array.
563+ * @since 9.9.0
564+ */
565+ default <A , T > @ NotNull ConcurrentArray <E > runInWriteLock (
566+ @ NotNull A first ,
567+ @ NotNull T second ,
568+ @ NotNull NotNullTripleConsumer <ConcurrentArray <E >, A , T > function
569+ ) {
570+ var stamp = writeLock ();
571+ try {
572+ function .accept (this , first , second );
573+ } finally {
574+ writeUnlock (stamp );
575+ }
576+ return this ;
577+ }
578+
477579 /**
478580 * Search an element using the condition under {@link #readLock()} block.
479581 *
0 commit comments