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 fSnoozeCancel(create_sem(1, NULL)) 23 { 24 acquire_sem(fSnoozeCancel); 25 mutex_init(&fRequestLock, NULL); 26 } 27 28 29 Cookie::~Cookie() 30 { 31 delete_sem(fSnoozeCancel); 32 mutex_destroy(&fRequestLock); 33 } 34 35 36 status_t 37 Cookie::RegisterRequest(RPC::Request* req) 38 { 39 mutex_lock(&fRequestLock); 40 RequestEntry* ent = new RequestEntry; 41 if (ent == NULL) { 42 mutex_unlock(&fRequestLock); 43 return B_NO_MEMORY; 44 } 45 46 ent->fRequest = req; 47 ent->fNext = fRequests; 48 fRequests = ent; 49 mutex_unlock(&fRequestLock); 50 return B_OK; 51 } 52 53 54 status_t 55 Cookie::UnregisterRequest(RPC::Request* req) 56 { 57 mutex_lock(&fRequestLock); 58 RequestEntry* ent = fRequests; 59 RequestEntry* prev = NULL; 60 while (ent != NULL) { 61 if (ent->fRequest == req) { 62 if (prev == NULL) 63 fRequests = ent->fNext; 64 else 65 prev->fNext = ent->fNext; 66 delete ent; 67 } 68 69 prev = ent; 70 ent = ent->fNext; 71 } 72 mutex_unlock(&fRequestLock); 73 return B_OK; 74 } 75 76 77 status_t 78 Cookie::CancelAll() 79 { 80 release_sem(fSnoozeCancel); 81 82 mutex_lock(&fRequestLock); 83 RequestEntry* ent = fRequests; 84 while (ent != NULL) { 85 fFilesystem->Server()->WakeCall(ent->fRequest); 86 ent = ent->fNext; 87 } 88 mutex_unlock(&fRequestLock); 89 return B_OK; 90 } 91 92 93 OpenFileCookie::OpenFileCookie() 94 { 95 mutex_init(&fLocksLock, NULL); 96 } 97 98 99 OpenFileCookie::~OpenFileCookie() 100 { 101 mutex_destroy(&fLocksLock); 102 } 103 104