Skip to content

Commit 6d427c3

Browse files
Darwin: Make it possible to build with chip_system_config_use_dispatch=false
Note: This is for unit testing / development purposes only.
1 parent 3bc5667 commit 6d427c3

File tree

4 files changed

+24
-17
lines changed

4 files changed

+24
-17
lines changed

src/platform/Darwin/PlatformManagerImpl.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@
3535
#include <platform/PlatformManager.h>
3636

3737
// Include the non-inline definitions for the GenericPlatformManagerImpl<> template,
38+
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
3839
#include <platform/internal/GenericPlatformManagerImpl.ipp>
40+
#else
41+
#include <platform/internal/GenericPlatformManagerImpl_POSIX.ipp>
42+
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
3943

4044
#include <CoreFoundation/CoreFoundation.h>
4145
#include <tracing/metric_event.h>
@@ -64,7 +68,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
6468
ReturnErrorOnFailure(Internal::PosixConfig::Init());
6569
#endif // CHIP_DISABLE_PLATFORM_KVS
6670

67-
#if !CHIP_SYSTEM_CONFIG_USE_LIBEV
71+
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
6872
// Ensure there is a dispatch queue available
6973
static_cast<System::LayerSocketsLoop &>(DeviceLayer::SystemLayer()).SetDispatchQueue(GetWorkQueue());
7074
#endif
@@ -83,6 +87,7 @@ CHIP_ERROR PlatformManagerImpl::_InitChipStack()
8387
return CHIP_NO_ERROR;
8488
}
8589

90+
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
8691
CHIP_ERROR PlatformManagerImpl::_StartEventLoopTask()
8792
{
8893
auto expected = WorkQueueState::kSuspended;
@@ -128,12 +133,6 @@ void PlatformManagerImpl::_RunEventLoop()
128133
mRunLoopSem = nullptr;
129134
}
130135

131-
void PlatformManagerImpl::_Shutdown()
132-
{
133-
// Call up to the base class _Shutdown() to perform the bulk of the shutdown.
134-
GenericPlatformManagerImpl<ImplClass>::_Shutdown();
135-
}
136-
137136
CHIP_ERROR PlatformManagerImpl::_PostEvent(const ChipDeviceEvent * event)
138137
{
139138
const ChipDeviceEvent eventCopy = *event;
@@ -142,6 +141,7 @@ CHIP_ERROR PlatformManagerImpl::_PostEvent(const ChipDeviceEvent * event)
142141
});
143142
return CHIP_NO_ERROR;
144143
}
144+
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
145145

146146
#if CHIP_STACK_LOCK_TRACKING_ENABLED
147147
bool PlatformManagerImpl::_IsChipStackLockedByCurrentThread() const

src/platform/Darwin/PlatformManagerImpl.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525

2626
#include <lib/core/Global.h>
2727
#include <platform/Darwin/BleScannerDelegate.h>
28+
29+
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
2830
#include <platform/internal/GenericPlatformManagerImpl.h>
31+
#else
32+
#include <platform/internal/GenericPlatformManagerImpl_POSIX.h>
33+
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
2934

3035
#include <atomic>
3136
#include <dispatch/dispatch.h>
@@ -38,7 +43,12 @@ class BleScannerDelegate;
3843
/**
3944
* Concrete implementation of the PlatformManager singleton object for Darwin platforms.
4045
*/
41-
class PlatformManagerImpl final : public PlatformManager, public Internal::GenericPlatformManagerImpl<PlatformManagerImpl>
46+
class PlatformManagerImpl final : public PlatformManager,
47+
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
48+
public Internal::GenericPlatformManagerImpl<PlatformManagerImpl>
49+
#else
50+
public Internal::GenericPlatformManagerImpl_POSIX<PlatformManagerImpl>
51+
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
4252
{
4353
// Allow the PlatformManager interface class to delegate method calls to
4454
// the implementation methods provided by this class.
@@ -58,8 +68,8 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
5868
private:
5969
// ===== Methods that implement the PlatformManager abstract interface.
6070
CHIP_ERROR _InitChipStack();
61-
void _Shutdown();
6271

72+
#if CHIP_SYSTEM_CONFIG_USE_DISPATCH
6373
CHIP_ERROR _StartChipTimer(System::Clock::Timeout delay) { return CHIP_ERROR_NOT_IMPLEMENTED; };
6474
CHIP_ERROR _StartEventLoopTask();
6575
CHIP_ERROR _StopEventLoopTask();
@@ -69,6 +79,7 @@ class PlatformManagerImpl final : public PlatformManager, public Internal::Gener
6979
bool _TryLockChipStack() { return false; };
7080
void _UnlockChipStack(){};
7181
CHIP_ERROR _PostEvent(const ChipDeviceEvent * event);
82+
#endif // CHIP_SYSTEM_CONFIG_USE_DISPATCH
7283

7384
#if CHIP_STACK_LOCK_TRACKING_ENABLED
7485
bool _IsChipStackLockedByCurrentThread() const;

src/platform/Darwin/SystemPlatformConfig.h

-8
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ struct ChipDeviceEvent;
3434

3535
// ==================== Platform Adaptations ====================
3636

37-
#if !CHIP_SYSTEM_CONFIG_USE_LIBEV
38-
// FIXME: these should not be hardcoded here, it is set via build config
39-
// Need to exclude these for now in libev case
40-
#define CHIP_SYSTEM_CONFIG_POSIX_LOCKING 0
41-
#define CHIP_SYSTEM_CONFIG_FREERTOS_LOCKING 0
42-
#define CHIP_SYSTEM_CONFIG_NO_LOCKING 1
43-
#endif
44-
4537
#define CHIP_SYSTEM_CONFIG_PLATFORM_PROVIDES_TIME 1
4638
#define CHIP_SYSTEM_CONFIG_USE_POSIX_TIME_FUNCTS 1
4739
#define CHIP_SYSTEM_CONFIG_POOL_USE_HEAP 1

src/system/system.gni

+4
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ assert(
8080
chip_system_config_locking == "zephyr",
8181
"Please select a valid mutex implementation: posix, freertos, mbed, cmsis-rtos, zephyr, none")
8282

83+
assert(
84+
!chip_system_config_use_dispatch || chip_system_config_locking == "none",
85+
"When chip_system_config_use_dispatch is true, chip_system_config_locking must be 'none'")
86+
8387
assert(
8488
chip_system_config_clock == "clock_gettime" ||
8589
chip_system_config_clock == "gettimeofday",

0 commit comments

Comments
 (0)