@@ -260,22 +260,17 @@ void ggml_threading_suspend(struct ggml_threading_context *ctx) {
260
260
return ;
261
261
}
262
262
263
- struct ggml_compute_state_shared * shared = & ctx -> shared ;
264
-
265
- ggml_spin_lock (& shared -> spin );
263
+ PRINT_DEBUG ("[main] wait_now will be set, expect %d workers wait\n" ,
264
+ n_worker_threads );
266
265
ctx -> shared .wait_now = true;
267
- ggml_spin_unlock (& shared -> spin );
268
266
269
267
const int n_worker_threads = ctx -> n_threads - 1 ;
270
-
271
268
while (ctx -> shared .n_waiting != n_worker_threads ) {
272
269
ggml_spin_pause ();
273
270
}
274
271
275
- ggml_spin_lock (& shared -> spin );
276
- ctx -> suspending = true;
277
- ggml_spin_unlock (& shared -> spin );
278
272
PRINT_DEBUG ("[main] saw %d workers waiting\n" , n_worker_threads );
273
+ ctx -> suspending = true;
279
274
}
280
275
281
276
// Wakeup all workers.
@@ -291,7 +286,6 @@ void ggml_threading_resume(struct ggml_threading_context *ctx) {
291
286
}
292
287
293
288
struct ggml_compute_state_shared * shared = & ctx -> shared ;
294
- ggml_spin_lock (& shared -> spin );
295
289
296
290
int64_t perf_cycles_0 = 0 ;
297
291
int64_t perf_time_0 = 0 ;
@@ -307,8 +301,6 @@ void ggml_threading_resume(struct ggml_threading_context *ctx) {
307
301
shared -> wait_now = false;
308
302
309
303
while (shared -> n_waiting != 0 ) {
310
- ggml_spin_unlock (& shared -> spin );
311
-
312
304
if (loop_counter > 0 ) {
313
305
ggml_spin_pause ();
314
306
if (loop_counter > 3 ) {
@@ -326,18 +318,14 @@ void ggml_threading_resume(struct ggml_threading_context *ctx) {
326
318
GGML_ASSERT (pthread_cond_broadcast (& shared -> cond ) == 0 );
327
319
GGML_ASSERT (pthread_mutex_unlock (& shared -> mutex ) == 0 );
328
320
last_signal_time = ggml_time_us ();
329
-
330
- ggml_spin_lock (& shared -> spin );
331
321
}
332
322
333
323
ctx -> suspending = false;
334
324
335
325
if (shared -> ctx -> features & GGML_THREADING_FEATURE_PERF ) {
336
326
ggml_perf_collect (& shared -> ctx -> wakeup_perf , perf_cycles_0 ,
337
327
perf_time_0 );
338
- }
339
-
340
- ggml_spin_unlock (& shared -> spin );
328
+ };
341
329
}
342
330
343
331
bool ggml_threading_is_suspending (struct ggml_threading_context * ctx ) {
@@ -385,8 +373,6 @@ static void ggml_threading_setup_workers(struct ggml_threading_context *ctx,
385
373
}
386
374
} else if (current -> wait ) {
387
375
if (shared -> n_waiting < n_worker_threads ) {
388
- PRINT_DEBUG ("[main] wait_now will be set, expect %d workers wait\n" ,
389
- n_worker_threads );
390
376
ggml_spin_unlock (& ctx -> shared .spin );
391
377
ggml_threading_suspend (ctx );
392
378
ggml_spin_lock (& ctx -> shared .spin );
0 commit comments