---
name: "corelinux_SemaphoreCommon"
section: "3"
platform: "linux"
package: "libcorelinux-dev"
version: "0.4.32-5"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/corelinux_SemaphoreCommon"
---

# corelinux\_SemaphoreCommon(3)

The SemaphoreCommon manages the SemaphoreGroup common storage area.

## NAME

corelinux::SemaphoreCommon - The **SemaphoreCommon** manages the **SemaphoreGroup** common storage area.

## SYNOPSIS

`#include <SemaphoreCommon.hpp>`

Inherits **corelinux::Synchronized**.

### Static Public Member Functions

Int **getSemaphoreMaxValue** (**SemaphoreGroupPtr**, Int)\
 *Returns the maximum value for a semaphore as defined by the original semaphore claimant.*  void **groupDefined** (**SemaphoreGroupPtr**)\
 *When a shared semaphore group is created, it is updated in the CSA, either by increasing the count of processes accessing a particular group, or adding to the csa initially.*  Int **groupUnDefined** (**SemaphoreGroupPtr**)\
 *When the local process is deleting a semaphore group and it is considered a shared group, we are asked to adjust the map accordingly.*  Int **setLock** (**SemaphoreGroupPtr**, Int, Int, Int)\
 *Called by the base semaphore to aquire a lock for a specific semaphore.*  Int **setUnLock** (**SemaphoreGroupPtr**, Int, Int, Int)\
 *Called by the base semaphore to relinquish a lock for a specific semaphore.*  Int **waitZero** (**SemaphoreGroupPtr**, Int, Int, Int)\
 *Called by the base semaphore to wait for a specific semaphore to have a zero value.*  Int **obtainSemaphore** (**SemaphoreGroupPtr**, Int, IntRef, IntRef, IntRef, Int)\
 *Typically called by a* **SemaphoreGroup** *prior to passing out the semaphore type to the caller.*  Int **relinquishSemaphore** (**SemaphoreGroupPtr**, Int)\
 *Called when the semaphore is no longer being referenced.*  Int **setMaxValue** (**SemaphoreGroupPtr**, Int, Int)\
 *Called to set the semaphore maximum value.*

### Protected Member Functions

**SemaphoreCommon** (void)\
 *Default constructor used by class.*  virtual **~SemaphoreCommon** (void)\
 *Destructor.*  void **registerGroup** (**SemaphoreGroupPtr**)\
 *Does the work of getting the group registered in the CSA.*  Int **deregisterGroup** (**SemaphoreGroupPtr**)\
 *Does the work of reducing the group share count, or marking the group for reclaimation.*  Int **claimSemaphore** (**SemaphoreGroupPtr**, Int, IntRef, IntRef, IntRef, Int)\
 *Called when the group is determined to be shared and a semaphore share is to be claimed.*  Int **reclaimSemaphore** (**SemaphoreGroupPtr**, Int)\
 *Called when a group wishes to let the CSA reclaim a semaphore share.*  **CSAGrpHeaderPtr** **findGroup** (IntCref, IntCref, **CSAGrpHeaderPtr**)\
 *Attempt to locate a specific group.*  **CSAGrpHeaderPtr** **findAvailableGroup** (IntCref, IntCref, **CSAGrpHeaderPtr**)\
 *Find open slot that fits count criteria.*  **CSAGrpHeaderPtr** **subsetGroup** (Int, **CSAGrpHeaderPtr**)\
 *Utility to clean CSA group tail.*  **CSAGrpHeaderPtr** **combineGroup** (Int, **CSAGrpHeaderPtr**)\
 bool **isOriginator** (void) const \
 Int **getOriginatorId** (void) const \
 Int **canonicalUndefined** (void)\

### Static Protected Member Functions

void **createAttachment** (void)\
 *Factory for CSA.*  void **exitAttachment** (void)\
 *On the way out from run-time.*

### Friends

class **CoreLinuxGuardPool**\

## Detailed Description

The **SemaphoreCommon** manages the **SemaphoreGroup** common storage area.

This area is to communicate between address spaces when using one of the CoreLinux++ **SemaphoreGroup** types in public mode.

## Member Function Documentation

### Int corelinux::SemaphoreCommon::claimSemaphore (SemaphoreGroupPtr, Int, IntRef, IntRef, IntRef, Int)` [protected]`

Called when the group is determined to be shared and a semaphore share is to be claimed. **Parameters:**

*SemaphoreGroup* the group pointer \
 *Int* the semaphore identifier/index -1 = any \
 *Int* the initial value (becomes the max if new) \
 *IntRef* the recursive condition \
 *IntRef* the balking condition \
 *Int* 0 must not exist, 1 share, 2 must exist

### Int corelinux::SemaphoreCommon::deregisterGroup (SemaphoreGroupPtr)` [protected]`

Does the work of reducing the group share count, or marking the group for reclaimation. **Parameters:**

*SemaphoreGroup* pointer to register

### Int corelinux::SemaphoreCommon::getSemaphoreMaxValue (SemaphoreGroupPtr, Int)` [static]`

Returns the maximum value for a semaphore as defined by the original semaphore claimant. **Parameters:**

*SemaphoreGroup* pointer to group owner \
 *Int* zero offset semaphore identifier

**Returns:**

Int -1 for local unknown, \> 0 for common

### void corelinux::SemaphoreCommon::groupDefined (SemaphoreGroupPtr)` [static]`

When a shared semaphore group is created, it is updated in the CSA, either by increasing the count of processes accessing a particular group, or adding to the csa initially. **Parameters:**

*SemaphoreGroup* pointer

### Int corelinux::SemaphoreCommon::groupUnDefined (SemaphoreGroupPtr)` [static]`

When the local process is deleting a semaphore group and it is considered a shared group, we are asked to adjust the map accordingly. **Parameters:**

*SemaphoreGroup* pointer to the group

**Returns:**

Int number of shares on group

### Int corelinux::SemaphoreCommon::obtainSemaphore (SemaphoreGroupPtr, Int, IntRef, IntRef, IntRef, Int)` [static]`

Typically called by a **SemaphoreGroup** prior to passing out the semaphore type to the caller. **Parameters:**

*SemaphoreGroup* the group pointer \
 *Int* the semaphore identifier/index -1 = any \
 *Int* reference the initial value (becomes the max if new) \
 *Int* reference the recursive condition \
 *Int* reference the balking condition \
 *Int* 0 must not exist, 1 share, 2 must exist

### Int corelinux::SemaphoreCommon::reclaimSemaphore (SemaphoreGroupPtr, Int)` [protected]`

Called when a group wishes to let the CSA reclaim a semaphore share. **Parameters:**

*SemaphoreGroup* the group pointer \
 *Int* the semaphore identifier/index

**Returns:**

Int the number of shares outstanding

### void corelinux::SemaphoreCommon::registerGroup (SemaphoreGroupPtr)` [protected]`

Does the work of getting the group registered in the CSA. **Parameters:**

*SemaphoreGroup* pointer to register

### Int corelinux::SemaphoreCommon::relinquishSemaphore (SemaphoreGroupPtr, Int)` [static]`

Called when the semaphore is no longer being referenced. Effectively reducing the share count for shared group semaphores

**Parameters:**

*SemaphoreGroup* pointer \
 *Int* the zero index semaphore identifier

**Returns:**

Int the number of outstanding shares

### Int corelinux::SemaphoreCommon::setLock (SemaphoreGroupPtr, Int, Int, Int)` [static]`

Called by the base semaphore to aquire a lock for a specific semaphore. **Parameters:**

*SemaphoreGroup* pointer to the group \
 *Int* the system group id \
 *Int* the zero offset semaphore id \
 *Int* the system dependent flag

**Returns:**

Int return code

### Int corelinux::SemaphoreCommon::setMaxValue (SemaphoreGroupPtr, Int, Int)` [static]`

Called to set the semaphore maximum value. For local this is SETVAL, for shared it is ignored

**Parameters:**

*SemaphoreGroup* pointer \
 *Int* the zero index semaphore identifier \
 *Int* the value

### Int corelinux::SemaphoreCommon::setUnLock (SemaphoreGroupPtr, Int, Int, Int)` [static]`

Called by the base semaphore to relinquish a lock for a specific semaphore. **Parameters:**

*SemaphoreGroup* pointer to the group \
 *Int* the system group id \
 *Int* the zero offset semaphore id \
 *Int* the system dependent flag

**Returns:**

Int return code

### Int corelinux::SemaphoreCommon::waitZero (SemaphoreGroupPtr, Int, Int, Int)` [static]`

Called by the base semaphore to wait for a specific semaphore to have a zero value. **Parameters:**

*SemaphoreGroup* pointer to the group \
 *Int* the system group id \
 *Int* the zero offset semaphore id \
 *Int* the system dependent flag

**Returns:**

Int return code

## Author

Generated automatically by Doxygen for CoreLinux++ from the source code.
