summaryrefslogtreecommitdiffstats
path: root/runtime/base/scoped_flock.h
diff options
context:
space:
mode:
authorNarayan Kamath <narayan@google.com>2014-06-09 16:50:19 +0100
committerNarayan Kamath <narayan@google.com>2014-06-10 11:25:06 +0100
commitd1c606f280797be81e2592c483869a6ec836a9f3 (patch)
treef49689281100d0fccdc5493f1a2567b435a247ea /runtime/base/scoped_flock.h
parentfbc2b1747e7e3d06f214f801f53218a1d4bf2dbe (diff)
downloadart-d1c606f280797be81e2592c483869a6ec836a9f3.zip
art-d1c606f280797be81e2592c483869a6ec836a9f3.tar.gz
art-d1c606f280797be81e2592c483869a6ec836a9f3.tar.bz2
Add locking around boot image generation.
If zygote aborts due to an error, it will restart and spawn another dex2oat process while the old one is still running. If this happens fast enough, the system will eventually need a kernel reboot since neither the zygote nor dex2oat are killable. This brings boot image generation in line with dex2oat generation, which uses a similar pattern of advisory locking. bug: 15415316 Change-Id: Iaccd274d3d96ab002b04e246ec4b3ef9a422ff7c
Diffstat (limited to 'runtime/base/scoped_flock.h')
-rw-r--r--runtime/base/scoped_flock.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/runtime/base/scoped_flock.h b/runtime/base/scoped_flock.h
new file mode 100644
index 0000000..26b4eb0
--- /dev/null
+++ b/runtime/base/scoped_flock.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ART_RUNTIME_BASE_SCOPED_FLOCK_H_
+#define ART_RUNTIME_BASE_SCOPED_FLOCK_H_
+
+#include <memory>
+#include <string>
+
+#include "base/macros.h"
+#include "os.h"
+
+namespace art {
+
+class ScopedFlock {
+ public:
+ ScopedFlock();
+
+ // Attempts to acquire an exclusive file lock (see flock(2)) on the file
+ // at filename, and blocks until it can do so.
+ //
+ // Returns true if the lock could be acquired, or false if an error
+ // occurred. It is an error if the file does not exist, or if its inode
+ // changed (usually due to a new file being created at the same path)
+ // between attempts to lock it.
+ bool Init(const char* filename, std::string* error_msg);
+
+ // Returns the (locked) file associated with this instance.
+ File* GetFile();
+ ~ScopedFlock();
+ private:
+ std::unique_ptr<File> file_;
+ DISALLOW_COPY_AND_ASSIGN(ScopedFlock);
+};
+
+} // namespace art
+
+#endif // ART_RUNTIME_BASE_SCOPED_FLOCK_H_