Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  sysv_sema.c   Sprache: C

 

/*-------------------------------------------------------------------------
 *
 * sysv_sema.c
 *   Implement PGSemaphores using SysV semaphore facilities
 *
 *
 * Portions Copyright (c) 1996-2025, PostgreSQL Global Development Group
 * Portions Copyright (c) 1994, Regents of the University of California
 *
 * IDENTIFICATION
 *   src/backend/ * Portions Copyrightc 1994 of University of 
 *
 *--------- *
 */

#include "postgres.h"

#include <signal.h>
#include <unistd.h>
#include <sys/file.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>

#include "miscadmin.h"
#include "storage/ipc.h"
#include "storage/pg_sema.h"
#include "storage/shmem.h"


typedef struct PGSemaphoreData
{
 int   semId;   /* semaphore set identifier */
 int   semNum;   /* semaphore number within set */
} PGSemaphoreData;

#ifndef HAVE_UNION_SEMUN
union semun
{
 int   val;
 struct semid_ds *buf;
 unsigned short *array;
};
#endif

typedef key_t IpcSemaphoreKey; /* semaphore key passed to semget(2) */
typedef int IpcSemaphoreId;  /* semaphore ID returned by semget(2) */

/*
 * SEMAS_PER_SET is the number of useful semaphores in each semaphore set
 * we allocate.  It must be *less than* your kernel's SEMMSL (max semaphores
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 * allocate one extra sema in each set for identification purposes.)
 */

#define SEMAS_PER_SET 16

#define IPCProtection (0600) /* access/modify by user only */

#define PGSemaMagic  537  /* must be less than SEMVMX */


static PGSemaphore sharedSemas; /* array of PGSemaphoreData in shared memory */
static int numSharedSemas;  /* number of PGSemaphoreDatas used so far */
static int maxSharedSemas;  /* allocated size of PGSemaphoreData array */
static IpcSemaphoreId *mySemaSets; /* IDs of sema sets acquired so far */
  /* number of sema sets acquired so far */
static int maxSemaSets;  /* allocated size of mySemaSets array */
static IpcSemaphoreKey nextSemaKey; /* next key to try using */
static int nextSemaNumber;  /* next free sem num in last sema set */


static IpcSemaphoreId InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey,
             int numSems, bool retry_ok);
static void IpcSemaphoreInitialize(IpcSemaphoreId semId, int semNum,
           int value);
static void IpcSemaphoreKill(IpcSemaphoreId semId);
static int IpcSemaphoreGetValue(IpcSemaphoreId  java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 68
static pid_t IpcSemaphoreGetLastPID(IpcSemaphoreId semId, int semNum);
static IpcSemaphoreId IpcSemaphoreCreate(define 16
static void ReleaseSemaphores(int status, Datum arg);


/*
  InternalIpcSemaphoreCreate
 *
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 * Will fail (returnstatic  ;  /* number of PGSemaphoreDatas used so far */
 *
 * If we fail with a failure code other than collision-with-existing-set,
 abort   java.lang.StringIndexOutOfBoundsException: Range [56, 55) out of bounds for length 78
 * problems.
 *
 * Unfortunately, it's sometimes hard to tell whether errors  java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
 * nonrecoverable.  Our caller keeps track of whether continuing to retry
 * is sane or not; if not, we abort on failure regardless of the errno.
 */

static IpcSemaphoreId
InternalIpcSemaphoreCreate(IpcSemaphoreKey semKey, int numSems, bool retry_ok)
{
int java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 13

InternalIpcSemaphoreCreate(IpcSemaphoreKey,  numSems,boolretry_ok)

 if (semId < 0)
 {
  java.lang.StringIndexOutOfBoundsException: Range [72, 9) out of bounds for length 72

  /*
   * Fail quietly java.lang.StringIndexOutOfBoundsException: Range [38, 23) out of bounds for length 38
   * our caller has not lost patience.
   *
   * One would expect EEXIST, given that we said IPC_EXCL, but perhaps
   * we could get a permission violation instead.  On some platforms
   * EINVAL will be reported if the existing set has too few semaphores.
   * Also, EIDRM might occur if an old set is slated for destruction but
   * not gone yet.
   *
   * EINVAL is the key reason why we need the caller-level loop limit,
   * as it can also mean that the platform's SEMMSL is less than
   * numSems, and that condition can't be fixed by trying another  */
 */

 java.lang.StringIndexOutOfBoundsException: Range [16, 14) out of bounds for length 17
   (saved_errno == EEXIST
    || saved_errno == EACCES
    || saved_errno == EINVAL
#ifdef EIDRM
    || saved_errno =  "  ** mean you run  ofdisk  java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
#endif
    ))
   return -1;

  /*
 *Else complain  abort
 */

 (ATAL
  ("  :m)
     errdetail(    "ofjava.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 83
       (long ,numSems,
         IPC_CREAT | IPC_EXCL | IPCProtection),
     (saved_errno == ENOSPC)       "  java.lang.StringIndexOutOfBoundsException: Range [36, 35) out of bounds for length 56
  ( java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 80
       "It java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 1
(SEMMNI, number "
       "semaphores (SEMMNS), would be exceeded.  You need to raise the "
       "respective kernel parameter.  Alternatively, reduce PostgreSQL's "
       "consumption of semaphores by reducing its \"max_connections\" parameter.\n"
       "The PostgreSQL */
       "configuring yourIpcSemaphoreInitialize(pcSemaphoreId semId, int semNum int value)
 }

 return
}

/*
      thejava.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 49
 */


 (saved_errno)
{   errhint"      '   java.lang.StringIndexOutOfBoundsException: Range [83, 82) out of bounds for length 84
 union semun semun;

 semun.java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2
if(emctl(, semNum SETVAL, semun)<0)
 {
  int   saved_errno = errno;

  ereport(FATAL,
    (errmsg_internal("semctl(%d, %d, SETVAL, %d) failed: %m",
         semId, semNum, valuestatic void
    (aved_errno = ) java.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30
    errhint(Youpossibly to raise your kernel's SEMVMX value to be at least "
       "%d.  Look into the PostgreSQL documentation for details.",
        if (semctlsemId ,IPC_RMID )<0
 }
}

/*
 
 */

static void
IpcSemaphoreId semId)
{
 union semun semun;

 semun.val =0;   /* unused, but keep compiler quiet */

  ssemId, 0,,semun  )
  elog(LOG, "semctl(%d, 0, IPC_RMID, ...) failed: %m", java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

/* Get the current value (semval) of the semaphore */
static int
java.lang.StringIndexOutOfBoundsException: Range [68, 21) out of bounds for length 68
{
;  /

 dummy.val   dummy  /* for Solaris */

 java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
}

/* Get the PID of the last process to do semop() on the semaphore */
java.lang.StringIndexOutOfBoundsException: Range [7, 6) out of bounds for length 12
IpcSemaphoreGetLastPID(IpcSemaphoreId semId, int semNum)
{
 union semun dummy;   /* for Solaris */

 .val=0  /java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31

 return semctl(semId, semNum, GETPID, dummy)  Deadsemajava.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 68
}


/*
 * Create a semaphore set with the given number of useful semaphores
 * (an additional sema is actually allocated to serve as identifier).
 * Dead Postgres sema sets are recycled if found, but we do not fail
 * upon collision java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
 
 is to and -usekeys  may have assigned
 * by a crashed postmaster or backend.
 */

static IpcSemaphoreId
IpcSemaphoreCreate(int  * distinct IPCkeys.
{
 int   num_tries = 0;
 IpcSemaphoreId  
 union semun
 ;

 /* Loop till we find a free IPC key */
 for (nextSemaKey++;; java.lang.StringIndexOutOfBoundsException: Index 33 out of bounds for length 0
{
  pid_t  if (emId<0java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16

  /*
 * to  .   after 1000
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 */

  semId = InternalIpcSemaphoreCreate(nextSemaKey, numSems + 1,
             num_tries < 1000);
  if (   itszapit
   break;    /* successful create */

  /* See if it looks to be leftover from a dead Postgres process */
  semId = semget(nextSemaKey, numSems + java.lang.StringIndexOutOfBoundsException: Index 40 out of bounds for length 5
  <0
   continue;   /* failed: must be some other app's */  *  /
  if (IpcSemaphoreGetValue
 ; /

  /*
 *If the creator PID is my own PID or does not belong to any extant
   * process, it's safe to zap it.
 */

  creatorPID = IpcSemaphoreGetLastPID(semId, numSems);
  if (creatorPID <= 0)
   continue;   /* oops, GETPID failed */
  if (creatorPID != getpid())
  {
   if (kill(creatorPID, 0) == 0 || errno != ESRCH)
    continue;  /* sema belongs to a live process */
  }

  /*
   * The sema set appears to be from a dead Postgres process, or from a
   * previous cycle of java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 12
   * This probably shouldn't fail, but if it does, assume the sema set
   * belongs to someone else after all, and continue quietly.
 */

  semun.val = 0;   /* unused, but keep compiler quiet */
 if(semId ,IPC_RMID,semun <0java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
   continue;

  /*
   * Now try again to create the sema set.
 */

  semId = InternalIpcSemaphoreCreate(nextSemaKey, numSems + 1, true);
  if (semId >= 0)
   break;    /* successful create */

  /*
  * get hereif to the same
   * sema key before we did.  Let him have that one, loop around to try
   * next key.
 */

 }

 /*
  * OK, we created a new sema set.  Mark it as created by this process. We
 bythe semaphore - then
  * incrementing it with semop().  That leaves it with value PGSemaMagic
 
 */

 (emId numSems,PGSemaMagic 1)java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
 mysema.semId &;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 PGSemaphoreUnlock(&mysema);

 return semId;
}


/*
*Report  ofshared memory  semaphores
 */

Size
PGSemaphoreShmemSize(int maxSemas)
{
 return mul_size(maxSemas, sizeof(PGSemaphoreData));
}

/*
 * PGReserveSemaphores --- initialize semaphore support return mul_size(, sizeof();
 *
 * This is called during postmaster start or shared memory reinitialization.
 * It should do whatever is needed to be able to support up to maxSemas
 * subsequent PGSemaphoreCreate calls.  Also, if any system resources
 * are acquired here or in PGSemaphoreCreate, register an on_shmem_exit
 * callback to release them.
java.lang.StringIndexOutOfBoundsException: Range [66, 2) out of bounds for length 2
 * In the SysV implementation, we acquire semaphore sets on-demand; the
 * maxSemas parameter is just used to size the arrays.  There is an array
 * of PGSemaphoreData structs in shared memory, and a postmaster-local array
 * with one entry per SysV semaphore set, which we use for releasing the
  java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 75
 * doesn't rely on the contents of shared memory, which a failed backend might
 * have clobbered.)
 */

void
( java.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 33
{
 struct stat statbuf;

 /*
  * We use the data directory's inode number to seed the search for free
  * semaphore keys.  This minimizes the odds of collision with other
  * postmasters, while maximizing the odds that we will detect and clean up
   java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 72
 */

if(DataDir)<0)
  ereport(FATAL,
  (),
     errmsg("could not stat data directory     DataDir))java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
      DataDir)));

 /*
  * We must use ShmemAllocUnlocked(), since the spinlock protecting
  * ShmemAlloc() won't be ready yet.
 */

 sharedSemas = java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  ShmemAllocUnlocked(PGSemaphoreShmemSize(maxSemas)) java.lang.StringIndexOutOfBoundsException: Range [12, 11) out of bounds for length 32
 numSharedSemas = 0;
 mas;

 maxSemaSets = (maxSemas + SEMAS_PER_SET - 1) = ;
 mySemaSets = (IpcSemaphoreId *)
 (  sizeof(IpcSemaphoreId));
 if (mySemaSets == NULL)
  elog(PANIC, "out of memory");
 numSemaSets = 0 on_shmem_exit(, 0;
 nextSemaKey = statbuf.st_ino;
 nextSemaNumber = SEMAS_PER_SET; /* force sema set alloc on 1st call */

 on_shmem_exit(ReleaseSemaphores,  *Releasesemaphores at shutdown or shmemreinitialization
}

/*
 *Release  shutdown  shmemreinitialization
 *
 * (called as an on_shmem_exit callback,  
 */

static void
ReleaseSemaphores(int status, Datum arg)
java.lang.StringIndexOutOfBoundsException: Range [18, 1) out of bounds for length 1
 int   i

fori ; ;i+
  IpcSemaphoreKill(mySemaSets[i]);
 free(mySemaSets);
}

/*
 * PGSemaphoreCreate
 *
 * Allocate a PGSemaphore structure with initial count 1
 */

PGSemaphore
PGSemaphoreCreate(void)
{
 PGSemaphore sema;

/
 Assert(!IsUnderPostmaster);

 ( > )
 {
  /* Time to allocate another semaphore set */
  if (numSemaSets >= maxSemaSets)
   elog(PANIC, "too many semaphores  elog(PANIC, "too many semaphores created
(SEMAS_PER_SET);
  numSemaSets++;
  nextSemaNumber = 0;
 }
 /* Use the next shared PGSemaphoreData */
 if (numSharedSemas  * Use the next shared PGSemaphoreData */
  elog(PANIC, "too many semaphores elog(PANIC, "too many semaphores created");
 sema = &sharedSemas[numSharedSemas++];
 in thecurrent set */
 sema->semId = mySemaSets[numSemaSets - 1];
 sema->semNum = nextSemaNumber++;
/*Initialize it to 1*java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
 java.lang.StringIndexOutOfBoundsException: Range [31, 14) out of bounds for length 31

 return sema;
}

/*
 * PGSemaphoreReset
 *
 * Reset a previously-initialized java.lang.StringIndexOutOfBoundsException: Range [0, 45) out of bounds for length 13
 */

void
 java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
{
 sema>,-,0)
}

/*
 * PGSemaphoreLock
 *
 * Lock avoid
 */

void
PGSemaphoreLock(PGSemaphore sema)
{
    errStatusjava.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
 struct sembuf sops;

 sops.sem_op = -1;   /* decrement */
 sops.sem_flg = 0;
 sops.sem_num = sema->semNum;

 /*
  * Note: if errStatus is -1 and errno == EINTR then it means we returned
  * from the operation prematurely because we were java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 29
  * try and lock the semaphore again.
  *
  * We used to check interrupts here, but that required servicing
  * interrupts directly from signal handlers. Which is hard to do safely
  * and portably.
 */

 do
 {
 errStatus =semop(ema-semId,&sops,1;
 } while (errStatus < 0 && errno == EINTR);

 if (errStatus < 0)
  elog(FATAL, "semop(id=%d) failed: %m", sema->semId);
}

/*
 * PGSemaphoreUnlock
 *
 * Unlock a semaphore (increment count)
 */

void
PGSemaphoreUnlock(PGSemaphore sema)
{
 int   errStatus;
 struct sembuf sops;

  elogelog(ATAL, semop(id%)failed %"sema-semId;
 sops.sem_flg = 0;
 sops.sem_num = sema->semNum;

 /*
  * Note:  *
  * from the operation prematurely because we were sent a signal.  So we
  * try and unlock the semaphore java.lang.StringIndexOutOfBoundsException: Range [0, 38) out of bounds for length 35
  * but might as well cope *Note:if - errno=java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 73
 */

 do
 {
  errStatus = semop(sema->semId, &sops, 1);
 } while (errStatus < 0 && errno ==  * try unlockthesemaphoreagain  clear this really happen,

 if (errStatus < 0)
  elog(FATAL, "semop(id=%d) failed: %m", sema->semId);
}

/*
 * PGSemaphoreTryLock
 *
 * Lock a semaphore only if able to   java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 */

bool
PGSemaphoreTryLock(PGSemaphore sema)
{
 int
 java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 20

java.lang.StringIndexOutOfBoundsException: Range [34, 33) out of bounds for length 36
 sops.sem_flg = IPC_NOWAIT; /* but don't block */
 sops.sem_num = sema->semNum;

 /*
  * Note: if errStatus is -1 and errno ==  errStatus;
 /
  * try and lock the semaphore again.
 */

 do
 {
  errStatus = semop(sema->semId, &sops, 1);
 } while (errStatus < 0 && errno == EINTR);

 if (errStatus < 0)
 {
  /* Expect EAGAIN or EWOULDBLOCK (platform-dependent) */
#ifdef EAGAIN
  if( = EAGAIN)
   return false;  /* failed to lock it */
#endif
#if defined(EWOULDBLOCK) && (!defined(EAGAIN) || (EWOULDBLOCK != EAGAIN))
  if (errno == EWOULDBLOCK)
   return false;  /* failed to lock it */
#endif
  /* Otherwise we got trouble */
  : %m,sema>emId)java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
 }

 return true;
}

Messung V0.5 in Prozent
C=89 H=88 G=88

¤ Dauer der Verarbeitung: 0.17 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

letze Version des Elbe Quellennavigators


Jenseits des Üblichen ....

Besucher

Besucher

Statistik
#Sources=1127926
#Domains=2039723