Skip to content

Commit 60c5c53

Browse files
committed
cleanup some loose ends
1 parent 2d2e422 commit 60c5c53

4 files changed

Lines changed: 31 additions & 29 deletions

File tree

include/reflex/timer.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ inline float timer_elapsed(timer_type& t) ///< timer to be updated
5959
{
6060
timer_type now;
6161
GetLocalTime(&now);
62-
float sec = now.wMilliseconds;
63-
sec -= t.wMilliseconds;
62+
float ms = now.wMilliseconds;
63+
ms -= t.wMilliseconds;
6464
t.wMilliseconds = now.wMilliseconds;
65-
sec += 1000.0f * (now.wSecond - t.wSecond);
65+
ms += 1000.0f * (now.wSecond - t.wSecond);
6666
t.wSecond = now.wSecond;
67-
if (sec < 0.0)
68-
sec += 60000.0;
69-
return sec;
67+
if (ms < 0.0)
68+
ms += 60000.0;
69+
return ms;
7070
}
7171

7272
} // namespace reflex
@@ -91,14 +91,14 @@ inline float timer_elapsed(timer_type& t) ///< timer to be updated
9191
{
9292
timer_type now;
9393
gettimeofday(&now, NULL);
94-
float sec = now.tv_usec;
95-
sec -= t.tv_usec;
94+
float ms = now.tv_usec;
95+
ms -= t.tv_usec;
9696
t.tv_usec = now.tv_usec;
97-
sec = 1000.0 * (now.tv_sec - t.tv_sec) + sec/1000.0;
97+
ms = 1000.0 * (now.tv_sec - t.tv_sec) + ms/1000.0;
9898
t.tv_sec = now.tv_sec;
99-
if (sec < 0.0)
100-
sec += 60000.0;
101-
return sec;
99+
if (ms < 0.0)
100+
ms += 60000.0;
101+
return ms;
102102
}
103103

104104
} // namespace reflex

lib/input.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ bool Input::file_ready()
10311031
if (file_ == NULL || feof(file_))
10321032
return false;
10331033
#if (defined(__WIN32__) || defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(__BORLANDC__)) && !defined(__CYGWIN__) && !defined(__MINGW32__) && !defined(__MINGW64__)
1034-
return true;
1034+
return !ferror(file_);
10351035
#else
10361036
if (ferror(file_))
10371037
{
@@ -1042,9 +1042,8 @@ bool Input::file_ready()
10421042
if (errno == EAGAIN)
10431043
{
10441044
struct stat buf;
1045-
fstat(fileno(file_), &buf);
1046-
if (S_ISREG(buf.st_mode))
1047-
return false;
1045+
if (fstat(fileno(file_), &buf) == 0 && S_ISREG(buf.st_mode))
1046+
return false
10481047
}
10491048
#endif
10501049
}

lib/pattern.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4404,7 +4404,7 @@ void Pattern::analyze_dfa(DFA::State *start)
44044404
}
44054405
for (Hash i = 0; i < Const::HASH; ++i)
44064406
{
4407-
if (pma_[i] != (1 << (8 * Const::PM_M)) - 1)
4407+
if (pma_[i] != (1 << (2 * Const::PM_M)) - 1)
44084408
{
44094409
if (isprint(i))
44104410
DBGLOGN("pma['%c'] = %04x", i, pma_[i]);
@@ -4541,14 +4541,14 @@ void Pattern::gen_predict_match_transitions(uint16_t level, DFA::State *state, c
45414541
std::pair<ORanges<Hash>,ORanges<Char> > *next_hashes = (level + 1 < Const::BITS && !next_accept) ? &level_hashes[next_state] : NULL;
45424542
Char lo = edge.lo();
45434543
Char hi = edge.hi();
4544-
DBGLOG("PM level %zu %p: %u~%u %s%s", level, state, lo, hi, next_accept ? "accept " : "", next_hashes ? "nexthashes" : "");
4544+
DBGLOG("PM level %hu %p: %u~%u %s%s", level, state, lo, hi, next_accept ? "accept " : "", next_hashes ? "nexthashes" : "");
45454545
if (level < min_)
45464546
{
45474547
// populate bit array
45484548
Bitap mask = ~(1 << level);
45494549
for (Char ch = lo; ch <= hi; ++ch)
45504550
bit_[ch] &= mask;
4551-
DBGLOG("%zu bitap %p: %u..%u -> %p", level, state, lo, hi, next_state);
4551+
DBGLOG("%hu bitap %p: %u..%u -> %p", level, state, lo, hi, next_state);
45524552
// update tap_[] bitap hashed pairs at previous level using previous character ranges
45534553
mask >>= 1;
45544554
for (ORanges<Char>::iterator prev_range = previous.second.begin(); prev_range != previous.second.end(); ++prev_range)

src/zthread.hpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ struct Zthread {
9898
pipe_fd[1] = -1;
9999
}
100100

101-
~Zthread()
101+
// no copy constructor
102+
Zthread(const Zthread&) = delete;
103+
104+
// destructor
105+
virtual ~Zthread()
102106
{
103107
// recursively join all stages of the decompression thread chain (--zmax>1), delete zstream
104108
join();
@@ -124,6 +128,7 @@ struct Zthread {
124128
// partnameref is not assigned yet, used only when this decompression thread is chained
125129
is_assigned = false;
126130

131+
// flag to inform main thread what's going on when it calls decompressing()
127132
is_compressed = false;
128133

129134
// open pipe between the main thread or the previous decompression thread and this (new) decompression thread
@@ -233,12 +238,10 @@ struct Zthread {
233238
pipe_fd[0] = -1;
234239

235240
// if extracting and the decompression filter thread is not yet waiting, then wait until decompression thread closed its end of the pipe
236-
{
237-
std::unique_lock<std::mutex> lock(pipe_mutex);
238-
if (!is_waiting)
239-
pipe_close.wait(lock);
240-
lock.unlock();
241-
}
241+
std::unique_lock<std::mutex> lock(pipe_mutex);
242+
if (!is_waiting)
243+
pipe_close.wait(lock);
244+
lock.unlock();
242245

243246
// partnameref is not assigned yet, used only when this decompression thread is chained
244247
is_assigned = false;
@@ -254,8 +257,8 @@ struct Zthread {
254257
// if chained before another decompression thread
255258
if (is_chained)
256259
{
257-
// use lock and wait for partname ready
258-
std::unique_lock<std::mutex> lock(pipe_mutex);
260+
// wait for partname ready
261+
lock.lock();
259262
// notify the decompression filter thread of the new pipe
260263
pipe_ready.notify_one();
261264
// wait for the partname to be set by the next decompression thread in the ztchain
@@ -289,7 +292,7 @@ struct Zthread {
289292
pipe_ready.notify_one();
290293

291294
// when an error occurred, we still need to notify the receiver in case it is waiting on the partname
292-
std::unique_lock<std::mutex> lock(pipe_mutex);
295+
lock.lock();
293296
is_assigned = true;
294297
part_ready.notify_one();
295298
lock.unlock();

0 commit comments

Comments
 (0)