From 595a0a5684d908af171dca13f4a2cfadd7c24b75 Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Wed, 17 Mar 2021 14:25:34 +0000 Subject: [PATCH] Revert "Backport atomic job locking from ksh 93v- beta" (52067c3d) That patch broke the build on Cygwin, where gcc apparently doesn't have the required atomic addition/subtraction compiler builtins. The build fails at link time with those functions not found. As far as I know, ksh was actually working fine (after @JohnoKing's gcc workaround in c258a04f), so I'll just revert this for now. If a need for it is demonstrated later, we'll have to add a feature test or find some other way to get it working on Cygwin. --- src/cmd/ksh93/include/jobs.h | 14 ++++++++------ src/cmd/ksh93/sh/jobs.c | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/cmd/ksh93/include/jobs.h b/src/cmd/ksh93/include/jobs.h index 7dd01085cc75..5365152bbfe6 100644 --- a/src/cmd/ksh93/include/jobs.h +++ b/src/cmd/ksh93/include/jobs.h @@ -33,7 +33,6 @@ # include #endif /* !SIGINT */ #include "FEATURE/options" -#include #undef JOBS #if defined(SIGCLD) && !defined(SIGCHLD) @@ -126,13 +125,16 @@ extern struct jobs job; #define vmbusy() 0 #endif -#define job_lock() asoincint(&job.in_critical) +#define job_lock() (job.in_critical++) #define job_unlock() \ do { \ - int _sig; \ - if (asogetint(&job.in_critical) == 1 && (_sig = job.savesig) && !vmbusy()) \ - job_reap(_sig); \ - asodecint(&job.in_critical); \ + int sig; \ + if (!--job.in_critical && (sig = job.savesig)) \ + { \ + if (!job.in_critical++ && !vmbusy()) \ + job_reap(sig); \ + job.in_critical--; \ + } \ } while(0) extern const char e_jobusage[]; diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index e1c664b1d304..873bd1170c04 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -1891,8 +1891,14 @@ static int job_chksave(register pid_t pid) void *job_subsave(void) { - struct back_save *bp = new_of(struct back_save,0); + /* + * We must make a lock first before doing anything else, + * otherwise GCC will remove the job locking mechanism + * as a result of compiler optimization. + */ job_lock(); + + struct back_save *bp = new_of(struct back_save,0); *bp = bck; bp->prev = bck.prev; bck.count = 0;