arpadboda commented on a change in pull request #677: MINIFICPP-1065 - Fix UUID 
generation uniqueness and thread safety
URL: https://github.com/apache/nifi-minifi-cpp/pull/677#discussion_r344203428
 
 

 ##########
 File path: nanofi/src/core/cuuid.c
 ##########
 @@ -16,20 +16,78 @@
  * limitations under the License.
  */
 
+// This needs to be included first to let uuid.h sort out the system header 
collisions
+#ifndef WIN32
+#include "uuid.h"
+#endif
+
 #include "core/cuuid.h"
 
+#ifdef WIN32
+#include "Rpc.h"
+#include "Winsock2.h"
+#pragma comment(lib, "Rpcrt4.lib")
+#pragma comment(lib, "Ws2_32.lib")
+#else
+#include <pthread.h>
+#endif
+
+#ifdef WIN32
+  void windows_uuid_to_str(const UUID* uuid, char* out) {
+    RPC_CSTR str = NULL;
+    UuidToStringA(uuid, &str);
+    snprintf(out, 37, "%.36s", (char*)str);
+    RpcStringFreeA(&str);
+  }
+
+  void windows_uuid_generate_time(char* out) {
+    UUID uuid;
+    UuidCreateSequential(&uuid);
+    windows_uuid_to_str(&uuid, out);
+  }
+
+  void windows_uuid_generate_random(char* out) {
+    UUID uuid;
+    UuidCreate(&uuid);
+    windows_uuid_to_str(&uuid, out);
+  }
+#else
+  int generate_uuid_with_uuid_impl(unsigned int mode, char* out) {
+    static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+    static uuid_t* uuid_impl = NULL;
+    pthread_mutex_lock(&mutex);
+    if (uuid_impl == NULL) {
+      if (uuid_create(&uuid_impl) != UUID_RC_OK) {
+        return -1;
 
 Review comment:
   unlock here?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to