FFmpegfs Fuse Multi Media Filesystem 2.16
Macros | Functions | Variables
cache_maintenance.cc File Reference

Cache maintenance implementation More...

#include "cache_maintenance.h"
#include "ffmpegfs.h"
#include "logging.h"
#include <csignal>
#include <unistd.h>
#include <sys/shm.h>
#include <semaphore.h>
Include dependency graph for cache_maintenance.cc:

Go to the source code of this file.

Macros

#define CLOCKID   CLOCK_REALTIME
 Use real time clock here. More...
 
#define SIGMAINT   SIGRTMIN
 Map maintenance signal. More...
 
#define SEM_OPEN_FILE   "/" PACKAGE_NAME "_04806785-b5fb-4615-ba56-b30a2946e80b"
 Shared semaphore name, should be unique system wide. More...
 

Functions

static void maintenance_handler (int sig, __attribute__((unused)) siginfo_t *si, __attribute__((unused)) void *uc)
 Run maintenance handler. More...
 
static bool start_timer (time_t interval)
 Start the maintenance timer at predefined interval. More...
 
static bool stop_timer ()
 Stop the maintenance timer. More...
 
static bool link_up ()
 Set system wide inter process link up. More...
 
static void master_check ()
 Check if a master is already running. We become master if not. More...
 
static bool link_down ()
 Set system wide inter process link down. More...
 
bool start_cache_maintenance (time_t interval)
 Start cache maintenance timer. More...
 
bool stop_cache_maintenance ()
 Stop cache maintenance timer. More...
 

Variables

static sigset_t mask
 Process mask for timer. More...
 
static timer_t timerid
 Timer id. More...
 
static sem_t * sem
 Semaphore used to synchronise between master and slave processes. More...
 
static int shmid
 Shared memory segment ID. More...
 
static pid_t * pid_master
 PID of master process. More...
 
static bool master
 If true, we are master. More...
 

Detailed Description

Cache maintenance implementation

Author
Norbert Schlia (nschl.nosp@m.ia@o.nosp@m.blivi.nosp@m.on-s.nosp@m.oftwa.nosp@m.re.d.nosp@m.e)

Definition in file cache_maintenance.cc.

Macro Definition Documentation

◆ CLOCKID

#define CLOCKID   CLOCK_REALTIME

Use real time clock here.

Definition at line 41 of file cache_maintenance.cc.

◆ SEM_OPEN_FILE

#define SEM_OPEN_FILE   "/" PACKAGE_NAME "_04806785-b5fb-4615-ba56-b30a2946e80b"

Shared semaphore name, should be unique system wide.

Definition at line 44 of file cache_maintenance.cc.

◆ SIGMAINT

#define SIGMAINT   SIGRTMIN

Map maintenance signal.

Definition at line 42 of file cache_maintenance.cc.

Function Documentation

◆ link_down()

static bool link_down ( )
static

Set system wide inter process link down.

Returns
On success, returns true. On error, returns false. Check errno for details.

Definition at line 271 of file cache_maintenance.cc.

References Logging::error(), Logging::info(), pid_master, sem, SEM_OPEN_FILE, and shmid.

Referenced by link_up(), and stop_cache_maintenance().

◆ link_up()

static bool link_up ( )
static

Set system wide inter process link up.

Returns
On success, returns true. On error, returns false. Check errno for details.

Definition at line 172 of file cache_maintenance.cc.

References Logging::debug(), Logging::error(), Logging::info(), link_down(), master, pid_master, sem, SEM_OPEN_FILE, and shmid.

Referenced by start_cache_maintenance().

◆ maintenance_handler()

static void maintenance_handler ( int  sig,
__attribute__((unused)) siginfo_t *  si,
__attribute__((unused)) void *  uc 
)
static

Run maintenance handler.

Parameters
[in]sig- Signal, must be SIGMAINT.
[in]si
[in]uc

Definition at line 67 of file cache_maintenance.cc.

References Logging::info(), master, master_check(), SIGMAINT, and transcoder_cache_maintenance().

Referenced by start_timer().

◆ master_check()

static void master_check ( )
static

Check if a master is already running. We become master if not.

Definition at line 238 of file cache_maintenance.cc.

References Logging::info(), master, pid_master, sem, and Logging::trace().

Referenced by maintenance_handler().

◆ start_cache_maintenance()

bool start_cache_maintenance ( time_t  interval)

Start cache maintenance timer.

Parameters
[in]interval- Interval in seconds to run timer at.
Returns
On success, returns true. On error, returns false. Check errno for details.

Definition at line 319 of file cache_maintenance.cc.

References link_up(), and start_timer().

Referenced by ffmpegfs_init().

◆ start_timer()

static bool start_timer ( time_t  interval)
static

Start the maintenance timer at predefined interval.

Parameters
[in]interval- Timer interval in seconds.
Returns
On success, returns true. On error, returns false. Check errno for details.

Definition at line 89 of file cache_maintenance.cc.

References CLOCKID, Logging::error(), format_time(), maintenance_handler(), mask, SIGMAINT, timerid, and Logging::trace().

Referenced by start_cache_maintenance().

◆ stop_cache_maintenance()

bool stop_cache_maintenance ( )

Stop cache maintenance timer.

Returns
On success, returns true. On error, returns false. Check errno for details.

Definition at line 331 of file cache_maintenance.cc.

References link_down(), and stop_timer().

Referenced by ffmpegfs_destroy().

◆ stop_timer()

static bool stop_timer ( )
static

Stop the maintenance timer.

Returns
On success, returns true. On error, returns false. Check errno for details.

Definition at line 155 of file cache_maintenance.cc.

References Logging::error(), Logging::info(), and timerid.

Referenced by stop_cache_maintenance().

Variable Documentation

◆ mask

sigset_t mask
static

Process mask for timer.

Definition at line 46 of file cache_maintenance.cc.

Referenced by start_timer().

◆ master

bool master
static

If true, we are master.

Definition at line 52 of file cache_maintenance.cc.

Referenced by link_up(), maintenance_handler(), and master_check().

◆ pid_master

pid_t* pid_master
static

PID of master process.

Definition at line 51 of file cache_maintenance.cc.

Referenced by link_down(), link_up(), and master_check().

◆ sem

sem_t* sem
static

Semaphore used to synchronise between master and slave processes.

Definition at line 49 of file cache_maintenance.cc.

Referenced by link_down(), link_up(), and master_check().

◆ shmid

int shmid
static

Shared memory segment ID.

Definition at line 50 of file cache_maintenance.cc.

Referenced by link_down(), and link_up().

◆ timerid

timer_t timerid
static

Timer id.

Definition at line 47 of file cache_maintenance.cc.

Referenced by start_timer(), and stop_timer().