(file_lock, file_unlock, ef_lock, ef_unlock, commlock, communlock):

File locking doesn't make sense, must be a leftover from the distant
past.  Remove.  Callers changed.
This commit is contained in:
Markus Armbruster 2004-01-29 17:07:26 +00:00
parent daad9ed79c
commit beba530119
11 changed files with 2 additions and 191 deletions

View file

@ -105,8 +105,6 @@ extern int ef_extend(int, int);
extern void ef_zapcache(int); extern void ef_zapcache(int);
extern int ef_nelem(int); extern int ef_nelem(int);
extern int ef_flags(int); extern int ef_flags(int);
extern int ef_lock(int);
extern int ef_unlock(int);
extern int ef_vars(int, register s_char *, u_char **, extern int ef_vars(int, register s_char *, u_char **,
u_char **, u_short **); u_char **, u_short **);
extern int ef_byname(s_char *); extern int ef_byname(s_char *);

View file

@ -175,8 +175,6 @@ extern double reltech(int level1, int level2, double mult);
extern double multread(natid, natid); extern double multread(natid, natid);
extern int commread(void); extern int commread(void);
extern int commwrite(void); extern int commwrite(void);
extern int commlock(void);
extern int communlock(void);
extern int commamt(natid, int, float *); extern int commamt(natid, int, float *);
extern void commset(natid, int, int); extern void commset(natid, int, int);
extern void multset(natid, float); extern void multset(natid, float);

View file

@ -418,8 +418,6 @@ extern s_char *getstring(s_char *, s_char *);
#if !defined(_WIN32) #if !defined(_WIN32)
extern s_char *inet_ntoa(struct in_addr); extern s_char *inet_ntoa(struct in_addr);
#endif #endif
extern int file_lock(int);
extern int file_unlock(int);
extern int diffx(int, int); extern int diffx(int, int);
extern int diffy(int, int); extern int diffy(int, int);
extern int deltax(int, int); extern int deltax(int, int);

View file

@ -238,14 +238,12 @@ diss(void)
putloan(ni.cur, &loan); putloan(ni.cur, &loan);
} }
/* clean up commodity and trade for this nation. */ /* clean up commodity and trade for this nation. */
commlock();
commread(); commread();
for (n = 1; n < I_MAX + 1; n++) { for (n = 1; n < I_MAX + 1; n++) {
val = commamt(player->cnum, n, &dummy); val = commamt(player->cnum, n, &dummy);
commset(player->cnum, n, -val); commset(player->cnum, n, -val);
} }
commwrite(); commwrite();
communlock();
snxtitem_all(&ni, EF_TRADE); snxtitem_all(&ni, EF_TRADE);
while (nxtitem(&ni, (s_char *)&trade)) { while (nxtitem(&ni, (s_char *)&trade)) {
if (trade.trd_unitid >= 0 && trade.trd_owner == player->cnum) { if (trade.trd_unitid >= 0 && trade.trd_owner == player->cnum) {

View file

@ -105,12 +105,7 @@ multsingle(natid us, natid them, struct natstr *natp)
price = minmult; price = minmult;
if (price >= maxmult) if (price >= maxmult)
price = maxmult; price = maxmult;
if (!commlock()) {
pr("Unable to lock commodity file; get help!\n");
return;
}
if (commread() < 0) { if (commread() < 0) {
(void)communlock();
pr("Unable to re-read commodity file; get help!\n"); pr("Unable to re-read commodity file; get help!\n");
return; return;
} }
@ -118,5 +113,4 @@ multsingle(natid us, natid them, struct natstr *natp)
if (commwrite() < 0) { if (commwrite() < 0) {
pr("Unable to write out commodity file; get help!\n"); pr("Unable to write out commodity file; get help!\n");
} }
(void)communlock();
} }

View file

@ -127,10 +127,6 @@ set(void)
} }
if ((price = atoi(p)) < 0) if ((price = atoi(p)) < 0)
continue; continue;
if (!ef_lock(EF_TRADE)) {
logerror("can't lock trade file");
return RET_SYS;
}
foundslot = -1; foundslot = -1;
freeslot = -1; freeslot = -1;
snxtitem_all(&ni_trade, EF_TRADE); snxtitem_all(&ni_trade, EF_TRADE);
@ -178,7 +174,6 @@ set(void)
trade_nameof(&trade, &item), ni.cur, trade_nameof(&trade, &item), ni.cur,
id, foundslot >= 0 ? "reset" : "set", price); id, foundslot >= 0 ? "reset" : "set", price);
} }
ef_unlock(EF_TRADE);
} }
return RET_OK; return RET_OK;
} }

View file

@ -421,18 +421,6 @@ ef_flags(int type)
return empfile[type].flags; return empfile[type].flags;
} }
int
ef_lock(int type)
{
return file_lock(empfile[type].fd);
}
int
ef_unlock(int type)
{
return file_unlock(empfile[type].fd);
}
time_t time_t
ef_mtime(int type) ef_mtime(int type)
{ {

View file

@ -37,13 +37,13 @@ NTLIB = $(SRCDIR)\lib\libgen.lib
OBJS = atoip.o chance.o copy.o disassoc.o dtable.o \ OBJS = atoip.o chance.o copy.o disassoc.o dtable.o \
emp_config.o getstarg.o getstring.o inet.o io.o \ emp_config.o getstarg.o getstring.o inet.o io.o \
io_mask.o ioqueue.o lock.o mapdist.o minmax.o numstr.o onearg.o \ io_mask.o ioqueue.o mapdist.o minmax.o numstr.o onearg.o \
parse.o plur.o queue.o round.o scthash.o \ parse.o plur.o queue.o round.o scthash.o \
strdup.o strdup.o
NTOBJS = atoip.obj chance.obj copy.obj disassoc.obj dtable.obj \ NTOBJS = atoip.obj chance.obj copy.obj disassoc.obj dtable.obj \
emp_config.obj getstarg.obj getstring.obj \ emp_config.obj getstarg.obj getstring.obj \
inet.obj io.obj io_mask.obj ioqueue.obj lock.obj mapdist.obj minmax.obj \ inet.obj io.obj io_mask.obj ioqueue.obj mapdist.obj minmax.obj \
numstr.obj onearg.obj parse.obj plur.obj queue.obj round.obj \ numstr.obj onearg.obj parse.obj plur.obj queue.obj round.obj \
scthash.obj strdup.obj scthash.obj strdup.obj

View file

@ -1,140 +0,0 @@
/*
* Empire - A multi-player, client/server Internet based war game.
* Copyright (C) 1986-2000, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* ---
*
* See the "LEGAL", "LICENSE", "CREDITS" and "README" files for all the
* related information and legal notices. It is expected that any future
* projects/authors will amend these files as needed.
*
* ---
*
* lock.c: Lock a file
*
* Known contributors to this file:
* Doug Hay, 1998
*/
#ifdef aix
#define L_SET 0
#endif /* aix */
#include "misc.h"
#include "gen.h"
#include "common.h"
#include <fcntl.h>
#ifdef sys5
#include <unistd.h>
#endif
#if !defined(L_SET) && !defined(_WIN32)
#include <sys/file.h>
#endif
#ifdef aix
#define L_SET 0
#endif /* aix */
#if defined(_WIN32)
#include <sys/locking.h>
int
file_lock(int fd)
{
if (_locking(fd, _LK_LOCK, 0) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
}
int
file_unlock(int fd)
{
if (_locking(fd, _LK_UNLCK, 0) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
}
#else
#ifndef NOFLOCK
int flock();
int
file_lock(int fd)
{
if (flock(fd, LOCK_EX) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
}
int
file_unlock(int fd)
{
if (flock(fd, LOCK_UN) < 0) {
logerror("file unlock (fd %d) failed", fd);
return 0;
}
return 1;
}
#else
int
file_lock(int fd)
{
struct flock lock;
lock.l_type = F_WRLCK;
lock.l_whence = L_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = 0;
if (fcntl(fd, F_SETLKW, &lock) < 0) {
logerror("file lock (fd %d) failed", fd);
return 0;
}
return 1;
}
int
file_unlock(int fd)
{
struct flock lock;
lock.l_type = F_UNLCK;
lock.l_whence = L_SET;
lock.l_start = 0;
lock.l_len = 0;
lock.l_pid = 0;
if (fcntl(fd, F_SETLKW, &lock) < 0) {
logerror("file unlock (fd %d) failed", fd);
return 0;
}
return 1;
}
#endif
#endif /* _WIN32 */

View file

@ -129,18 +129,6 @@ commwrite(void)
return 0; return 0;
} }
int
commlock(void)
{
return file_lock(commf);
}
int
communlock(void)
{
return file_unlock(commf);
}
/* /*
* returns amount of commodity, and price to the user * returns amount of commodity, and price to the user
*/ */

View file

@ -55,17 +55,11 @@ distrea(int n, register struct trtstr *tp)
return 0; return 0;
(void)time(&now); (void)time(&now);
if (now > tp->trt_exp) { if (now > tp->trt_exp) {
if (!ef_lock(EF_TREATY)) {
pr("Can't lock treaty file; get help!\n");
return 0;
}
tp->trt_status = TS_FREE; tp->trt_status = TS_FREE;
if (!puttre(n, tp)) { if (!puttre(n, tp)) {
pr("Couldn't save treaty; get help!\n"); pr("Couldn't save treaty; get help!\n");
(void)ef_unlock(EF_TREATY);
return 0; return 0;
} }
(void)ef_unlock(EF_TREATY);
pr("Treaty #%d expired %s", n, ctime(&tp->trt_exp)); pr("Treaty #%d expired %s", n, ctime(&tp->trt_exp));
return 0; return 0;
} }