/* SPDX-License-Identifier: GPL-2.0-or-later */ /* * Copyright (C) 2019, Google Inc. * * event-dispatcher.cpp - Event dispatcher test */ #include #include #include #include #include #include #include #include "test.h" using namespace std; using namespace libcamera; static EventDispatcher *dispatcher; static bool interrupt; class EventDispatcherTest : public Test { protected: static void sigAlarmHandler(int) { cout << "SIGALARM received" << endl; if (interrupt) dispatcher->interrupt(); } int init() { dispatcher = Thread::current()->eventDispatcher(); struct sigaction sa = {}; sa.sa_handler = &sigAlarmHandler; sigaction(SIGALRM, &sa, nullptr); return 0; } int run() { Timer timer; /* Event processing interruption by signal. */ std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now(); timer.start(1000); struct itimerval itimer = {}; itimer.it_value.tv_usec = 500000; interrupt = false; setitimer(ITIMER_REAL, &itimer, nullptr); dispatcher->processEvents(); std::chrono::steady_clock::time_point stop = std::chrono::steady_clock::now(); std::chrono::steady_clock::duration duration = stop - start; int msecs = std::chrono::duration_cast(duration).count(); if (abs(msecs - 1000) > 50) { cout << "Event processing restart test failed" << endl; return TestFail; } /* Event processing interruption. */ timer.start(1000); dispatcher->interrupt(); dispatcher->processEvents(); if (!timer.isRunning()) { cout << "Event processing immediate interruption failed" << endl; return TestFail; } timer.start(1000); itimer.it_value.tv_usec = 500000; interrupt = true; setitimer(ITIMER_REAL, &itimer, nullptr); dispatcher->processEvents(); if (!timer.isRunning()) { cout << "Event processing delayed interruption failed" << endl; return TestFail; } return TestPass; } void cleanup() { } }; TEST_REGISTER(EventDispatcherTest) diff
blob: e34e8618db3d613536dd4685b24c9ee0bcd2debe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
 * Copyright (C) 2021, Google Inc.
 *
 * mutex.cpp - Mutex classes with clang thread safety annotation
 */

#include <libcamera/base/mutex.h>

/**
 * \file base/mutex.h
 * \brief Mutex classes with clang thread safety annotation
 */

namespace libcamera {

/**
 * \class Mutex
 * \brief std::mutex wrapper with clang thread safety annotation
 *
 * The Mutex class wraps a std::mutex instance to add clang thread safety
 * annotation support. The class exposes the same interface as std::mutex and
 * can be used as a transparent replacement. It integrates with the
 * MutexLocker and ConditionVariable classes.
 *
 * See https://en.cppreference.com/w/cpp/thread/mutex for the complete API
 * documentation.
 */

/**
 * \class MutexLocker
 * \brief std::unique_lock wrapper with clang thread safety annotation
 *
 * The MutexLocker class wraps a std::unique_lock instance to add clang thread
 * safety annotation support. The class exposes the same interface as
 * std::unique_lock and can be used as a transparent replacement. It integrates
 * with the Mutex and ConditionVariable classes.
 *
 * See https://en.cppreference.com/w/cpp/thread/unique_lock for the complete API
 * documentation.
 */

/**
 * \class ConditionVariable
 * \brief std::condition_variable wrapper integrating with MutexLocker
 *
 * The ConditionVariable class wraps a std::condition_variable instance to
 * integrate with the MutexLocker class. The class exposes the same interface as
 * std::condition_variable and can be used as a transparent replacement.
 *
 * See https://en.cppreference.com/w/cpp/thread/condition_variable for the
 * complete API documentation.
 */

} /* namespace libcamera */