mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Revision:
189:f392fc9709a3
Parent:
188:bcfe06ba3d64
--- a/platform/SingletonPtr.h	Thu Nov 08 11:46:34 2018 +0000
+++ b/platform/SingletonPtr.h	Wed Feb 20 22:31:08 2019 +0000
@@ -7,6 +7,7 @@
  */
 /* mbed Microcontroller Library
  * Copyright (c) 2006-2013 ARM Limited
+ * SPDX-License-Identifier: Apache-2.0
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +24,7 @@
 #ifndef SINGLETONPTR_H
 #define SINGLETONPTR_H
 
+#include <stdlib.h>
 #include <stdint.h>
 #include <new>
 #include "platform/mbed_assert.h"
@@ -88,7 +90,7 @@
      * @returns
      *   A pointer to the singleton
      */
-    T *get()
+    T *get() const
     {
         if (NULL == _ptr) {
             singleton_lock();
@@ -108,15 +110,30 @@
      * @returns
      *   A pointer to the singleton
      */
-    T *operator->()
+    T *operator->() const
     {
         return get();
     }
 
+    /** Get a reference to the underlying singleton
+     *
+     * @returns
+     *   A reference to the singleton
+     */
+    T &operator*() const
+    {
+        return *get();
+    }
+
     // This is zero initialized when in global scope
-    T *_ptr;
-    // Force data to be 4 byte aligned
-    uint32_t _data[(sizeof(T) + sizeof(uint32_t) - 1) / sizeof(uint32_t)];
+    mutable T *_ptr;
+#if __cplusplus >= 201103L
+    // Align data appropriately
+    alignas(T) mutable char _data[sizeof(T)];
+#else
+    // Force data to be 8 byte aligned
+    mutable uint64_t _data[(sizeof(T) + sizeof(uint64_t) - 1) / sizeof(uint64_t)];
+#endif
 };
 
 #endif