Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MacOS #3

Merged
merged 3 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
.DS_Store
.idea
*.log
tmp/

# Created by https://www.toptal.com/developers/gitignore/api/c++
# Edit at https://www.toptal.com/developers/gitignore?templates=c++

### C++ ###
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# End of https://www.toptal.com/developers/gitignore/api/c++

5 changes: 5 additions & 0 deletions CometSearch/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ typedef __int64 comet_fileoffset_t;
#include <errno.h>
#include <pthread.h>
#define STRCMP_IGNORE_CASE(a,b) strcasecmp(a,b)
#ifdef __APPLE__
#define off64_t off_t
#define fseeko64 fseeko
#define ftello64 ftello
#endif
typedef off64_t comet_fileoffset_t;
#define comet_fseek(handle, offset, whence) fseeko64(handle, offset, whence)
#define comet_ftell(handle) ftello64(handle)
Expand Down
12 changes: 9 additions & 3 deletions CometSearch/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,10 @@ class ThreadPool
this->UNLOCK(&this->lock_);
//Threading::ThreadSleep(100);
// When threads are still busy and no jobs to do wait ...
#ifndef _WIN32
#if !defined(_WIN32) && !defined(__APPLE__)
pthread_yield();
#elif __APPLE__
sched_yield();
#else
std::this_thread::yield();
#endif
Expand Down Expand Up @@ -179,8 +181,10 @@ class ThreadPool
while(data_.size() > 0 && running_count_ >= (int)data_.size())
{
this->UNLOCK(&countlock_);
#ifndef _WIN32
#if !defined(_WIN32) && !defined(__APPLE__)
pthread_yield();
#elif __APPLE__
sched_yield();
#else
std::this_thread::yield();
#endif
Expand Down Expand Up @@ -336,8 +340,10 @@ inline void* threadStart(void* ptr)
{
tp->UNLOCK(&tp->lock_);

#ifndef _WIN32
#if !defined(_WIN32) && !defined(__APPLE__)
pthread_yield();
#elif __APPLE__
sched_yield();
#else
std::this_thread::yield();
#endif
Expand Down