Skip to content

Commit

Permalink
Overhaul formatting of krnlmon source files (#62)
Browse files Browse the repository at this point in the history
- Use clang-format to canonicalize the C source files.

- Fix issues in header file dependencies that were revealed
  when we reformatted the source files with clang-format.

- Correct a couple of aberrant include guards.

- Update Intel copyright notices

Signed-off-by: Derek G Foster <[email protected]>
  • Loading branch information
ffoulkes authored Oct 25, 2023
1 parent fb68507 commit bf51b23
Show file tree
Hide file tree
Showing 120 changed files with 9,637 additions and 10,794 deletions.
18 changes: 9 additions & 9 deletions krnlmon_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ static pthread_t stop_tid;

extern "C" {
// Ensure that the functions passed to pthread_create() have C interfaces.
static void *krnlmon_main_wrapper(void *arg);
static void *krnlmon_stop_wrapper(void *arg);
static void* krnlmon_main_wrapper(void* arg);
static void* krnlmon_stop_wrapper(void* arg);
}

static void *krnlmon_main_wrapper(void *arg) {
static void* krnlmon_main_wrapper(void* arg) {
// Wait for stratum server to signal that it is ready.
auto ready_sync = static_cast<absl::Notification*>(arg);
ready_sync->WaitForNotification();
Expand All @@ -35,7 +35,7 @@ static void *krnlmon_main_wrapper(void *arg) {
return nullptr;
}

static void *krnlmon_stop_wrapper(void *arg) {
static void* krnlmon_stop_wrapper(void* arg) {
// Wait for stratum server to signal that it is done.
auto done_sync = static_cast<absl::Notification*>(arg);
done_sync->WaitForNotification();
Expand All @@ -46,16 +46,16 @@ static void *krnlmon_stop_wrapper(void *arg) {
return nullptr;
}

static void print_strerror(const char *msg, int err) {
static void print_strerror(const char* msg, int err) {
char errbuf[64];
printf("%s: %s\n", msg, strerror_r(err, errbuf, sizeof(errbuf)));
}

int krnlmon_create_main_thread(absl::Notification* ready_sync) {
int rc = pthread_create(&main_tid, NULL, &krnlmon_main_wrapper, ready_sync);
if (rc) {
print_strerror("Error creating switchlink_main thread", rc);
return -1;
print_strerror("Error creating switchlink_main thread", rc);
return -1;
}

rc = pthread_setname_np(main_tid, "switchlink_main");
Expand All @@ -69,8 +69,8 @@ int krnlmon_create_main_thread(absl::Notification* ready_sync) {
int krnlmon_create_shutdown_thread(absl::Notification* done_sync) {
int rc = pthread_create(&stop_tid, NULL, &krnlmon_stop_wrapper, done_sync);
if (rc) {
print_strerror("Error creating switchlink_stop thread", rc);
return -1;
print_strerror("Error creating switchlink_stop thread", rc);
return -1;
}

rc = pthread_setname_np(stop_tid, "switchlink_stop");
Expand Down
27 changes: 13 additions & 14 deletions switchapi/dpdk/switch_config.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2013-present Barefoot Networks, Inc.
* Copyright (c) 2022 Intel Corporation.
* Copyright 2022-2023 Intel Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -25,12 +25,13 @@ extern "C" {
#define __FILE_ID__ SWITCH_CONFIG
switch_config_info_t config_info;

switch_status_t switch_config_init(switch_config_t *switch_config) {
switch_status_t switch_config_init(switch_config_t* switch_config) {
switch_status_t status = SWITCH_STATUS_SUCCESS;

if (config_info.config_inited) {
status = SWITCH_STATUS_ITEM_ALREADY_EXISTS;
krnlmon_log_error("config init failed, error: %s", switch_error_to_string(status));
krnlmon_log_error("config init failed, error: %s",
switch_error_to_string(status));
return status;
}

Expand Down Expand Up @@ -68,14 +69,13 @@ switch_status_t switch_config_free(void) {
}

switch_status_t switch_config_device_context_set(
switch_device_t device, switch_device_context_t *device_ctx) {
switch_device_t device, switch_device_context_t* device_ctx) {
switch_status_t status = SWITCH_STATUS_SUCCESS;

if (device_ctx && config_info.device_inited[device]) {
status = SWITCH_STATUS_ITEM_ALREADY_EXISTS;
krnlmon_log_error("config free failed for device %d, error: %s",
device,
switch_error_to_string(status));
krnlmon_log_error("config free failed for device %d, error: %s", device,
switch_error_to_string(status));
return status;
}

Expand All @@ -91,14 +91,13 @@ switch_status_t switch_config_device_context_set(
}

switch_status_t switch_config_device_context_get(
switch_device_t device, switch_device_context_t **device_ctx) {
switch_device_t device, switch_device_context_t** device_ctx) {
switch_status_t status = SWITCH_STATUS_SUCCESS;

if (!config_info.device_inited[device]) {
status = SWITCH_STATUS_UNINITIALIZED;
krnlmon_log_error("Failed to get device context for device %d, error: %s\n",
device,
switch_error_to_string(status));
device, switch_error_to_string(status));
return status;
}

Expand All @@ -108,14 +107,14 @@ switch_status_t switch_config_device_context_get(
}

switch_status_t switch_config_table_sizes_get(switch_device_t device,
switch_size_t *table_sizes) {
switch_size_t* table_sizes) {
switch_status_t status = SWITCH_STATUS_SUCCESS;

status = switch_table_default_sizes_get(table_sizes);
if (status != SWITCH_STATUS_SUCCESS) {
krnlmon_log_error("Failed to get config table sizes for device %d, error: %s\n",
device,
switch_error_to_string(status));
krnlmon_log_error(
"Failed to get config table sizes for device %d, error: %s\n", device,
switch_error_to_string(status));
return status;
}

Expand Down
Loading

0 comments on commit bf51b23

Please sign in to comment.