summaryrefslogtreecommitdiff
path: root/lib/Input.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Input.cc')
-rw-r--r--lib/Input.cc118
1 files changed, 14 insertions, 104 deletions
diff --git a/lib/Input.cc b/lib/Input.cc
index 46f507b..4c2f419 100644
--- a/lib/Input.cc
+++ b/lib/Input.cc
@@ -37,6 +37,7 @@
#include "Input.h"
#include "Exceptions.h"
#include "gettext.h"
+#include "Atomic.h"
#ifndef S_ISREG
#define S_ISREG(x) 1
@@ -86,10 +87,6 @@ static Input::openresults_t gresults;
int Input::nb_input = 0;
-int Input::GetNbInput() {
- return nb_input;
-}
-
Input::Input(const String & no) throw (GeneralException) :
Handle(no.strlen() ? wrapopen(no, &gresults) : dup(0)),
n(no) {
@@ -105,12 +102,10 @@ Input::Input(const String & no) throw (GeneralException) :
throw IOGeneral(String(_("Error opening file ")) + no + _(" for reading: ") + strerror(errno));
}
- nb_input++;
+ Atomic::Increment(&nb_input);
results = gresults;
- UNLOCK
-
fromarchive = false;
if (results.name == "") {
#ifndef __MIPSEL__
@@ -145,18 +140,6 @@ Input::Input(const String & no) throw (GeneralException) :
}
}
-Input::Input(const Input & i) : Handle(i), n(i.n), size(i.size), date_modif(i.date_modif) {
- nb_input++;
-}
-
-bool Input::CanWrite() const {
- return 0;
-}
-
-bool Input::CanRead() const {
- return 1;
-}
-
bool Input::CanSeek() const {
#ifdef __MIPSEL__
return true;
@@ -169,18 +152,6 @@ bool Input::CanSeek() const {
#endif
}
-String Input::GetName() const {
- return n;
-}
-
-ssize_t Input::GetSize() const {
- return size;
-}
-
-time_t Input::GetModif() const {
- return date_modif;
-}
-
off_t Input::seek(off_t offset, int whence) throw (GeneralException) {
if (!fromarchive) {
if ((itell = lseek(GetHandle(), offset, whence)) < 0) {
@@ -198,7 +169,6 @@ off_t Input::seek(off_t offset, int whence) throw (GeneralException) {
}
int Input::wrapopen(const String & fname, openresults_t * results) {
- LOCK;
#ifdef DEBUG
printm(M_INFO, _("Wrap-opening ") + fname + "\n");
#endif
@@ -238,21 +208,12 @@ void Input::SetZ(int l) throw(GeneralException) {
Handle::SetZ(l);
}
-Stdin_t::Stdin_t() { }
-
-bool Stdin_t::CanSeek() const {
- return 0;
-}
-
-String Stdin_t::GetName() const {
- return "Stdin";
-}
-
#ifdef HOOK_STDS
Stdin_t Stdin;
#endif
Archive * Archive::header = 0;
+iLock Archive::lock;
Archive::Archive(const String & fname, int atype) :
name(fname), archive(new Input(fname)), type(atype) {
@@ -366,6 +327,8 @@ void Archive::create() throw (GeneralException) {
archive->read(buffer, 4);
if (*((Uint32 *)buffer) != BUILTIN_SIG)
throw GeneralException(_("Archive: not in built-in format."));
+
+ lock.lock();
while (p) {
archive->read(buffer, 1);
len = *buffer;
@@ -386,27 +349,15 @@ void Archive::create() throw (GeneralException) {
}
}
filetree.compute_ptrs(archive->tell());
+ lock.unlock();
break;
default:
throw GeneralException(_("Archive: unsupported archive format."));
}
-
- next = header;
- prev = 0;
- header = this;
- if (next)
- next->prev = this;
-}
-
-Archive::~Archive() {
- if (prev)
- prev->next = next;
- if (next)
- next->prev = prev;
- if (header == this)
- header = next;
-
- delete archive;
+
+ do {
+ next = header;
+ } while (!Atomic::CmpXChgBool(&header, this, next));
}
Archive * Archive::inarchive(const String & fname) {
@@ -426,25 +377,11 @@ Archive * Archive::inarchive(const String & fname) {
}
int Archive::open(const String & fname, Input::openresults_t * results) {
-#if 0
- Archive * p;
-
- for (p = header; p; p = p->next) {
- bool t;
- t = p->inarchive(fname);
- if (t)
- return p->openin(fname, results);
- }
- throw IOGeneral(_("File `") + fname + _("' not found in archive collection."));
-#endif
return openin(fname, results);
}
-Handle * Archive::GetHandle() {
- return archive;
-}
-
bool Archive::inarchivein(const String & fname) {
+ lock.lock();
Archive::FileTree * p = filetree.Child();
ssize_t pos;
String name = fname;
@@ -472,11 +409,13 @@ bool Archive::inarchivein(const String & fname) {
}
}
}
+ lock.unlock();
return p != 0;
}
int Archive::openin(const String & fname, Input::openresults_t * results) throw (GeneralException) {
+ lock.lock();
Archive::FileTree * p = filetree.Child();
ssize_t pos;
String name = fname;
@@ -502,6 +441,7 @@ int Archive::openin(const String & fname, Input::openresults_t * results) throw
}
}
}
+ lock.unlock();
if (!p)
throw IOGeneral(_("File `") + fname + _("' not in archive ") + this->name);
@@ -533,20 +473,6 @@ Archive::FileTree::FileTree(const String & fname, size_t fsize, int ftype, Archi
}
}
-Archive::FileTree::~FileTree() {
- if (child)
- delete child;
- if (next)
- next->prev = prev;
- if (prev)
- prev->next = next;
- if (father) {
- if (father->child == this)
- father->child = next;
- father->touched();
- }
-}
-
void Archive::FileTree::touched() {
if (father)
father->touched();
@@ -575,19 +501,3 @@ int Archive::FileTree::compute_ptrs(size_t cptr) {
return size + ptr;
}
-
-Archive::FileTree * Archive::FileTree::Father() {
- return father;
-}
-
-Archive::FileTree * Archive::FileTree::Child() {
- return child;
-}
-
-Archive::FileTree * Archive::FileTree::Next() {
- return next;
-}
-
-Archive::FileTree * Archive::FileTree::Prev() {
- return prev;
-}