bump product version to 6.3.0.0.beta1
[LibreOffice.git] / avmedia / source / vlc / inc / wrapper / ThreadsafeQueue.hxx
blobf76a08fda2763abdf08cb6d8be20d9adb1665e9b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_AVMEDIA_SOURCE_VLC_INC_WRAPPER_THREADSAFEQUEUE_HXX
20 #define INCLUDED_AVMEDIA_SOURCE_VLC_INC_WRAPPER_THREADSAFEQUEUE_HXX
21 #include <queue>
22 #include <iostream>
23 #include <osl/mutex.hxx>
24 #include <osl/conditn.hxx>
26 namespace avmedia
28 namespace vlc
30 namespace wrapper
32 template<class T>
33 class ThreadsafeQueue
35 public:
36 ThreadsafeQueue(const ThreadsafeQueue&) = delete;
37 const ThreadsafeQueue& operator=(const ThreadsafeQueue&) = delete;
39 ThreadsafeQueue();
41 void push( const T& data );
42 void pop( T& data );
44 private:
45 std::queue< T > mQueue;
46 mutable ::osl::Mutex mMutex;
47 ::osl::Condition mCondition;
50 template<class T>
51 ThreadsafeQueue<T>::ThreadsafeQueue()
55 template<class T>
56 void ThreadsafeQueue<T>::push( const T& data )
58 ::osl::MutexGuard guard( mMutex );
59 mQueue.push( data );
60 mMutex.release();
61 mCondition.set();
64 template<class T>
65 void ThreadsafeQueue<T>::pop( T& data )
67 mCondition.wait();
68 ::osl::MutexGuard guard( mMutex );
69 while ( mQueue.empty() )
71 mMutex.release();
72 mCondition.wait();
73 mMutex.acquire();
75 data = mQueue.front();
76 mQueue.pop();
82 #endif
83 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */