LwIPCoreLock.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. *
  3. * Copyright (c) 2021 Project CHIP Authors
  4. * Copyright (c) 2018 Nest Labs, Inc.
  5. * All rights reserved.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. */
  19. /* this file behaves like a config.h, comes first */
  20. #include <platform/internal/CHIPDeviceLayerInternal.h>
  21. #include <support/logging/CHIPLogging.h>
  22. namespace {
  23. SemaphoreHandle_t LwIPCoreLock;
  24. }
  25. namespace chip {
  26. namespace DeviceLayer {
  27. namespace Internal {
  28. CHIP_ERROR InitLwIPCoreLock(void)
  29. {
  30. if (LwIPCoreLock == NULL)
  31. {
  32. LwIPCoreLock = xSemaphoreCreateMutex();
  33. if (LwIPCoreLock == NULL)
  34. {
  35. ChipLogError(DeviceLayer, "Failed to create LwIP core lock");
  36. return CHIP_ERROR_NO_MEMORY;
  37. }
  38. }
  39. return CHIP_NO_ERROR;
  40. }
  41. } // namespace Internal
  42. } // namespace DeviceLayer
  43. } // namespace chip
  44. extern "C" void lock_lwip_core()
  45. {
  46. xSemaphoreTake(LwIPCoreLock, portMAX_DELAY);
  47. }
  48. extern "C" void unlock_lwip_core()
  49. {
  50. xSemaphoreGive(LwIPCoreLock);
  51. }