Back to index

lightning-sunbird  0.9+nobinonly
Public Types | Public Member Functions | Public Attributes | Private Member Functions | Friends
Hammer Class Reference
Inheritance diagram for Hammer:
Inheritance graph
[legend]
Collaboration diagram for Hammer:
Collaboration graph
[legend]

List of all members.

Public Types

enum  Action { sg_go, sg_stop, sg_done }
enum  Problem {
  sg_okay, sg_open, sg_close, sg_delete,
  sg_write, sg_seek
}

Public Member Functions

virtual ~Hammer ()
 Hammer (RCThread::Scope scope, RCLock *lock, RCCondition *cond, PRUint32 clip)
virtual PRUint32 Random ()

Public Attributes

Action action
Problem problem
PRUint32 writes
RCInterval timein

Private Member Functions

void RootFunction ()

Friends

class Hammer

Detailed Description

Definition at line 102 of file ranfile.cpp.


Member Enumeration Documentation

enum HammerData::Action [inherited]
Enumerator:
sg_go 
sg_stop 
sg_done 

Definition at line 80 of file ranfile.cpp.

enum HammerData::Problem [inherited]
Enumerator:
sg_okay 
sg_open 
sg_close 
sg_delete 
sg_write 
sg_seek 

Definition at line 82 of file ranfile.cpp.


Constructor & Destructor Documentation

Hammer::~Hammer ( ) [virtual]

Definition at line 148 of file ranfile.cpp.

{ }
Hammer::Hammer ( RCThread::Scope  scope,
RCLock *  lock,
RCCondition *  cond,
PRUint32  clip 
)

Definition at line 150 of file ranfile.cpp.

                                                                        :
       HammerData(lock, cond, clip), RCThread(scope, RCThread::joinable, 0) { }

Member Function Documentation

PRUint32 HammerData::Random ( ) [virtual, inherited]

Definition at line 136 of file ranfile.cpp.

{
    PRUint32 rv;
    PRUint64 shift;
    RCInterval now = RCInterval(RCInterval::now);
    PRFloat64 random = seed * (PRFloat64)((PRIntervalTime)now);
    LL_USHR(shift, *((PRUint64*)&random), 16);
    LL_L2UI(rv, shift);
    seed = (PRFloat64)rv;
    return rv;
}  /* HammerData::Random */

Here is the call graph for this function:

Here is the caller graph for this function:

void Hammer::RootFunction ( ) [private]

Definition at line 194 of file ranfile.cpp.

{
    PRUint32 index;
    RCFileIO file;
    char filename[30];
    const char zero = 0;
    PRStatus rv = PR_SUCCESS;

    limit = (Random() % limit) + 1;

    (void)sprintf(filename, "%ssg%04p.dat", baseName, this);

    if (debug_mode) PR_fprintf(output, "Starting work on %s\n", filename);

    while (PR_TRUE)
    {
        PRUint64 bytes;
        PRUint32 minor = (Random() % limit) + 1;
        PRUint32 random = (Random() % limit) + 1;
        PRUint32 pages = (Random() % limit) + 10;
        while (minor-- > 0)
        {
            problem = sg_okay;
            if (action != sg_go) goto finished;
            problem = sg_open;
            rv = file.Open(filename, PR_RDWR|PR_CREATE_FILE, 0666);
            if (PR_FAILURE == rv) goto finished;
            for (index = 0; index < pages; index++)
            {
                problem = sg_okay;
                if (action != sg_go) goto close;
                problem = sg_seek;
                bytes = file.Seek(pageSize * index, RCFileIO::set);
                if (bytes != pageSize * index) goto close;
                problem = sg_write;
                bytes = file.Write(&zero, sizeof(zero));
                if (bytes <= 0) goto close;
                writes += 1;
            }
            problem = sg_close;
            rv = file.Close();
            if (rv != PR_SUCCESS) goto purge;

            problem = sg_okay;
            if (action != sg_go) goto purge;

            problem = sg_open;
            rv = file.Open(filename, PR_RDWR, 0666);
            if (PR_FAILURE == rv) goto finished;
            for (index = 0; index < pages; index++)
            {
                problem = sg_okay;
                if (action != sg_go) goto close;
                problem = sg_seek;
                bytes = file.Seek(pageSize * index, RCFileIO::set);
                if (bytes != pageSize * index) goto close;
                problem = sg_write;
                bytes = file.Write(&zero, sizeof(zero));
                if (bytes <= 0) goto close;
                writes += 1;
                random = (random + 511) % pages;
            }
            problem = sg_close;
            rv = file.Close();
            if (rv != PR_SUCCESS) goto purge;
            problem = sg_delete;
            rv = file.Delete(filename);
            if (rv != PR_SUCCESS) goto finished;
       }
    }

close:
    (void)file.Close();
purge:
    (void)file.Delete(filename);
finished:
    RCEnter scope(ml);
    action = HammerData::sg_done;
    cv->Notify();

    if (debug_mode) PR_fprintf(output, "Ending work on %s\n", filename);

    return;
}  /* Hammer::RootFunction */

Here is the call graph for this function:


Friends And Related Function Documentation

friend class Hammer [friend, inherited]

Definition at line 93 of file ranfile.cpp.


Member Data Documentation

Definition at line 89 of file ranfile.cpp.

Definition at line 90 of file ranfile.cpp.

RCInterval HammerData::timein [inherited]

Definition at line 92 of file ranfile.cpp.

Definition at line 91 of file ranfile.cpp.


The documentation for this class was generated from the following file: