Skip to content

Commit

Permalink
Merge pull request #69 from Galfurian/fix-memory-leak-timer
Browse files Browse the repository at this point in the history
Fix memory leak in the timer routine
  • Loading branch information
Galfurian authored Apr 4, 2024
2 parents 8266b92 + 25e23a2 commit c399078
Show file tree
Hide file tree
Showing 14 changed files with 499 additions and 500 deletions.
8 changes: 8 additions & 0 deletions libc/inc/sys/list_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ typedef struct list_head {
#define list_for_each_decl(pos, head) \
for (list_head * (pos) = (head)->next; (pos) != (head); (pos) = (pos)->next)

/// @brief Iterates over a list safe against removal of list entry.
/// @param pos the name of the iterator used to visit the list.
/// @param store another list iterator to use as temporary storage.
/// @param head the head for your list.
#define list_for_each_safe_decl(pos, store, head) \
for (list_head * (pos) = (head)->next, *(store) = (pos)->next; (pos) != (head); \
(pos) = (store), (store) = (pos)->next)

/// @brief Iterates over a list backwards.
/// @param pos the name of the iterator used to visit the list.
/// @param head the head for your list.
Expand Down
39 changes: 12 additions & 27 deletions mentos/inc/hardware/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/// This enables the system dump tvec_base timer vectors content on
/// the console.
#define ENABLE_REAL_TIMER_SYSTEM_DUMP
//#define ENABLE_REAL_TIMER_SYSTEM_DUMP

/// Counts down in real (i.e., wall clock) time.
#define ITIMER_REAL 0
Expand Down Expand Up @@ -61,6 +61,8 @@ void timer_phase(const uint32_t hz);

#ifdef ENABLE_REAL_TIMER_SYSTEM

/// Number of normal timer vectors.
#define TVN_COUNT 4
/// Number of bits for the normal timer vector.
#define TVN_BITS 6
/// Number of bits for the root timer vector.
Expand All @@ -78,18 +80,6 @@ void timer_phase(const uint32_t hz);
/// Expiration ticks of timer based on position inside tvec_base structure
#define TIMER_TICKS(tv) (1 << TIMER_TICKS_BITS(tv))

/// @brief Root timer vector.
typedef struct timer_vec_root {
/// Array of lists of timers
list_head vec[TVR_SIZE];
} timer_vec_root;

/// @brief Normal timer vector.
typedef struct timer_vec {
/// Array of lists of timers
list_head vec[TVN_SIZE];
} timer_vec;

#endif

/// @brief Contains all the timers of a single CPU
Expand All @@ -102,16 +92,14 @@ typedef struct tvec_base_s {
/// The earliest expiration time of the dynamic timers yet to be checked
unsigned long timer_ticks;

/// Lists of timers that will expires in the next 255 ticks
struct timer_vec_root tv1;
/// Lists of timers that will expires in the next 2^14 - 1 ticks
struct timer_vec tv2;
/// Lists of timers that will expires in the next 2^20 - 1 ticks
struct timer_vec tv3;
/// Lists of timers that will expires in the next 2^26 - 1 ticks
struct timer_vec tv4;
/// Lists of timers with extremely large expires fields (2^32 - 1 ticks)
struct timer_vec tv5;
/// Lists of root timers that will expires in the next 255 ticks.
list_head tvr[TVR_SIZE];
/// Lists of normal timers that will expires in the next:
/// tv[0] : 2^14 - 1 ticks
/// tv[1] : 2^20 - 1 ticks
/// tv[2] : 2^26 - 1 ticks
/// tv[3] : 2^32 - 1 ticks
list_head tvn[TVN_COUNT][TVN_SIZE];

#else
/// List of all the timers
Expand Down Expand Up @@ -153,10 +141,7 @@ void add_timer(struct timer_list *timer);

/// @brief Removes a timer from the current CPU.
/// @param timer The timer to remove.
void del_timer(struct timer_list *timer);

/// @brief Updates and executes dynamics timers
void run_timer_softirq(void);
void remove_timer(struct timer_list *timer);

/// @brief Suspends the execution of the calling thread.
/// @param req The amount of time we want to sleep.
Expand Down
9 changes: 9 additions & 0 deletions mentos/inc/process/wait.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ typedef struct wait_queue_entry_t {
struct list_head task_list;
} wait_queue_entry_t;


/// @brief Allocates the memory for a wait_queue_entry.
/// @return a pointer to the allocated wait_queue_entry.
wait_queue_entry_t * wait_queue_entry_alloc();

/// @brief Frees the memory of a wait_queue_entry.
/// @param wait_queue_entry pointer to the wait_queue_entry.
void wait_queue_entry_dealloc(wait_queue_entry_t * wait_queue_entry);

/// @brief Initialize the waiting queue entry.
/// @param wq The entry we initialize.
/// @param task The task associated with the entry.
Expand Down
Loading

0 comments on commit c399078

Please sign in to comment.