2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
16 LockOwner::LockOwner(uint32 owner
)
24 memset(fStateId
, 0, sizeof(fStateId
));
25 mutex_init(&fLock
, NULL
);
29 LockOwner::~LockOwner()
31 mutex_destroy(&fLock
);
35 LockInfo::LockInfo(LockOwner
* owner
)
39 ASSERT(owner
!= NULL
);
51 LockInfo::operator==(const struct flock
& lock
) const
53 bool eof
= lock
.l_len
+ lock
.l_start
== OFF_MAX
;
54 uint64 start
= static_cast<uint64
>(lock
.l_start
);
55 uint64 length
= static_cast<uint64
>(lock
.l_len
);
57 return fStart
== start
&& (fLength
== length
58 || (eof
&& fLength
== UINT64_MAX
));
63 LockInfo::operator==(const LockInfo
& lock
) const
65 return fOwner
== lock
.fOwner
&& fStart
== lock
.fStart
66 && fLength
== lock
.fLength
&& fType
== lock
.fType
;
70 Cookie::Cookie(FileSystem
* fileSystem
)
72 fFileSystem(fileSystem
),
74 fSnoozeCancel(create_sem(1, NULL
))
76 acquire_sem(fSnoozeCancel
);
77 mutex_init(&fRequestLock
, NULL
);
83 delete_sem(fSnoozeCancel
);
84 mutex_destroy(&fRequestLock
);
89 Cookie::RegisterRequest(RPC::Request
* request
)
91 ASSERT(request
!= NULL
);
93 RequestEntry
* entry
= new RequestEntry
;
97 MutexLocker
_(fRequestLock
);
98 entry
->fRequest
= request
;
99 entry
->fNext
= fRequests
;
107 Cookie::UnregisterRequest(RPC::Request
* request
)
109 ASSERT(request
!= NULL
);
111 MutexLocker
_(fRequestLock
);
112 RequestEntry
* entry
= fRequests
;
113 RequestEntry
* previous
= NULL
;
114 while (entry
!= NULL
) {
115 if (entry
->fRequest
== request
) {
116 if (previous
== NULL
)
117 fRequests
= entry
->fNext
;
119 previous
->fNext
= entry
->fNext
;
125 entry
= entry
->fNext
;
135 release_sem(fSnoozeCancel
);
137 MutexLocker
_(fRequestLock
);
138 RequestEntry
* entry
= fRequests
;
139 while (entry
!= NULL
) {
140 fFileSystem
->Server()->WakeCall(entry
->fRequest
);
141 entry
= entry
->fNext
;
148 OpenStateCookie::OpenStateCookie(FileSystem
* fileSystem
)
155 OpenFileCookie::OpenFileCookie(FileSystem
* fileSystem
)
157 OpenStateCookie(fileSystem
),
164 OpenFileCookie::AddLock(LockInfo
* lock
)
166 ASSERT(lock
!= NULL
);
168 lock
->fCookieNext
= fLocks
;
174 OpenFileCookie::RemoveLock(LockInfo
* lock
, LockInfo
* previous
)
176 if (previous
!= NULL
)
177 previous
->fCookieNext
= lock
->fCookieNext
;
179 ASSERT(previous
== NULL
&& fLocks
== lock
);
180 fLocks
= lock
->fCookieNext
;
185 OpenDirCookie::OpenDirCookie(FileSystem
* fileSystem
)
193 OpenDirCookie::~OpenDirCookie()
195 if (fSnapshot
!= NULL
)
196 fSnapshot
->ReleaseReference();
200 OpenAttrCookie::OpenAttrCookie(FileSystem
* fileSystem
)
202 OpenStateCookie(fileSystem
)