Skip to content

Commit 95cae32

Browse files
committed
GstWebRTC-related backports from main
1 parent 3946d5a commit 95cae32

39 files changed

Lines changed: 2430 additions & 644 deletions

Source/WTF/wtf/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ set(WTF_PUBLIC_HEADERS
329329
WeakHashSet.h
330330
WeakPtr.h
331331
WeakRandom.h
332+
WeakRandomNumber.h
332333
WindowsExtras.h
333334
WordLock.h
334335
WorkQueue.h
@@ -346,6 +347,8 @@ set(WTF_PUBLIC_HEADERS
346347
dtoa/strtod.h
347348
dtoa/utils.h
348349

350+
glib/GThreadSafeWeakPtr.h
351+
349352
persistence/PersistentCoder.h
350353
persistence/PersistentCoders.h
351354
persistence/PersistentDecoder.h
@@ -498,6 +501,7 @@ set(WTF_SOURCES
498501
WTFAssertions.cpp
499502
WTFConfig.cpp
500503
WallTime.cpp
504+
WeakRandomNumber.cpp
501505
WordLock.cpp
502506
WorkQueue.cpp
503507
WorkerPool.cpp
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright (C) 2006-2022 Apple Inc. All rights reserved.
3+
* (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
4+
* Copyright (C) 2013 Andrew Bortz. All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
*
15+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
16+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
19+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
28+
#include "config.h"
29+
#include <wtf/WeakRandomNumber.h>
30+
31+
#include <wtf/WeakRandom.h>
32+
33+
namespace WTF {
34+
35+
template<> unsigned weakRandomNumber<unsigned>()
36+
{
37+
// We don't care about thread safety. WeakRandom just uses POD types,
38+
// and racy access just increases randomness.
39+
static WeakRandom s_weakRandom;
40+
return s_weakRandom.getUint32();
41+
}
42+
43+
#if PLATFORM(COCOA)
44+
45+
// Older versions of Safari frameworks were using weakRandomUint32.
46+
// Remove this once we no longer need to support those.
47+
48+
WTF_EXPORT_PRIVATE unsigned weakRandomUint32();
49+
50+
unsigned weakRandomUint32()
51+
{
52+
return random();
53+
}
54+
55+
#endif
56+
57+
}

Source/WTF/wtf/WeakRandomNumber.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (C) 2022 Apple Inc. All rights reserved.
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14+
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21+
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24+
*/
25+
26+
#pragma once
27+
28+
namespace WTF {
29+
30+
template<typename IntegerType> IntegerType weakRandomNumber() = delete;
31+
32+
// Returns a cheap pseudo-random number in the range [0, UINT_MAX].
33+
template<> WTF_EXPORT_PRIVATE unsigned weakRandomNumber<unsigned>();
34+
35+
}
36+
37+
using WTF::weakRandomNumber;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Copyright (C) 2024 Igalia S.L.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Library General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Library General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Library General Public License
15+
* along with this library; see the file COPYING.LIB. If not, write to
16+
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
* Boston, MA 02110-1301, USA.
18+
*
19+
*/
20+
21+
#pragma once
22+
23+
#if USE(GLIB)
24+
25+
#include "GRefPtr.h"
26+
27+
#include <glib-object.h>
28+
#include <wtf/Noncopyable.h>
29+
30+
namespace WTF {
31+
32+
template <typename T> class GThreadSafeWeakPtr {
33+
WTF_MAKE_NONCOPYABLE(GThreadSafeWeakPtr);
34+
public:
35+
GThreadSafeWeakPtr()
36+
{
37+
g_weak_ref_init(&m_ref, nullptr);
38+
}
39+
40+
explicit GThreadSafeWeakPtr(T* ptr)
41+
{
42+
RELEASE_ASSERT(!ptr || G_IS_OBJECT(ptr));
43+
g_weak_ref_init(&m_ref, ptr);
44+
}
45+
46+
GThreadSafeWeakPtr(GThreadSafeWeakPtr&& other)
47+
{
48+
auto strongRef = other.get();
49+
g_weak_ref_set(&other.m_ref, nullptr);
50+
g_weak_ref_init(&m_ref, strongRef.get());
51+
}
52+
53+
~GThreadSafeWeakPtr()
54+
{
55+
g_weak_ref_clear(&m_ref);
56+
}
57+
58+
WARN_UNUSED_RETURN GRefPtr<T> get()
59+
{
60+
return adoptGRef(reinterpret_cast<T*>(g_weak_ref_get(&m_ref)));
61+
}
62+
63+
void reset(T* ptr = nullptr)
64+
{
65+
RELEASE_ASSERT(!ptr || G_IS_OBJECT(ptr));
66+
g_weak_ref_set(&m_ref, ptr);
67+
}
68+
69+
GThreadSafeWeakPtr& operator=(std::nullptr_t)
70+
{
71+
reset();
72+
return *this;
73+
}
74+
75+
private:
76+
GWeakRef m_ref;
77+
};
78+
79+
} // namespace WTF
80+
81+
using WTF::GThreadSafeWeakPtr;
82+
83+
#endif // USE(GLIB)

0 commit comments

Comments
 (0)