Ejemplo n.º 1
0
/* Steal a work item from another worker */
void SNetWorkerStealVictim(worker_t *victim, worker_t *thief)
{
  work_item_t   *item = victim->todo.head.next_item;
  int            amount;

  assert(thief->loot.desc == NULL);
  for (; item && !thief->loot.desc; item = item->next_item) {
    if (item->count > 0 && trylock_work_item(item, thief)) {
      if (item->count > 0 && item->desc && DESC_LOCK(item->desc) == 0) {
        work_item_t *lookup = (work_item_t *)
            SNetHashPtrLookup(thief->hash_ptab, item->desc);
        if (lookup) {
          if (item->desc->landing->type == LAND_garbage) {
            /* Take everything. */
            amount = item->count;
          } else {
            /* Split the work evenly. */
            amount = (item->count - lookup->count) / 2;
          }
          if (amount > 0) {
            FAS(&item->count, amount);
            thief->loot.count = amount;
          } else {
            thief->loot.count = 0;
          }
          thief->loot.desc = item->desc;
          thief->loot.item = lookup;
          thief->has_work = true;
        }
        else /* (lookup == NULL) */ {
          if (item->desc->landing->type == LAND_garbage) {
            /* Take everything. */
            amount = item->count;
          } else {
            /* Talk half of it, but at least one. */
            amount = (item->count + 1) / 2;
          }
          if (amount > 0) {
            FAS(&item->count, amount);
            thief->loot.count = amount;
            thief->loot.desc = item->desc;
            thief->loot.item = NULL;
            thief->has_work = true;
          }
        }
      }
      unlock_work_item(item, thief);
    }
  }
  if (thief->loot.desc && SNetDebugWS()) {
    printf("steal\n");
  }
}
Ejemplo n.º 2
0
void EnterMsgAreaBarricade(void)
{
  if (!eqstri(CurrentMenuName(), MAS(mah, barricademenu)))
    return;

  if (fah.heap && !eqstri(CurrentMenuName(), FAS(fah, barricademenu)))
    ExitFileAreaBarricade();

  if (mah.bi.use_barpriv)
  {
    /* Save current priv level on stack */

    lam->biOldPriv.use_barpriv=TRUE;
    lam->biOldPriv.priv=usr.priv;
    lam->biOldPriv.keys=usr.xkeys;

    /* Set the user's priv level to that of the barricade priv */

    usr.priv = mah.bi.priv;
    usr.xkeys |= mah.bi.keys;
  }
  else
  {
    lam->biOldPriv.use_barpriv=FALSE;
  }
}
Ejemplo n.º 3
0
OpResult LIFOPool::consume(Task*& t, AtomicStatistics* stat) {
	Lifo::Node* n = stack->pop();
	if (n == NULL) {
		t = NULL; return EMPTY;
	}
	t = n->task;
	FAS(&size, 1);
	return SUCCESS;
}
Ejemplo n.º 4
0
void File_Kill(void)
{
  byte filename[PATHLEN];
  byte filespec[PATHLEN];
  byte temp[PATHLEN];

  WhiteN();

  InputGets(filename, file_to_kill);

  Strip_Path(filename);

  if (! *filename)
    return;

  sprintf(filespec, ss, FAS(fah, downpath), filename);

  if (! fexist(filespec))
  {
    if (IsInFilesBbs(&fah, filename, NULL, NULL))
      Remove_Files_Entry(filename, NULL);
    else Printf(cantfind+1, filespec);

    return;
  }


  sprintf(temp, delete_yn, filename);

  if (GetyNAnswer(temp, 0)==YES)
  {
    if (unlink(filespec)==-1)
    {
      Printf(cant_unlink, filespec);
      Press_ENTER();
    }
    else Remove_Files_Entry(filename, NULL);
  }
  else
  {
    /* if user doesn't want to kill file, but wants to remove entry */

    if (GetyNAnswer(lfbrfbe, 0)==YES)
      Remove_Files_Entry(filename, NULL);
  }
}
Ejemplo n.º 5
0
/* Frees the memory allocated for c4snet_data_t struct. */
void C4SNetFree(c4snet_data_t *data)
{
#if HAVE_SYNC_ATOMIC_BUILTINS
  /* Temporary fix for race condition: */
  unsigned int refs = FAS(&data->ref_count, 1);
  assert(refs > 0);
  if (refs == 1)
#else
  /* Old code, which contains a race condition: */
  if (--data->ref_count == 0)
#endif
  {
    if (data->vtype == VTYPE_array) MemFree(data->data.ptr);

    SNetMemFree(data);
  }
}
Ejemplo n.º 6
0
void MaxWriteCtl(struct _proto *pro, word ul)
{
  FILE *ctl;
  char fname[PATHLEN];
  word n;
  long bd=steady_baud_l ? steady_baud_l : baud;

  FENTRY fent;

  /* Delete any preexisting log file */

  Parse_Outside_Cmd(pro->log, fname);
  unlink(fname);
  
  
  /* Handle the "%" translation characters */

  Parse_Outside_Cmd(pro->ctl, fname);
  
  if ((ctl=fopen(fname, fopen_write))==NULL)
  {
    cant_open(fname);
    return;
  }

  /* If we need to handle an Opus-style control file, do so now */

  if (pro->flag & P_OPUS)
  {
    if (local)
      fprintf(ctl, xctl_keyboard);
    else fprintf(ctl, xctl_port_baud, port+1, bd);

    if (!local)
      fprintf(ctl, xctl_modem,
              port+1, bd,
              prm.handshake_mask /* 3 */, prm.carrier_mask, baud);

    fprintf(ctl, xctl_time, timeleft());

    if (log_name && *log_name)
      fprintf(ctl, xctl_log, log_name);

    fprintf(ctl, xctl_msgs, MAS(mah, path));
    fprintf(ctl, xctl_uploads, FAS(fah, uppath));
    fprintf(ctl, xctl_downloads, FAS(fah, downpath));
    fprintf(ctl, xctl_help,  original_path);
  
    if (fah.heap)
    {
      if (*FAS(fah, filesbbs))
        fprintf(ctl, xctl_filesbbs, FAS(fah, filesbbs));
    }
  }

  /* Now write out the names of the files to send */

  for (n=0; GetFileEntry(n, &fent); n++)
  {
    fprintf(ctl, ul ? pro->ulstr : pro->dlstr, fent.szName);
    fputc('\n', ctl);
  }

  /* Close the control file */

  fclose(ctl);
}
Ejemplo n.º 7
0
word MaxReadLog(struct _proto *pro, word doing_ul)
{
  FILE *log;

  #define LOGLEN 255
  char fname[PATHLEN];
  char line[LOGLEN];
  word gotfile=FALSE;
  char tempname[PATHLEN];

  FENTRY fent;

  /* Handle the "%" translation characters */

  Parse_Outside_Cmd(pro->log, fname);
  
  if ((log=fopen(fname, fopen_read))==NULL)
  {
    cant_open(fname);
    return FALSE;
  }

  while (fgets(line, LOGLEN, log))
  {
    char *ulstr, *dlstr, *got, *desc;
    word ul;
    word fn;
    
    /* Find the positions of the upload and download strings */

    dlstr=strstr(line, pro->dlkey);
    ulstr=strstr(line, pro->ulkey);

    if (ulstr==NULL && dlstr==NULL)
      continue;

    if (pro->flag & P_BI)
    {
      /* Use whichever token comes FIRST in the log line, since we might    *
       * see either.                                                        */
      
      ul=(ulstr && (dlstr==NULL || ulstr < dlstr));
      got=(ul ? ulstr : dlstr);
    }
    else
    {
      /* Otherwise, just get the one that was requested */

      ul=doing_ul;
      
      got=(ul ? ulstr : dlstr);

      if (!got)
        continue;
    }

    /* Now copy the filename, based on the word# we're supposed to get. */

    getword(got, fname, ctl_delim, pro->fnamword+1);

    /* Skip it if we didn't get anything */

    if (*fname=='\0')
      continue;
    
    /* Now figure out if we requested this file or not... */
    
    for (fn=0; GetFileEntry(fn, &fent); fn++)
      if (eqstri(No_Path(fent.szName), No_Path(fname)))
        break;

    if (fn==FileEntries())
      memset(&fent, 0, sizeof fent);
      
    /* Grab the description, if any */

    desc=pro->descword ? firstchar(got, ctl_delim, pro->descword) : NULL;

    if (desc)
      fent.szDesc=desc;

    /* If we're doing an upload, strip the path specification */

    if (ul)
    {
      strcpy(tempname, No_Path(fname));
      fent.szName=tempname;

      /* Now figure out the fully-qualified path/name of the file so
       * that we can get the correct size.
       */

      sprintf(fname, ss, FAS(fah, uppath), fent.szName);
    }
    else
    {
      fent.szName=fname;
    }

    /* Now get the size of this file */
    
    fent.ulSize = fsize(fent.szName);

    if (ul)
    {
      logit(log_ul, *pro->desc, FAS(fah, uppath), fent.szName);
      fent.fFlags |= FFLAG_GOT;
    }
    else
    {
      fent.fFlags |= FFLAG_SENT;
    }

    UpdFileEntry(fn, &fent);
    gotfile=TRUE;
  }

  fclose(log);

  /* If the transfer was successful, delete both the .CTL and .LOG files */

  if (gotfile)
  {
    Parse_Outside_Cmd(pro->log, fname);
    unlink(fname);

    Parse_Outside_Cmd(pro->ctl, fname);
    unlink(fname);
  }
  
  return gotfile;
}