Skip to content

Commit

Permalink
unify comments
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Sep 6, 2024
1 parent 8e23cc3 commit a7a1234
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
10 changes: 5 additions & 5 deletions src/process_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
*/
struct process_group
{
/** Pointer to the process table for storing process information */
/* Pointer to the process table for storing process information */
struct process_table *proctable;

/** Pointer to the list of processes in this group */
/* Pointer to the list of processes in this group */
struct list *proclist;

/** PID of the target process to monitor */
/* PID of the target process to monitor */
pid_t target_pid;

/** Flag indicating whether to include child processes (1 for yes, 0 for no) */
/* Flag indicating whether to include child processes (1 for yes, 0 for no) */
int include_children;

/** Timestamp of the last update for this process group */
/* Timestamp of the last update for this process group */
struct timespec last_update;
};

Expand Down
70 changes: 54 additions & 16 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,60 +13,80 @@
/* Useful macros */

#if defined(__GNUC__) && !defined(__UNIQUE_ID)
/* Helper macros to concatenate tokens */
/**
* Helper macros to concatenate tokens
*/
#define ___PASTE(a, b) a##b
#define __PASTE(a, b) ___PASTE(a, b)

/* Generates a unique ID based on a prefix */
/**
* Generates a unique ID based on a prefix
*/
#define __UNIQUE_ID(prefix) \
__PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
#endif

#ifndef MIN
#ifdef __GNUC__
/* Helper for finding the minimum of two values, utilizing type safety */
/**
* Helper for finding the minimum of two values, utilizing type safety
*/
#define __min(t1, t2, min1, min2, x, y) \
(__extension__({ \
t1 min1 = (x); \
t2 min2 = (y); \
(void)(&min1 == &min2); \
min1 < min2 ? min1 : min2; \
}))
/**
* Macro to find the minimum of two values
*/
#define MIN(x, y) \
__min(__typeof__(x), __typeof__(y), \
__UNIQUE_ID(min1_), __UNIQUE_ID(min2_), \
x, y)
#else
/* Simple macro to find the minimum of two values */
/**
* Simple macro to find the minimum of two values
*/
#define MIN(a, b) \
(((a) < (b)) ? (a) : (b))
#endif
#endif

#ifndef MAX
#ifdef __GNUC__
/* Helper for finding the maximum of two values, utilizing type safety */
/**
* Helper for finding the maximum of two values, utilizing type safety
*/
#define __max(t1, t2, max1, max2, x, y) \
(__extension__({ \
t1 max1 = (x); \
t2 max2 = (y); \
(void)(&max1 == &max2); \
max1 > max2 ? max1 : max2; \
}))
/**
* Macro to find the maximum of two values
*/
#define MAX(x, y) \
__max(__typeof__(x), __typeof__(y), \
__UNIQUE_ID(max1_), __UNIQUE_ID(max2_), \
x, y)
#else
/* Simple macro to find the maximum of two values */
/**
* Simple macro to find the maximum of two values
*/
#define MAX(a, b) \
(((a) > (b)) ? (a) : (b))
#endif
#endif

#ifndef basename
#ifdef __GNUC__
/* Helper macro to get the basename of a path */
/**
* Helper macro to get the basename of a path
*/
#define __basename(path, full_path, last_slash) \
(__extension__({ \
const char *full_path = (path); \
Expand All @@ -76,14 +96,18 @@
#define basename(path) \
__basename((path), __UNIQUE_ID(full_path_), __UNIQUE_ID(last_slash_))
#else
/* Fallback function declaration for basename */
/**
* Get the basename of a path
*/
const char *__basename(const char *path);
#define basename(path) __basename(path)
#define __IMPL_BASENAME
#endif
#endif

/* Converts nanoseconds to a timespec structure */
/**
* Converts nanoseconds to a timespec structure
*/
#ifndef nsec2timespec
#define nsec2timespec(nsec, t) \
do \
Expand All @@ -93,7 +117,9 @@ const char *__basename(const char *path);
} while (0)
#endif

/* Sleep for a specified timespec duration */
/**
* Sleep for a specified timespec duration
*/
#ifndef sleep_timespec
#if defined(__linux__) && _POSIX_C_SOURCE >= 200112L && defined(CLOCK_TAI)
#define sleep_timespec(t) clock_nanosleep(CLOCK_TAI, 0, (t), NULL)
Expand All @@ -102,7 +128,9 @@ const char *__basename(const char *path);
#endif
#endif

/* Retrieves the current time into a timespec structure */
/**
* Retrieves the current time into a timespec structure
*/
#ifndef get_time
#if _POSIX_TIMERS > 0
#if defined(CLOCK_TAI)
Expand All @@ -113,26 +141,36 @@ const char *__basename(const char *path);
#endif
#endif

/* Fallback function for getting time if not defined */
/**
* Fallback function for getting time if not defined
*/
#ifndef get_time
int __get_time(struct timespec *ts);
#define get_time(ts) __get_time(ts)
#define __IMPL_GET_TIME
#endif

/* Returns the difference between two timespecs in milliseconds */
/**
* Returns the difference between two timespecs in milliseconds
*/
#ifndef timediff_in_ms
#define timediff_in_ms(t1, t2) \
(((t1)->tv_sec - (t2)->tv_sec) * 1e3 + ((t1)->tv_nsec - (t2)->tv_nsec) / 1e6)
#endif

/* Increases the priority of the current process */
/**
* Increases the priority of the current process
*/
void increase_priority(void);

/* Retrieves the number of available CPUs */
/**
* Retrieves the number of available CPUs
*/
int get_ncpu(void);

/* Retrieves the maximum process ID */
/**
* Retrieves the maximum process ID
*/
pid_t get_pid_max(void);

#endif

0 comments on commit a7a1234

Please sign in to comment.