Skip to content

Commit

Permalink
Backport atomic job locking from ksh 93v- beta
Browse files Browse the repository at this point in the history
Something similar was previously done in 07cc71b from a Debian
patch, and eventually reverted; it redefined the ast atomic
functions asoincint() and asodecint() to be gcc-specific. This
imports the upstream version from the ksh 93v- beta instead.

This commit is based on an OpenSUSE patch:
https://build.opensuse.org/package/view_file/shells/ksh/ksh93-joblock.dif

src/cmd/ksh93/include/jobs.h:
- Replace job locking mechanism with the 93v- version which uses
  the atomic libast functions asoincint(), asogetint() and
  asodecint(). See: src/lib/libast/man/aso.3

src/cmd/ksh93/sh/jobs.c: job_subsave():
- Revert gcc optimiser bug workaround from c258a04.
  It should now be unnecessary.
  • Loading branch information
McDutchie committed Feb 2, 2021
1 parent 1bd0620 commit 52067c3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
14 changes: 6 additions & 8 deletions src/cmd/ksh93/include/jobs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
# include <signal.h>
#endif /* !SIGINT */
#include "FEATURE/options"
#include <aso.h>

#undef JOBS
#if defined(SIGCLD) && !defined(SIGCHLD)
Expand Down Expand Up @@ -125,16 +126,13 @@ extern struct jobs job;
#define vmbusy() 0
#endif

#define job_lock() (job.in_critical++)
#define job_lock() asoincint(&job.in_critical)
#define job_unlock() \
do { \
int sig; \
if (!--job.in_critical && (sig = job.savesig)) \
{ \
if (!job.in_critical++ && !vmbusy()) \
job_reap(sig); \
job.in_critical--; \
} \
int _sig; \
if (asogetint(&job.in_critical) == 1 && (_sig = job.savesig) && !vmbusy()) \
job_reap(_sig); \
asodecint(&job.in_critical); \
} while(0)

extern const char e_jobusage[];
Expand Down
8 changes: 1 addition & 7 deletions src/cmd/ksh93/sh/jobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1882,14 +1882,8 @@ static int job_chksave(register pid_t pid)

void *job_subsave(void)
{
/*
* 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);
job_lock();
*bp = bck;
bp->prev = bck.prev;
bck.count = 0;
Expand Down

0 comments on commit 52067c3

Please sign in to comment.