<commit_before>/* v/save.c
**
** This file is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <setjmp.h>
#include <gmp.h>
#include <stdint.h>
#include <termios.h>
#include <uv.h>

#include "all.h"
#include "v/vere.h"

/* _save_sign_cb: signal callback.
*/
static void
_save_sign_cb(uv_signal_t* sil_u, c3_i num_i)
{
  uL(fprintf(uH, "save: signal %d\n", num_i));
  {
    switch ( num_i ) {
      case SIGCHLD: u2_save_ef_chld(); break;
    }
  }
}

/* _save_time_cb(): timer callback.
*/
static void
_save_time_cb(uv_timer_t* tim_u, c3_i sas_i)
{
  u2_save* sav_u = &u2_Host.sav_u;

  if ( sav_u->pid_w ) {
    return;
  }

  if ( u2A->ent_w > sav_u->ent_w ) {
    // uL(fprintf(uH, "autosaving... ent_w %d\n", u2A->ent_w));

    u2_cm_purge();
    u2_lo_grab("save", u2_none);

#ifdef FORKPT
    c3_w pid_w;
    if ( 0 == (pid_w = fork()) ) {
      u2_loom_save(u2A->ent_w);
      exit(0);
    }
    else {
      uL(fprintf(uH, "checkpoint: process %d\n", pid_w));

      sav_u->ent_w = u2A->ent_w;
      sav_u->pid_w = pid_w;
    }
#else
    u2_loom_save(u2A->ent_w);
    sav_u->ent_w = u2A->ent_w;
#endif
  }
}

/* u2_save_ef_chld(): report save termination.
*/
void
u2_save_ef_chld(void)
{
  u2_save* sav_u = &u2_Host.sav_u;
  c3_i     loc_i;
  c3_w     pid_w;

  /* modified for cases with no pid_w
  */
  uL(fprintf(uH, "checkpoint: complete %d\n", sav_u->pid_w));
  pid_w = wait(&loc_i);
  if (0 != sav_u->pid_w) {
    c3_assert(pid_w == sav_u->pid_w);
  }
  else {
    c3_assert(pid_w > 0);
  }
  sav_u->pid_w = 0;
}

/* u2_save_io_init(): initialize autosave.
*/
void
u2_save_io_init(void)
{
  u2_save* sav_u = &u2_Host.sav_u;

  sav_u->ent_w = 0;
  sav_u->pid_w = 0;

  uv_timer_init(u2L, &sav_u->tim_u);
  uv_timer_start(&sav_u->tim_u, _save_time_cb, 15000, 15000);

  uv_signal_start(&sav_u->sil_u, _save_sign_cb, SIGCHLD);
}

/* u2_save_io_exit(): terminate save I/O.
*/
void
u2_save_io_exit(void)
{
}

/* u2_save_io_poll(): poll kernel for save I/O.
*/
void
u2_save_io_poll(void)
{
}

<commit_msg>Fix warning on implicit wait decl<commit_after>/* v/save.c
**
** This file is in the public domain.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>
#include <setjmp.h>
#include <gmp.h>
#include <stdint.h>
#include <termios.h>
#include <uv.h>

#include "all.h"
#include "v/vere.h"

/* _save_sign_cb: signal callback.
*/
static void
_save_sign_cb(uv_signal_t* sil_u, c3_i num_i)
{
  uL(fprintf(uH, "save: signal %d\n", num_i));
  {
    switch ( num_i ) {
      case SIGCHLD: u2_save_ef_chld(); break;
    }
  }
}

/* _save_time_cb(): timer callback.
*/
static void
_save_time_cb(uv_timer_t* tim_u, c3_i sas_i)
{
  u2_save* sav_u = &u2_Host.sav_u;

  if ( sav_u->pid_w ) {
    return;
  }

  if ( u2A->ent_w > sav_u->ent_w ) {
    // uL(fprintf(uH, "autosaving... ent_w %d\n", u2A->ent_w));

    u2_cm_purge();
    u2_lo_grab("save", u2_none);

#ifdef FORKPT
    c3_w pid_w;
    if ( 0 == (pid_w = fork()) ) {
      u2_loom_save(u2A->ent_w);
      exit(0);
    }
    else {
      uL(fprintf(uH, "checkpoint: process %d\n", pid_w));

      sav_u->ent_w = u2A->ent_w;
      sav_u->pid_w = pid_w;
    }
#else
    u2_loom_save(u2A->ent_w);
    sav_u->ent_w = u2A->ent_w;
#endif
  }
}

/* u2_save_ef_chld(): report save termination.
*/
void
u2_save_ef_chld(void)
{
  u2_save* sav_u = &u2_Host.sav_u;
  c3_i     loc_i;
  c3_w     pid_w;

  /* modified for cases with no pid_w
  */
  uL(fprintf(uH, "checkpoint: complete %d\n", sav_u->pid_w));
  pid_w = wait(&loc_i);
  if (0 != sav_u->pid_w) {
    c3_assert(pid_w == sav_u->pid_w);
  }
  else {
    c3_assert(pid_w > 0);
  }
  sav_u->pid_w = 0;
}

/* u2_save_io_init(): initialize autosave.
*/
void
u2_save_io_init(void)
{
  u2_save* sav_u = &u2_Host.sav_u;

  sav_u->ent_w = 0;
  sav_u->pid_w = 0;

  uv_timer_init(u2L, &sav_u->tim_u);
  uv_timer_start(&sav_u->tim_u, _save_time_cb, 15000, 15000);

  uv_signal_start(&sav_u->sil_u, _save_sign_cb, SIGCHLD);
}

/* u2_save_io_exit(): terminate save I/O.
*/
void
u2_save_io_exit(void)
{
}

/* u2_save_io_poll(): poll kernel for save I/O.
*/
void
u2_save_io_poll(void)
{
}


{'fraction_non_alphanumeric': 0.17211583372255956, 'fraction_numerical': 0.02382064455861747, 'mean_word_length': 3.283, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4163024', 'n_tokens_mistral': 2156, 'n_tokens_neox': 2096, 'n_words': 361}