GCC Middle and Back End API Reference
lockfile Class Reference

#include <lockfile.h>

Public Member Functions

 lockfile ()
 
 lockfile (std::string filename)
 
 lockfile (lockfile const &o)
 
void operator= (lockfile o)
 
int lock_write ()
 
int try_lock_write ()
 
int lock_read ()
 
void unlock ()
 
bool locked ()
 

Static Public Member Functions

static bool lockfile_supported ()
 

Private Attributes

std::string filename
 
int fd
 

Detailed Description

File locking.
   Copyright (C) 2023-2025 Free Software Foundation, Inc.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.   
Used to synchronize across multiple processes.   

Constructor & Destructor Documentation

◆ lockfile() [1/3]

lockfile::lockfile ( )
inline

References fd.

Referenced by lockfile(), lockfile(), and operator=().

◆ lockfile() [2/3]

lockfile::lockfile ( std::string filename)
inline

References filename, and lockfile().

◆ lockfile() [3/3]

lockfile::lockfile ( lockfile const & o)
inline

References filename, and lockfile().

Member Function Documentation

◆ lock_read()

int lockfile::lock_read ( )
Shared read lock.  Only read lock can be held concurrently.
If write lock is already held by this process, it will be
changed to read lock.
Blocking call.   

References errno, fd, filename, and SEEK_SET.

Referenced by run_gcc().

◆ lock_write()

int lockfile::lock_write ( )
fcntl.h may exist without expected contents.   
Unique write lock.  No other lock can be held on this lockfile.
Blocking call.   

References errno, fd, filename, and SEEK_SET.

Referenced by run_gcc().

◆ locked()

bool lockfile::locked ( )
inline

References fd.

◆ lockfile_supported()

bool lockfile::lockfile_supported ( )
static
Are lockfiles supported?   

Referenced by run_gcc().

◆ operator=()

void lockfile::operator= ( lockfile o)
inline

References fd, filename, lockfile(), and unlock().

◆ try_lock_write()

int lockfile::try_lock_write ( )
Unique write lock.  No other lock can be held on this lockfile.
Only locks if this filelock is not locked by any other process.
Return whether locking was successful.   

References fd, filename, and SEEK_SET.

◆ unlock()

void lockfile::unlock ( )
Unlock all previously placed locks.   

References fd, and SEEK_SET.

Referenced by operator=(), and run_gcc().

Field Documentation

◆ fd

int lockfile::fd
private

◆ filename

std::string lockfile::filename
private

The documentation for this class was generated from the following files: