1 /* 2 * Copyright 2007, Haiku, Inc. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Axel Dörfler, axeld@pinc-software.de 7 */ 8 9 10 #include <DirectMessageTarget.h> 11 12 13 namespace BPrivate { 14 15 16 BDirectMessageTarget::BDirectMessageTarget() 17 : 18 fReferenceCount(1), 19 fClosed(false) 20 { 21 } 22 23 24 BDirectMessageTarget::~BDirectMessageTarget() 25 { 26 } 27 28 29 bool 30 BDirectMessageTarget::AddMessage(BMessage* message) 31 { 32 if (fClosed) { 33 delete message; 34 return false; 35 } 36 37 fQueue.AddMessage(message); 38 return true; 39 } 40 41 42 void 43 BDirectMessageTarget::Close() 44 { 45 fClosed = true; 46 } 47 48 49 void 50 BDirectMessageTarget::Acquire() 51 { 52 atomic_add(&fReferenceCount, 1); 53 } 54 55 56 void 57 BDirectMessageTarget::Release() 58 { 59 if (atomic_add(&fReferenceCount, -1) == 1) 60 delete this; 61 } 62 63 } // namespace BPrivate 64