Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b3a36ca5 authored by Dan Albert's avatar Dan Albert
Browse files

Fix gettid() on Windows.

Accidentally had this all hidden by an #ifndef _WIN32 when I wrote it.

Change-Id: I3a6afefe23b799ea7aa0f9a380f5a743673096d0
parent 0c4b3a31
Loading
Loading
Loading
Loading
+10 −7
Original line number Diff line number Diff line
@@ -17,6 +17,14 @@
#ifndef _LIBS_CUTILS_THREADS_H
#define _LIBS_CUTILS_THREADS_H

#include  <sys/types.h>

#if !defined(_WIN32)
#include <pthread.h>
#else
#include <windows.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif
@@ -29,10 +37,9 @@ extern "C" {
/***********************************************************************/
/***********************************************************************/

#if !defined(_WIN32)
extern pid_t gettid();

#include  <pthread.h>
#include  <sys/types.h>
#if !defined(_WIN32)

typedef struct {
    pthread_mutex_t   lock;
@@ -40,14 +47,10 @@ typedef struct {
    pthread_key_t     tls;
} thread_store_t;

extern pid_t gettid();

#define  THREAD_STORE_INITIALIZER  { PTHREAD_MUTEX_INITIALIZER, 0, 0 }

#else // !defined(_WIN32)

#include <windows.h>

typedef struct {
    int               lock_init;
    int               has_tls;
+21 −21
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@

#include "cutils/threads.h"

#if !defined(_WIN32)

// For gettid.
#if defined(__APPLE__)
#include "AvailabilityMacros.h"  // For MAC_OS_X_VERSION_MAX_ALLOWED
@@ -30,9 +28,29 @@
#include <syscall.h>
#include <unistd.h>
#elif defined(_WIN32)
#include <Windows.h>
#include <windows.h>
#endif

// No definition needed for Android because we'll just pick up bionic's copy.
#ifndef __ANDROID__
pid_t gettid() {
#if defined(__APPLE__)
  uint64_t owner;
  int rc = pthread_threadid_np(NULL, &owner);
  if (rc != 0) {
    abort();
  }
  return owner;
#elif defined(__linux__)
  return syscall(__NR_gettid);
#elif defined(_WIN32)
  return GetCurrentThreadId();
#endif
}
#endif  // __ANDROID__

#if !defined(_WIN32)

void*  thread_store_get( thread_store_t*  store )
{
    if (!store->has_tls)
@@ -58,24 +76,6 @@ extern void thread_store_set( thread_store_t* store,
    pthread_setspecific( store->tls, value );
}

// No definition needed for Android because we'll just pick up bionic's copy.
#ifndef __ANDROID__
pid_t gettid() {
#if defined(__APPLE__)
  uint64_t owner;
  int rc = pthread_threadid_np(NULL, &owner);
  if (rc != 0) {
    abort();
  }
  return owner;
#elif defined(__linux__)
  return syscall(__NR_gettid);
#elif defined(_WIN32)
  return (pid_t)GetCurrentThreadId();
#endif
}
#endif  // __ANDROID__

#else /* !defined(_WIN32) */
void*  thread_store_get( thread_store_t*  store )
{