netatalk  4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
idle_worker.c File Reference
#include <errno.h>
#include <pthread.h>
#include <signal.h>
#include <stdatomic.h>
#include <string.h>
#include <time.h>
#include <atalk/logger.h>
#include <atalk/queue.h>
#include "dircache.h"
#include "directory.h"
#include "idle_worker.h"

Macros

#define IDLE_WORKER_WAKE_MS   10
 

Functions

static int idle_worker_has_work (void)
 Check if any idle work is pending (work-availability predicate).
 
static void * idle_worker_main (void *arg)
 Worker thread main loop.
 
int idle_worker_init (void)
 
void idle_worker_start (void)
 
void idle_worker_stop (void)
 
void idle_worker_stop_signal_safe (void)
 
void idle_worker_shutdown (void)
 
int idle_worker_is_active (void)
 
void idle_worker_log_stats (void)
 

Variables

static atomic_int is_idle = 0
 
static atomic_int bg_running = 0
 
static atomic_int shutdown_flag = 0
 
static pthread_t worker_tid
 
static int worker_started = 0
 
struct { 
 
   unsigned int   cycles_started 
 
   unsigned int   cycles_completed 
 
   unsigned int   cycles_interrupted 
 
worker_stat 
 

Macro Definition Documentation

◆ IDLE_WORKER_WAKE_MS

#define IDLE_WORKER_WAKE_MS   10

Function Documentation

◆ idle_worker_has_work()

static int idle_worker_has_work ( void  )
static

Check if any idle work is pending (work-availability predicate).

This function serves two purposes:

  1. Idle guard: the is_idle check ensures the worker does not start work when the main thread is NOT in poll(). Also prevents work during the window between idle_worker_stop() and the next idle_worker_start().
  2. Work-availability predicate: returns true only if there is actual work to perform. If new work types are added to the idle worker (e.g., FCE event dispatch), their pending-work check MUST be added here — otherwise the worker will sleep through available work.

◆ idle_worker_init()

int idle_worker_init ( void  )

◆ idle_worker_is_active()

int idle_worker_is_active ( void  )

◆ idle_worker_log_stats()

void idle_worker_log_stats ( void  )

◆ idle_worker_main()

static void * idle_worker_main ( void *  arg)
static

Worker thread main loop.

Uses nanosleep() for 10ms polling which is a direct SYS_nanosleep syscall

◆ idle_worker_shutdown()

void idle_worker_shutdown ( void  )

◆ idle_worker_start()

void idle_worker_start ( void  )

◆ idle_worker_stop()

void idle_worker_stop ( void  )

◆ idle_worker_stop_signal_safe()

void idle_worker_stop_signal_safe ( void  )

Variable Documentation

◆ bg_running

atomic_int bg_running = 0
static

◆ cycles_completed

unsigned int cycles_completed

◆ cycles_interrupted

unsigned int cycles_interrupted

◆ cycles_started

unsigned int cycles_started

◆ is_idle

atomic_int is_idle = 0
static

◆ shutdown_flag

atomic_int shutdown_flag = 0
static

◆ worker_started

int worker_started = 0
static

◆ [struct]

struct { ... } worker_stat

◆ worker_tid

pthread_t worker_tid
static