~ubuntu-branches/ubuntu/oneiric/postgresql-9.1/oneiric-security

« back to all changes in this revision

Viewing changes to src/include/storage/spin.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * spin.h
 
4
 *         Hardware-independent implementation of spinlocks.
 
5
 *
 
6
 *
 
7
 *      The hardware-independent interface to spinlocks is defined by the
 
8
 *      typedef "slock_t" and these macros:
 
9
 *
 
10
 *      void SpinLockInit(volatile slock_t *lock)
 
11
 *              Initialize a spinlock (to the unlocked state).
 
12
 *
 
13
 *      void SpinLockAcquire(volatile slock_t *lock)
 
14
 *              Acquire a spinlock, waiting if necessary.
 
15
 *              Time out and abort() if unable to acquire the lock in a
 
16
 *              "reasonable" amount of time --- typically ~ 1 minute.
 
17
 *
 
18
 *      void SpinLockRelease(volatile slock_t *lock)
 
19
 *              Unlock a previously acquired lock.
 
20
 *
 
21
 *      bool SpinLockFree(slock_t *lock)
 
22
 *              Tests if the lock is free. Returns TRUE if free, FALSE if locked.
 
23
 *              This does *not* change the state of the lock.
 
24
 *
 
25
 *      Callers must beware that the macro argument may be evaluated multiple
 
26
 *      times!
 
27
 *
 
28
 *      CAUTION: Care must be taken to ensure that loads and stores of
 
29
 *      shared memory values are not rearranged around spinlock acquire
 
30
 *      and release. This is done using the "volatile" qualifier: the C
 
31
 *      standard states that loads and stores of volatile objects cannot
 
32
 *      be rearranged *with respect to other volatile objects*. The
 
33
 *      spinlock is always written through a volatile pointer by the
 
34
 *      spinlock macros, but this is not sufficient by itself: code that
 
35
 *      protects shared data with a spinlock MUST reference that shared
 
36
 *      data through a volatile pointer.
 
37
 *
 
38
 *      Keep in mind the coding rule that spinlocks must not be held for more
 
39
 *      than a few instructions.  In particular, we assume it is not possible
 
40
 *      for a CHECK_FOR_INTERRUPTS() to occur while holding a spinlock, and so
 
41
 *      it is not necessary to do HOLD/RESUME_INTERRUPTS() in these macros.
 
42
 *
 
43
 *      These macros are implemented in terms of hardware-dependent macros
 
44
 *      supplied by s_lock.h.  There is not currently any extra functionality
 
45
 *      added by this header, but there has been in the past and may someday
 
46
 *      be again.
 
47
 *
 
48
 *
 
49
 * Portions Copyright (c) 1996-2011, PostgreSQL Global Development Group
 
50
 * Portions Copyright (c) 1994, Regents of the University of California
 
51
 *
 
52
 * src/include/storage/spin.h
 
53
 *
 
54
 *-------------------------------------------------------------------------
 
55
 */
 
56
#ifndef SPIN_H
 
57
#define SPIN_H
 
58
 
 
59
#include "storage/s_lock.h"
 
60
 
 
61
 
 
62
#define SpinLockInit(lock)      S_INIT_LOCK(lock)
 
63
 
 
64
#define SpinLockAcquire(lock) S_LOCK(lock)
 
65
 
 
66
#define SpinLockRelease(lock) S_UNLOCK(lock)
 
67
 
 
68
#define SpinLockFree(lock)      S_LOCK_FREE(lock)
 
69
 
 
70
 
 
71
extern int      SpinlockSemas(void);
 
72
 
 
73
#endif   /* SPIN_H */