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

Disable usage of sched_setscheduler() on Apple devices #19

Merged
merged 1 commit into from
Nov 5, 2018
Merged
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
59 changes: 51 additions & 8 deletions dht.go.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,35 @@
#include <time.h>
#include <unistd.h>

// Add general block to detect OS
#ifdef _WIN32
//define something for Windows (32-bit and 64-bit, this part is common)
#ifdef _WIN64
//define something for Windows (64-bit only)
#else
//define something for Windows (32-bit only)
#endif
#elif __APPLE__
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_IPHONE
// iOS device
#elif TARGET_OS_MAC
// Other kinds of Mac OS
#else
# error "Unknown Apple platform"
#endif
#elif __linux__
// linux
#elif __unix__ // all unices not caught above
// Unix
#elif defined(_POSIX_VERSION)
// POSIX
#else
# error "Unknown compiler"
#endif

// GPIO direction: receive either output data to specific GPIO pin.
#define IN 0
#define OUT 1
Expand Down Expand Up @@ -293,6 +322,8 @@ static int gpio_read_seq_until_timeout(Pin *pin,
return 0;
}

#if !defined(__APPLE__) // sched_setscheduler() doesn't defined on Apple devices

// Used to gain maximum performance from device during
// receiving bunch of data from sensors like DHTxx.
static int set_max_priority(Error **err) {
Expand Down Expand Up @@ -321,6 +352,8 @@ static int set_default_priority(Error **err) {
return 0;
}

#endif // sched_setscheduler() doesn't defined on Apple devices

typedef struct {
int time;
int edge;
Expand Down Expand Up @@ -364,10 +397,16 @@ static int blink_n_times(int pin, int n, Error **err) {
// Activate DHTxx sensor and collect data sent by sensor for futher processing.
static int dial_DHTxx_and_read(int32_t pin, int32_t boostPerfFlag,
int32_t **arr, int32_t *arr_len, Error **err) {
// Set maximum priority for GPIO processing.
if (boostPerfFlag != FALSE && -1 == set_max_priority(err)) {
return -1;
}

#if !defined(__APPLE__)
// Set maximum priority for GPIO processing.
if (boostPerfFlag != FALSE && -1 == set_max_priority(err)) {
return -1;
}
#else
#warning "Darwin doesn't have sched_setscheduler, so parameter boostPerfFlag is useless on Apple devices"
#endif

Pin p;
if (-1 == gpio_export(pin, &p, err)) {
gpio_unexport(&p, err);
Expand Down Expand Up @@ -415,10 +454,14 @@ static int dial_DHTxx_and_read(int32_t pin, int32_t boostPerfFlag,
set_default_priority(err);
return -1;
}
// Return normal thread priority.
if (boostPerfFlag != FALSE && -1 == set_default_priority(err)) {
return -1;
}

#if !defined(__APPLE__)
// Return normal thread priority.
if (boostPerfFlag != FALSE && -1 == set_default_priority(err)) {
return -1;
}
#endif

return 0;
}

Expand Down