Merge pull request #1958 from DDRBoxman/format
Apply clang-format to objective c code
This commit is contained in:
@@ -54,7 +54,8 @@ static double ns_time_compute_factor()
|
||||
static uint64_t ns_time_full()
|
||||
{
|
||||
static double factor = 0.;
|
||||
if (factor == 0.) factor = ns_time_compute_factor();
|
||||
if (factor == 0.)
|
||||
factor = ns_time_compute_factor();
|
||||
return (uint64_t)(mach_absolute_time() * factor);
|
||||
}
|
||||
|
||||
@@ -72,18 +73,19 @@ static time_func ns_time_select_func()
|
||||
uint64_t os_gettime_ns(void)
|
||||
{
|
||||
static time_func f = NULL;
|
||||
if (!f) f = ns_time_select_func();
|
||||
if (!f)
|
||||
f = ns_time_select_func();
|
||||
return f();
|
||||
}
|
||||
|
||||
/* gets the location [domain mask]/Library/Application Support/[name] */
|
||||
static int os_get_path_internal(char *dst, size_t size, const char *name,
|
||||
NSSearchPathDomainMask domainMask)
|
||||
NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
|
||||
if([paths count] == 0)
|
||||
if ([paths count] == 0)
|
||||
bcrash("Could not get home directory (platform-cocoa)");
|
||||
|
||||
NSString *application_support = paths[0];
|
||||
@@ -96,12 +98,12 @@ static int os_get_path_internal(char *dst, size_t size, const char *name,
|
||||
}
|
||||
|
||||
static char *os_get_path_ptr_internal(const char *name,
|
||||
NSSearchPathDomainMask domainMask)
|
||||
NSSearchPathDomainMask domainMask)
|
||||
{
|
||||
NSArray *paths = NSSearchPathForDirectoriesInDomains(
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
NSApplicationSupportDirectory, domainMask, YES);
|
||||
|
||||
if([paths count] == 0)
|
||||
if ([paths count] == 0)
|
||||
bcrash("Could not get home directory (platform-cocoa)");
|
||||
|
||||
NSString *application_support = paths[0];
|
||||
@@ -109,7 +111,7 @@ static char *os_get_path_ptr_internal(const char *name,
|
||||
NSUInteger len = [application_support
|
||||
lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
|
||||
|
||||
char *path_ptr = bmalloc(len+1);
|
||||
char *path_ptr = bmalloc(len + 1);
|
||||
|
||||
path_ptr[len] = 0;
|
||||
|
||||
@@ -174,47 +176,47 @@ char *os_get_executable_path_ptr(const char *name)
|
||||
struct os_cpu_usage_info {
|
||||
int64_t last_cpu_time;
|
||||
int64_t last_sys_time;
|
||||
int core_count;
|
||||
int core_count;
|
||||
};
|
||||
|
||||
static inline void add_time_value(time_value_t *dst, time_value_t *a,
|
||||
time_value_t *b)
|
||||
time_value_t *b)
|
||||
{
|
||||
dst->microseconds = a->microseconds + b->microseconds;
|
||||
dst->seconds = a->seconds + b->seconds;
|
||||
dst->seconds = a->seconds + b->seconds;
|
||||
|
||||
if (dst->microseconds >= 1000000) {
|
||||
dst->seconds += dst->microseconds / 1000000;
|
||||
dst->seconds += dst->microseconds / 1000000;
|
||||
dst->microseconds %= 1000000;
|
||||
}
|
||||
}
|
||||
|
||||
static bool get_time_info(int64_t *cpu_time, int64_t *sys_time)
|
||||
{
|
||||
mach_port_t task = mach_task_self();
|
||||
mach_port_t task = mach_task_self();
|
||||
struct task_thread_times_info thread_data;
|
||||
struct task_basic_info_64 task_data;
|
||||
mach_msg_type_number_t count;
|
||||
kern_return_t kern_ret;
|
||||
time_value_t cur_time;
|
||||
struct task_basic_info_64 task_data;
|
||||
mach_msg_type_number_t count;
|
||||
kern_return_t kern_ret;
|
||||
time_value_t cur_time;
|
||||
|
||||
*cpu_time = 0;
|
||||
*sys_time = 0;
|
||||
|
||||
count = TASK_THREAD_TIMES_INFO_COUNT;
|
||||
kern_ret = task_info(task, TASK_THREAD_TIMES_INFO,
|
||||
(task_info_t)&thread_data, &count);
|
||||
(task_info_t)&thread_data, &count);
|
||||
if (kern_ret != KERN_SUCCESS)
|
||||
return false;
|
||||
|
||||
count = TASK_BASIC_INFO_64_COUNT;
|
||||
kern_ret = task_info(task, TASK_BASIC_INFO_64,
|
||||
(task_info_t)&task_data, &count);
|
||||
kern_ret = task_info(task, TASK_BASIC_INFO_64, (task_info_t)&task_data,
|
||||
&count);
|
||||
if (kern_ret != KERN_SUCCESS)
|
||||
return false;
|
||||
|
||||
add_time_value(&cur_time, &thread_data.user_time,
|
||||
&thread_data.system_time);
|
||||
&thread_data.system_time);
|
||||
add_time_value(&cur_time, &cur_time, &task_data.user_time);
|
||||
add_time_value(&cur_time, &cur_time, &task_data.system_time);
|
||||
|
||||
@@ -238,7 +240,7 @@ os_cpu_usage_info_t *os_cpu_usage_info_start(void)
|
||||
|
||||
double os_cpu_usage_info_query(os_cpu_usage_info_t *info)
|
||||
{
|
||||
int64_t sys_time, cpu_time;
|
||||
int64_t sys_time, cpu_time;
|
||||
int64_t sys_time_delta, cpu_time_delta;
|
||||
|
||||
if (!info || !get_time_info(&cpu_time, &sys_time))
|
||||
@@ -254,7 +256,7 @@ double os_cpu_usage_info_query(os_cpu_usage_info_t *info)
|
||||
info->last_cpu_time = cpu_time;
|
||||
|
||||
return (double)sys_time_delta * 100.0 / (double)cpu_time_delta /
|
||||
(double)info->core_count;
|
||||
(double)info->core_count;
|
||||
}
|
||||
|
||||
void os_cpu_usage_info_destroy(os_cpu_usage_info_t *info)
|
||||
@@ -272,7 +274,7 @@ os_performance_token_t *os_request_high_performance(const char *reason)
|
||||
return nil;
|
||||
|
||||
//taken from http://stackoverflow.com/a/20100906
|
||||
id activity = [pi beginActivityWithOptions:0x00FFFFFF
|
||||
id activity = [pi beginActivityWithOptions:0x00FFFFFF
|
||||
reason:@(reason)];
|
||||
|
||||
return CFBridgingRetain(activity);
|
||||
@@ -302,11 +304,11 @@ os_inhibit_t *os_inhibit_sleep_create(const char *reason)
|
||||
{
|
||||
struct os_inhibit_info *info = bzalloc(sizeof(*info));
|
||||
if (!reason)
|
||||
info->reason = CFStringCreateWithCString(kCFAllocatorDefault,
|
||||
reason, kCFStringEncodingUTF8);
|
||||
info->reason = CFStringCreateWithCString(
|
||||
kCFAllocatorDefault, reason, kCFStringEncodingUTF8);
|
||||
else
|
||||
info->reason = CFStringCreateCopy(kCFAllocatorDefault,
|
||||
CFSTR(""));
|
||||
info->reason =
|
||||
CFStringCreateCopy(kCFAllocatorDefault, CFSTR(""));
|
||||
|
||||
return info;
|
||||
}
|
||||
@@ -321,12 +323,11 @@ bool os_inhibit_sleep_set_active(os_inhibit_t *info, bool active)
|
||||
return false;
|
||||
|
||||
if (active) {
|
||||
IOPMAssertionDeclareUserActivity(info->reason,
|
||||
kIOPMUserActiveLocal, &info->user_id);
|
||||
IOPMAssertionDeclareUserActivity(
|
||||
info->reason, kIOPMUserActiveLocal, &info->user_id);
|
||||
success = IOPMAssertionCreateWithName(
|
||||
kIOPMAssertionTypeNoDisplaySleep,
|
||||
kIOPMAssertionLevelOn, info->reason,
|
||||
&info->sleep_id);
|
||||
kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn,
|
||||
info->reason, &info->sleep_id);
|
||||
|
||||
if (success != kIOReturnSuccess) {
|
||||
blog(LOG_WARNING, "Failed to disable sleep");
|
||||
@@ -361,16 +362,16 @@ static void os_get_cores_internal(void)
|
||||
core_count_initialized = true;
|
||||
|
||||
size_t size;
|
||||
int ret;
|
||||
int ret;
|
||||
|
||||
size = sizeof(physical_cores);
|
||||
ret = sysctlbyname("machdep.cpu.core_count", &physical_cores,
|
||||
&size, NULL, 0);
|
||||
ret = sysctlbyname("machdep.cpu.core_count", &physical_cores, &size,
|
||||
NULL, 0);
|
||||
if (ret != 0)
|
||||
return;
|
||||
|
||||
ret = sysctlbyname("machdep.cpu.thread_count", &logical_cores,
|
||||
&size, NULL, 0);
|
||||
ret = sysctlbyname("machdep.cpu.thread_count", &logical_cores, &size,
|
||||
NULL, 0);
|
||||
}
|
||||
|
||||
int os_get_physical_cores(void)
|
||||
@@ -390,8 +391,8 @@ int os_get_logical_cores(void)
|
||||
static inline bool os_get_sys_memory_usage_internal(vm_statistics_t vmstat)
|
||||
{
|
||||
mach_msg_type_number_t out_count = HOST_VM_INFO_COUNT;
|
||||
if (host_statistics(mach_host_self(), HOST_VM_INFO,
|
||||
(host_info_t)vmstat, &out_count) != KERN_SUCCESS)
|
||||
if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)vmstat,
|
||||
&out_count) != KERN_SUCCESS)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -409,8 +410,8 @@ uint64_t os_get_sys_free_size(void)
|
||||
typedef task_basic_info_data_t mach_task_basic_info_data_t;
|
||||
#endif
|
||||
|
||||
static inline bool os_get_proc_memory_usage_internal(
|
||||
mach_task_basic_info_data_t *taskinfo)
|
||||
static inline bool
|
||||
os_get_proc_memory_usage_internal(mach_task_basic_info_data_t *taskinfo)
|
||||
{
|
||||
#ifdef MACH_TASK_BASIC_INFO
|
||||
const task_flavor_t flavor = MACH_TASK_BASIC_INFO;
|
||||
@@ -419,8 +420,8 @@ static inline bool os_get_proc_memory_usage_internal(
|
||||
const task_flavor_t flavor = TASK_BASIC_INFO;
|
||||
mach_msg_type_number_t out_count = TASK_BASIC_INFO_COUNT;
|
||||
#endif
|
||||
if (task_info(mach_task_self(), flavor,
|
||||
(task_info_t)taskinfo, &out_count) != KERN_SUCCESS)
|
||||
if (task_info(mach_task_self(), flavor, (task_info_t)taskinfo,
|
||||
&out_count) != KERN_SUCCESS)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -432,7 +433,7 @@ bool os_get_proc_memory_usage(os_proc_memory_usage_t *usage)
|
||||
return false;
|
||||
|
||||
usage->resident_size = taskinfo.resident_size;
|
||||
usage->virtual_size = taskinfo.virtual_size;
|
||||
usage->virtual_size = taskinfo.virtual_size;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -461,8 +462,8 @@ char *cfstr_copy_cstr(CFStringRef cfstring, CFStringEncoding cfstring_encoding)
|
||||
return NULL;
|
||||
|
||||
// Try the quick way to obtain the buffer
|
||||
const char *tmp_buffer = CFStringGetCStringPtr(cfstring,
|
||||
cfstring_encoding);
|
||||
const char *tmp_buffer =
|
||||
CFStringGetCStringPtr(cfstring, cfstring_encoding);
|
||||
|
||||
if (tmp_buffer != NULL)
|
||||
return bstrdup(tmp_buffer);
|
||||
@@ -486,8 +487,8 @@ char *cfstr_copy_cstr(CFStringRef cfstring, CFStringEncoding cfstring_encoding)
|
||||
}
|
||||
|
||||
// Copy CFString in requested encoding to buffer
|
||||
Boolean success =
|
||||
CFStringGetCString(cfstring, buffer, max_size, cfstring_encoding);
|
||||
Boolean success = CFStringGetCString(cfstring, buffer, max_size,
|
||||
cfstring_encoding);
|
||||
|
||||
if (!success) {
|
||||
bfree(buffer);
|
||||
@@ -500,15 +501,15 @@ char *cfstr_copy_cstr(CFStringRef cfstring, CFStringEncoding cfstring_encoding)
|
||||
* Returns true on success or false on failure.
|
||||
* In case of failure, the dstr capacity but not size is changed.
|
||||
*/
|
||||
bool cfstr_copy_dstr(CFStringRef cfstring,
|
||||
CFStringEncoding cfstring_encoding, struct dstr *str)
|
||||
bool cfstr_copy_dstr(CFStringRef cfstring, CFStringEncoding cfstring_encoding,
|
||||
struct dstr *str)
|
||||
{
|
||||
if (!cfstring)
|
||||
return false;
|
||||
|
||||
// Try the quick way to obtain the buffer
|
||||
const char *tmp_buffer = CFStringGetCStringPtr(cfstring,
|
||||
cfstring_encoding);
|
||||
const char *tmp_buffer =
|
||||
CFStringGetCStringPtr(cfstring, cfstring_encoding);
|
||||
|
||||
if (tmp_buffer != NULL) {
|
||||
dstr_copy(str, tmp_buffer);
|
||||
@@ -530,8 +531,8 @@ bool cfstr_copy_dstr(CFStringRef cfstring,
|
||||
dstr_ensure_capacity(str, max_size);
|
||||
|
||||
// Copy CFString in requested encoding to dstr buffer
|
||||
Boolean success = CFStringGetCString(
|
||||
cfstring, str->array, max_size, cfstring_encoding);
|
||||
Boolean success = CFStringGetCString(cfstring, str->array, max_size,
|
||||
cfstring_encoding);
|
||||
|
||||
if (success)
|
||||
dstr_resize(str, max_size);
|
||||
|
Reference in New Issue
Block a user