<commit_before>#include "types.h"
#include "param.h"
#include "x86.h"
#include "mmu.h"
#include "proc.h"
#include "defs.h"
#include "file.h"
#include "spinlock.h"

#define PIPESIZE 512

struct pipe {
  int readopen;   // read fd is still open
  int writeopen;  // write fd is still open
  int writep;     // next index to write
  int readp;      // next index to read
  struct spinlock lock;
  char data[PIPESIZE];
};

int
pipe_alloc(struct file **f0, struct file **f1)
{
  *f0 = *f1 = 0;
  struct pipe *p = 0;

  if((*f0 = filealloc()) == 0)
    goto oops;
  if((*f1 = filealloc()) == 0)
    goto oops;
  if((p = (struct pipe*) kalloc(PAGE)) == 0)
    goto oops;
  p->readopen = 1;
  p->writeopen = 1;
  p->writep = 0;
  p->readp = 0;
  initlock(&p->lock, "pipe");
  (*f0)->type = FD_PIPE;
  (*f0)->readable = 1;
  (*f0)->writable = 0;
  (*f0)->pipe = p;
  (*f1)->type = FD_PIPE;
  (*f1)->readable = 0;
  (*f1)->writable = 1;<commit_msg>move variable declaration up<commit_after>#include "types.h"
#include "param.h"
#include "x86.h"
#include "mmu.h"
#include "proc.h"
#include "defs.h"
#include "file.h"
#include "spinlock.h"

#define PIPESIZE 512

struct pipe {
  int readopen;   // read fd is still open
  int writeopen;  // write fd is still open
  int writep;     // next index to write
  int readp;      // next index to read
  struct spinlock lock;
  char data[PIPESIZE];
};

int
pipe_alloc(struct file **f0, struct file **f1)
{
  struct pipe *p;

  p = 0;
  *f0 = *f1 = 0;
  if((*f0 = filealloc()) == 0)
    goto oops;
  if((*f1 = filealloc()) == 0)
    goto oops;
  if((p = (struct pipe*) kalloc(PAGE)) == 0)
    goto oops;
  p->readopen = 1;
  p->writeopen = 1;
  p->writep = 0;
  p->readp = 0;
  initlock(&p->lock, "pipe");
  (*f0)->type = FD_PIPE;
  (*f0)->readable = 1;
  (*f0)->writable = 0;
  (*f0)->pipe = p;
  (*f1)->type = FD_PIPE;
  (*f1)->readable = 0;
  (*f1)->writable = 1;
{'fraction_non_alphanumeric': 0.19040084388185655, 'fraction_numerical': 0.03270042194092827, 'mean_word_length': 2.9769392033542976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 27, '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': '1898104', 'n_tokens_mistral': 830, 'n_tokens_neox': 786, 'n_words': 217}