@@ -1100,6 +1100,12 @@ zstream_run_try(VALUE value_arg)
1100
1100
int err ;
1101
1101
VALUE old_input = Qnil ;
1102
1102
1103
+ /* Cannot start zstream while it is in progress. */
1104
+ if (z -> flags & ZSTREAM_IN_PROGRESS ) {
1105
+ rb_raise (cInProgressError , "zlib stream is in progress" );
1106
+ }
1107
+ z -> flags |= ZSTREAM_IN_PROGRESS ;
1108
+
1103
1109
if (NIL_P (z -> input ) && len == 0 ) {
1104
1110
z -> stream .next_in = (Bytef * )"" ;
1105
1111
z -> stream .avail_in = 0 ;
@@ -1167,35 +1173,18 @@ zstream_run_try(VALUE value_arg)
1167
1173
rb_str_resize (old_input , 0 );
1168
1174
}
1169
1175
1170
- if (args -> jump_state )
1171
- rb_jump_tag (args -> jump_state );
1172
-
1173
1176
return Qnil ;
1174
1177
}
1175
1178
1176
1179
static VALUE
1177
1180
zstream_run_ensure (VALUE value_arg )
1178
1181
{
1179
1182
struct zstream_run_args * args = (struct zstream_run_args * )value_arg ;
1183
+ struct zstream * z = args -> z ;
1180
1184
1181
1185
/* Remove ZSTREAM_IN_PROGRESS flag to signal that this zstream is not in use. */
1182
- args -> z -> flags &= ~ZSTREAM_IN_PROGRESS ;
1183
-
1184
- return Qnil ;
1185
- }
1186
-
1187
- static VALUE
1188
- zstream_run_synchronized (VALUE value_arg )
1189
- {
1190
- struct zstream_run_args * args = (struct zstream_run_args * )value_arg ;
1191
-
1192
- /* Cannot start zstream while it is in progress. */
1193
- if (args -> z -> flags & ZSTREAM_IN_PROGRESS ) {
1194
- rb_raise (cInProgressError , "zlib stream is in progress" );
1195
- }
1196
- args -> z -> flags |= ZSTREAM_IN_PROGRESS ;
1197
-
1198
- rb_ensure (zstream_run_try , value_arg , zstream_run_ensure , value_arg );
1186
+ z -> flags &= ~ZSTREAM_IN_PROGRESS ;
1187
+ rb_mutex_unlock (z -> mutex );
1199
1188
1200
1189
return Qnil ;
1201
1190
}
@@ -1212,7 +1201,10 @@ zstream_run(struct zstream *z, Bytef *src, long len, int flush)
1212
1201
.jump_state = 0 ,
1213
1202
.stream_output = !ZSTREAM_IS_GZFILE (z ) && rb_block_given_p (),
1214
1203
};
1215
- rb_mutex_synchronize (z -> mutex , zstream_run_synchronized , (VALUE )& args );
1204
+ rb_mutex_lock (z -> mutex );
1205
+ rb_ensure (zstream_run_try , (VALUE )& args , zstream_run_ensure , (VALUE )& args );
1206
+ if (args .jump_state )
1207
+ rb_jump_tag (args .jump_state );
1216
1208
}
1217
1209
1218
1210
static VALUE
0 commit comments