Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

spin.c File Reference

#include "postgres.h"
#include "miscadmin.h"
#include "replication/walsender.h"
#include "storage/lwlock.h"
#include "storage/spin.h"
Include dependency graph for spin.c:

Go to the source code of this file.

Functions

int SpinlockSemas (void)
void s_init_lock_sema (volatile slock_t *lock)
void s_unlock_sema (volatile slock_t *lock)
bool s_lock_free_sema (volatile slock_t *lock)
int tas_sema (volatile slock_t *lock)

Function Documentation

void s_init_lock_sema ( volatile slock_t lock  ) 

Definition at line 76 of file spin.c.

References PGSemaphoreCreate().

bool s_lock_free_sema ( volatile slock_t lock  ) 

Definition at line 88 of file spin.c.

References elog, and ERROR.

{
    /* We don't currently use S_LOCK_FREE anyway */
    elog(ERROR, "spin.c does not support S_LOCK_FREE()");
    return false;
}

void s_unlock_sema ( volatile slock_t lock  ) 

Definition at line 82 of file spin.c.

References PGSemaphoreUnlock().

int SpinlockSemas ( void   ) 

Definition at line 52 of file spin.c.

References max_wal_senders, NBuffers, and NumLWLocks().

Referenced by CreateSharedMemoryAndSemaphores().

{
    int     nsemas;

    /*
     * It would be cleaner to distribute this logic into the affected modules,
     * similar to the way shmem space estimation is handled.
     *
     * For now, though, there are few enough users of spinlocks that we just
     * keep the knowledge here.
     */
    nsemas = NumLWLocks();      /* one for each lwlock */
    nsemas += NBuffers;         /* one for each buffer header */
    nsemas += max_wal_senders;  /* one for each wal sender process */
    nsemas += 30;               /* plus a bunch for other small-scale use */

    return nsemas;
}

int tas_sema ( volatile slock_t lock  ) 

Definition at line 96 of file spin.c.

References PGSemaphoreTryLock().

{
    /* Note that TAS macros return 0 if *success* */
    return !PGSemaphoreTryLock((PGSemaphore) lock);
}