UDK 3.2.7 C/C++ API Reference
|
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 00002 /************************************************************************* 00003 * 00004 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 00005 * 00006 * Copyright 2000, 2010 Oracle and/or its affiliates. 00007 * 00008 * OpenOffice.org - a multi-platform office productivity suite 00009 * 00010 * This file is part of OpenOffice.org. 00011 * 00012 * OpenOffice.org is free software: you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 3 00014 * only, as published by the Free Software Foundation. 00015 * 00016 * OpenOffice.org is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License version 3 for more details 00020 * (a copy is included in the LICENSE file that accompanied this code). 00021 * 00022 * You should have received a copy of the GNU Lesser General Public License 00023 * version 3 along with OpenOffice.org. If not, see 00024 * <http://www.openoffice.org/license.html> 00025 * for a copy of the LGPLv3 License. 00026 * 00027 ************************************************************************/ 00028 00029 #ifndef _SALHELPER_FUTUREQUEUE_HXX_ 00030 #define _SALHELPER_FUTUREQUEUE_HXX_ 00031 00032 #include <sal/types.h> 00033 #include <rtl/ref.hxx> 00034 #include <osl/mutex.hxx> 00035 #include <salhelper/future.hxx> 00036 #include <salhelper/queue.hxx> 00037 00038 namespace salhelper 00039 { 00040 00041 //---------------------------------------------------------------------------- 00042 00043 #ifndef SALHELPER_COPYCTOR_API 00044 #define SALHELPER_COPYCTOR_API(C) C (const C&); C& operator= (const C&) 00045 #endif 00046 00047 //---------------------------------------------------------------------------- 00048 00049 template<class element_type> 00050 class FutureQueue : protected osl::Mutex 00051 { 00054 typedef salhelper::Future<element_type> future_type; 00055 00056 salhelper::QueueBase< rtl::Reference<future_type> > m_aDelayed; 00057 salhelper::QueueBase< rtl::Reference<future_type> > m_aPresent; 00058 00061 SALHELPER_COPYCTOR_API(FutureQueue<element_type>); 00062 00063 public: 00066 inline FutureQueue() 00067 {} 00068 00071 inline ~FutureQueue() 00072 {} 00073 00076 inline void put (const element_type& element) 00077 { 00078 osl::MutexGuard aGuard (*this); 00079 00080 rtl::Reference<future_type> xFuture (m_aDelayed.get()); 00081 if (!xFuture.is()) 00082 { 00083 xFuture = new future_type(); 00084 m_aPresent.put (xFuture); 00085 } 00086 xFuture->set (element); 00087 } 00088 00091 inline rtl::Reference< salhelper::Future<element_type> > get() 00092 { 00093 osl::MutexGuard aGuard (*this); 00094 00095 rtl::Reference<future_type> xFuture (m_aPresent.get()); 00096 if (!xFuture.is()) 00097 { 00098 xFuture = new future_type(); 00099 m_aDelayed.put (xFuture); 00100 } 00101 return (xFuture); 00102 } 00103 }; 00104 00105 //---------------------------------------------------------------------------- 00106 00107 } // namespace salhelper 00108 00109 #endif /* !_SALHELPER_FUTUREQUEUE */ 00110 00111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */