Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1559)

Unified Diff: native_client_sdk/src/libraries/nacl_io/kernel_object.h

Issue 18129008: Clean up locking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename mount functions Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: native_client_sdk/src/libraries/nacl_io/kernel_object.h
diff --git a/native_client_sdk/src/libraries/nacl_io/kernel_object.h b/native_client_sdk/src/libraries/nacl_io/kernel_object.h
index 6dc695999a9b68c919df2e74f43f3d1a40bca4f6..54108525936b36dc4020b79b402b3163c558b9c6 100644
--- a/native_client_sdk/src/libraries/nacl_io/kernel_object.h
+++ b/native_client_sdk/src/libraries/nacl_io/kernel_object.h
@@ -14,13 +14,15 @@
#include "nacl_io/error.h"
#include "nacl_io/kernel_handle.h"
#include "nacl_io/mount.h"
+#include "nacl_io/mount_node.h"
#include "nacl_io/path.h"
-// KernelObject provides basic functionality for threadsafe
-// access to kernel objects such as file descriptors and
-// file handles. It also provides access to the CWD for
-// path resolution.
+// KernelObject provides basic functionality for threadsafe access to kernel
+// objects such as the CWD, mount points, file descriptors and file handles.
+// All Kernel locks are private to ensure the lock order.
+//
+// All calls are assumed to be a relative path.
class KernelObject {
public:
typedef std::vector<ScopedKernelHandle> HandleMap_t;
@@ -29,11 +31,26 @@ class KernelObject {
KernelObject();
virtual ~KernelObject();
- // Find the mount for the given path, and acquires it.
- // Assumes |out_mount| and |out_path| are non-NULL.
- Error AcquireMountAndPath(const std::string& relpath,
+ // Attach the given Mount object at the specified path.
+ Error AttachMountAtPath(const ScopedMount& mnt, const std::string& path);
+
+ // Unmap the Mount object from the specified path and release it.
+ Error DetachMountAtPath(const std::string& path);
+
+ // Find the mount for the given path, and acquires it and return a
+ // path relative to the mount.
+ // Assumes |out_mount| and |rel_path| are non-NULL.
+ Error AcquireMountAndRelPath(const std::string& path,
+ ScopedMount* out_mount,
+ Path* rel_path);
+
+ // Find the mount and node for the given path, acquiring/creating it as
+ // specified by the |oflags|.
+ // Assumes |out_mount| and |out_node| are non-NULL.
+ Error AcquireMountAndNode(const std::string& path,
+ int oflags,
ScopedMount* out_mount,
- Path* out_path);
+ ScopedMountNode* out_node);
// Convert from FD to KernelHandle, and acquire the handle.
// Assumes |out_handle| is non-NULL.
@@ -48,20 +65,27 @@ class KernelObject {
void FreeAndReassignFD(int fd, const ScopedKernelHandle& handle);
void FreeFD(int fd);
- protected:
- Path GetAbsPathLocked(const std::string& path);
+ // Returns or sets CWD
+ std::string GetCWD();
+ Error SetCWD(const std::string& path);
- std::vector<int> free_fds_;
- std::string cwd_;
+ // Returns parts of the absolute path for the given relative path
+ Path GetAbsParts(const std::string& path);
+private:
+ std::string cwd_;
+ std::vector<int> free_fds_;
HandleMap_t handle_map_;
MountMap_t mounts_;
- // Kernel lock protects kernel wide resources such as the mount table...
- pthread_mutex_t kernel_lock_;
+ // Lock to protect free_fds_ and handle_map_.
+ pthread_mutex_t handle_lock_;
+
+ // Lock to protect handle_map_.
+ pthread_mutex_t mount_lock_;
- // Process lock protects process wide resources such as CWD, file handles...
- pthread_mutex_t process_lock_;
+ // Lock to protect cwd_.
+ pthread_mutex_t cwd_lock_;
DISALLOW_COPY_AND_ASSIGN(KernelObject);
};
« no previous file with comments | « native_client_sdk/src/libraries/nacl_io/kernel_handle.h ('k') | native_client_sdk/src/libraries/nacl_io/kernel_object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698