RocketLogger  2.0.2
sem.c File Reference
#include <errno.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "log.h"
#include "rl.h"
#include "sem.h"
+ Include dependency graph for sem.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 

Functions

int sem_create (key_t key, int count)
 
int sem_remove (int id)
 
int sem_open (key_t key, int count)
 
int sem_wait (int id, int index, int timeout)
 
int sem_set (int id, int index, int value)
 
int sem_get (int id, int index)
 

Macro Definition Documentation

◆ _GNU_SOURCE

#define _GNU_SOURCE

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 33 of file sem.c.

Function Documentation

◆ sem_create()

int sem_create ( key_t  key,
int  count 
)

Create RocketLogger semaphore set.

Parameters
keyThe key identifying the semaphore set to create
countThe number of semaphores in the set to create
Returns
ID of created set on success, negative on failure with errno set accordingly

Definition at line 49 of file sem.c.

References rl_log(), and RL_LOG_ERROR.

+ Here is the call graph for this function:

◆ sem_get()

int sem_get ( int  id,
int  index 
)

Get value of a semaphore.

Parameters
idID of semaphore set
indexIndex of semaphore in set
Returns
The semaphore count, or negative on failure with errno set accordingly

Definition at line 129 of file sem.c.

References rl_log(), and RL_LOG_ERROR.

+ Here is the call graph for this function:

◆ sem_open()

int sem_open ( key_t  key,
int  count 
)

Open existing RocketLogger semaphore set.

Parameters
keyThe key identifying the semaphore set
countThe number of semaphores in the set
Returns
ID of opened set, negative on failure with errno set accordingly

Definition at line 68 of file sem.c.

References rl_log(), and RL_LOG_ERROR.

+ Here is the call graph for this function:

◆ sem_remove()

int sem_remove ( int  id)

Remove semaphore set.

Parameters
idID of set to remove
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 58 of file sem.c.

References rl_log(), RL_LOG_ERROR, and SUCCESS.

+ Here is the call graph for this function:

◆ sem_set()

int sem_set ( int  id,
int  index,
int  value 
)

Set value to semaphore.

Parameters
idID of semaphore set
indexIndex of semaphore in set
valueValue to be set to semaphore
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 108 of file sem.c.

References rl_log(), RL_LOG_ERROR, SEM_OPT_NO_FLAG, SEM_TIMEOUT_WRITE, and SUCCESS.

+ Here is the call graph for this function:

◆ sem_wait()

int sem_wait ( int  id,
int  index,
int  timeout 
)

Wait on a semaphore until access granted.

Parameters
idID of semaphore set
indexIndex of semaphore in set
timeoutMaximum waiting time before failing in seconds
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 78 of file sem.c.

References rl_log(), RL_LOG_ERROR, SEM_OPT_NO_FLAG, and SUCCESS.

+ Here is the call graph for this function: