@@ -437,7 +437,12 @@ public ZstdCompressCtx loadDict(byte[] dict) {
437
437
*/
438
438
public ZstdFrameProgression getFrameProgression () {
439
439
ensureOpen ();
440
- return getFrameProgression0 (nativePtr );
440
+ acquireSharedLock ();
441
+ try {
442
+ return getFrameProgression0 (nativePtr );
443
+ } finally {
444
+ releaseSharedLock ();
445
+ }
441
446
}
442
447
private static native ZstdFrameProgression getFrameProgression0 (long ptr );
443
448
@@ -447,10 +452,16 @@ public ZstdFrameProgression getFrameProgression() {
447
452
*/
448
453
public void reset () {
449
454
ensureOpen ();
450
- long result = reset0 (nativePtr );
451
- if (Zstd .isError (result )) {
452
- throw new ZstdException (result );
455
+ acquireSharedLock ();
456
+ try {
457
+ long result = reset0 (nativePtr );
458
+ if (Zstd .isError (result )) {
459
+ throw new ZstdException (result );
460
+ }
461
+ } finally {
462
+ releaseSharedLock ();
453
463
}
464
+
454
465
}
455
466
private static native long reset0 (long ptr );
456
467
@@ -464,9 +475,14 @@ public void reset() {
464
475
*/
465
476
public void setPledgedSrcSize (long srcSize ) {
466
477
ensureOpen ();
467
- long result = setPledgedSrcSize0 (nativePtr , srcSize );
468
- if (Zstd .isError (result )) {
469
- throw new ZstdException (result );
478
+ acquireSharedLock ();
479
+ try {
480
+ long result = setPledgedSrcSize0 (nativePtr , srcSize );
481
+ if (Zstd .isError (result )) {
482
+ throw new ZstdException (result );
483
+ }
484
+ } finally {
485
+ releaseSharedLock ();
470
486
}
471
487
}
472
488
private static native long setPledgedSrcSize0 (long ptr , long srcSize );
@@ -482,14 +498,19 @@ public void setPledgedSrcSize(long srcSize) {
482
498
*/
483
499
public boolean compressDirectByteBufferStream (ByteBuffer dst , ByteBuffer src , EndDirective endOp ) {
484
500
ensureOpen ();
485
- long result = compressDirectByteBufferStream0 (nativePtr , dst , dst .position (), dst .limit (), src , src .position (), src .limit (), endOp .value ());
486
- if ((result & 0x80000000L ) != 0 ) {
487
- long code = result & 0xFF ;
488
- throw new ZstdException (code , Zstd .getErrorName (code ));
501
+ acquireSharedLock ();
502
+ try {
503
+ long result = compressDirectByteBufferStream0 (nativePtr , dst , dst .position (), dst .limit (), src , src .position (), src .limit (), endOp .value ());
504
+ if ((result & 0x80000000L ) != 0 ) {
505
+ long code = result & 0xFF ;
506
+ throw new ZstdException (code , Zstd .getErrorName (code ));
507
+ }
508
+ src .position ((int )(result & 0x7FFFFFFF ));
509
+ dst .position ((int )(result >>> 32 ) & 0x7FFFFFFF );
510
+ return (result >>> 63 ) == 1 ;
511
+ } finally {
512
+ releaseSharedLock ();
489
513
}
490
- src .position ((int )(result & 0x7FFFFFFF ));
491
- dst .position ((int )(result >>> 32 ) & 0x7FFFFFFF );
492
- return (result >>> 63 ) == 1 ;
493
514
}
494
515
495
516
/**
@@ -604,7 +625,6 @@ public int compressByteArray(byte[] dstBuff, int dstOffset, int dstSize, byte[]
604
625
* @return the size of the compressed data
605
626
*/
606
627
public int compress (ByteBuffer dstBuf , ByteBuffer srcBuf ) {
607
-
608
628
int size = compressDirectByteBuffer (dstBuf , // compress into dstBuf
609
629
dstBuf .position (), // write compressed data starting at offset position()
610
630
dstBuf .limit () - dstBuf .position (), // write no more than limit() - position() bytes
0 commit comments