xref: /haiku/src/add-ons/kernel/file_systems/nfs4/Cookie.cpp (revision 7d0b8c97865cb6a2ab1f534305913343de78ac50)
1 /*
2  * Copyright 2012 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Paweł Dziepak, pdziepak@quarnos.org
7  */
8 
9 
10 #include "Cookie.h"
11 
12 #include "Inode.h"
13 #include "Request.h"
14 
15 
16 vint64 OpenFileCookie::fLastOwnerId = 0;
17 
18 
19 Cookie::Cookie()
20 	:
21 	fRequests(NULL)
22 {
23 	mutex_init(&fRequestLock, NULL);
24 }
25 
26 
27 Cookie::~Cookie()
28 {
29 	mutex_destroy(&fRequestLock);
30 }
31 
32 
33 status_t
34 Cookie::RegisterRequest(RPC::Request* req)
35 {
36 	mutex_lock(&fRequestLock);
37 	RequestEntry* ent = new RequestEntry;
38 	if (ent == NULL) {
39 		mutex_unlock(&fRequestLock);
40 		return B_NO_MEMORY;
41 	}
42 
43 	ent->fRequest = req;
44 	ent->fNext = fRequests;
45 	fRequests = ent;
46 	mutex_unlock(&fRequestLock);
47 	return B_OK;
48 }
49 
50 
51 status_t
52 Cookie::UnregisterRequest(RPC::Request* req)
53 {
54 	mutex_lock(&fRequestLock);
55 	RequestEntry* ent = fRequests;
56 	RequestEntry* prev = NULL;
57 	while (ent != NULL) {
58 		if (ent->fRequest == req) {
59 			if (prev == NULL)
60 				fRequests = ent->fNext;
61 			else
62 				prev->fNext = ent->fNext;
63 			delete ent;
64 		}
65 
66 		prev = ent;
67 		ent = ent->fNext;
68 	}
69 	mutex_unlock(&fRequestLock);
70 	return B_OK;
71 }
72 
73 
74 status_t
75 Cookie::CancelAll()
76 {
77 	mutex_lock(&fRequestLock);
78 	RequestEntry* ent = fRequests;
79 	while (ent != NULL) {
80 		fFilesystem->Server()->WakeCall(ent->fRequest);
81 		ent = ent->fNext;
82 	}
83 	mutex_unlock(&fRequestLock);
84 	return B_OK;
85 }
86 
87 
88 OpenFileCookie::OpenFileCookie()
89 {
90 	mutex_init(&fLocksLock, NULL);
91 }
92 
93 
94 OpenFileCookie::~OpenFileCookie()
95 {
96 	mutex_destroy(&fLocksLock);
97 }
98 
99