OpenMP: Update documentation of metadirective implementation status.
[gcc.git] / gcc / lockfile.h
blob2c1eb2ba5cb64cc2e2582b13f885fdc3783d4ad6
1 /* File locking.
2 Copyright (C) 2023-2025 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef LOCKFILE_H
21 #define LOCKFILE_H
23 /* Used to synchronize across multiple processes. */
24 class lockfile {
25 public:
26 /* Default constructor. */
27 lockfile (): fd (-1)
29 /* Intended constructor for use. Filename should not be used for anything
30 other than locking to prevent unintentional unlock. */
31 lockfile (std::string filename): lockfile ()
33 this->filename = std::move (filename);
35 lockfile (lockfile const& o): lockfile (o.filename)
38 void operator=(lockfile o)
40 unlock ();
41 this->filename = o.filename;
42 this->fd = o.fd;
43 o.fd = -1;
46 /* Unique write lock. No other lock can be held on this lockfile.
47 Blocking call. */
48 int lock_write ();
50 /* Unique write lock. No other lock can be held on this lockfile.
51 Only locks if this filelock is not locked by any other process.
52 Return whether locking was successful. */
53 int try_lock_write ();
55 /* Shared read lock. Only read lock can be held concurrently.
56 If write lock is already held by this process, it will be
57 changed to read lock.
58 Blocking call. */
59 int lock_read ();
61 /* Unlock all previously placed locks. */
62 void unlock ();
64 /* Returns whether any lock is held. */
65 bool
66 locked ()
68 return fd < 0;
71 /* Are lockfiles supported? */
72 static bool lockfile_supported ();
73 private:
74 std::string filename;
75 int fd;
78 #endif