summaryrefslogtreecommitdiffstats
path: root/src/backend/port/hpux/tas.c.template
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 12:17:33 +0000
commit5e45211a64149b3c659b90ff2de6fa982a5a93ed (patch)
tree739caf8c461053357daa9f162bef34516c7bf452 /src/backend/port/hpux/tas.c.template
parentInitial commit. (diff)
downloadpostgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.tar.xz
postgresql-15-5e45211a64149b3c659b90ff2de6fa982a5a93ed.zip
Adding upstream version 15.5.upstream/15.5
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/backend/port/hpux/tas.c.template')
-rw-r--r--src/backend/port/hpux/tas.c.template40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/backend/port/hpux/tas.c.template b/src/backend/port/hpux/tas.c.template
new file mode 100644
index 0000000..5ccbbcd
--- /dev/null
+++ b/src/backend/port/hpux/tas.c.template
@@ -0,0 +1,40 @@
+/*
+ * tas() for HPPA.
+ *
+ * To generate tas.s using this template:
+ * 1. cc +O2 -S -c tas.c
+ * 2. edit tas.s:
+ * - replace the LDW with LDCWX
+ * 3. install as src/backend/port/tas/hpux_hppa.s.
+ *
+ * For details about the LDCWX instruction, see the "Precision
+ * Architecture and Instruction Reference Manual" (09740-90014 of June
+ * 1987), p. 5-38.
+ */
+
+int
+tas(lock)
+ int *lock; /* LDCWX is a word instruction */
+{
+ /*
+ * LDCWX requires that we align the "semaphore" to a 16-byte
+ * boundary. The actual datum is a single word (4 bytes).
+ */
+ lock = ((uintptr_t) lock + 15) & ~15;
+
+ /*
+ * The LDCWX instruction atomically clears the target word and
+ * returns the previous value. Hence, if the instruction returns
+ * 0, someone else has already acquired the lock before we tested
+ * it (i.e., we have failed).
+ *
+ * Notice that this means that we actually clear the word to set
+ * the lock and set the word to clear the lock. This is the
+ * opposite behavior from the SPARC LDSTUB instruction. For some
+ * reason everything that H-P does is rather baroque...
+ */
+ if (*lock) { /* this generates the LDW */
+ return(0); /* success */
+ }
+ return(1); /* failure */
+}