trouble building emptool

Posted by: techtom

trouble building emptool - 14/11/2013 06:33

I'm trying to compile emptool 2.00. I've fixed most of the issues and updated the python scripts with re, removing regex. I'm having a problem with the mutex.h file. Any cpp file that uses mutex.h has the same error:

Code:
make BUILD=car2 ARCH=pc emptool
make -C car-support/emptool
make[1]: Entering directory `/drive0/sswazey/empeg/emptool-release-2.00/car-support/emptool'
make[2]: Entering directory `/drive0/sswazey/empeg/emptool-release-2.00/lib/core'
Compiling dnew.cpp
In file included from dnew.cpp:40:
mutex.h:62: error: base type ‘pthread_mutex_t’ fails to be a struct or class type
mutex.h:87: error: field ‘mutex’ has incomplete type
mutex.h: In member function ‘RawMutex* Mutex::GetRawMutex()’:
mutex.h:120: error: ‘mutex’ was not declared in this scope
make[2]: *** [pc-car2-debug2/dnew.o] Error 1
make[2]: Leaving directory `/drive0/sswazey/empeg/emptool-release-2.00/lib/core'
make[1]: *** [.lib-empeg_core] Error 2
make[1]: Leaving directory `/drive0/sswazey/empeg/emptool-release-2.00/car-support/emptool'
make: *** [emptool] Error 2
Posted by: mlord

Re: trouble building emptool - 14/11/2013 12:01

#include <pthread.h> ?
Posted by: techtom

Re: trouble building emptool - 14/11/2013 16:44

Originally Posted By: mlord
#include <pthread.h> ?


I thought the same thing. I added a declaration of pthread_mutex_t test_me; and test_me works fine, but the RawMutex class does not.

Code:
pthread_mutex_t test_me;

class RawMutex : public pthread_mutex_t
{
 public:
    RawMutex();    // a bit too complex to inline
    ~RawMutex()    { pthread_mutex_destroy(this); }
    void Lock()    { pthread_mutex_lock(this); }
    void Unlock()  { pthread_mutex_unlock(this); }
    bool TryLock() { return pthread_mutex_trylock(this) == 0; }
};

Posted by: canuckInOR

Re: trouble building emptool - 14/11/2013 17:10

Quote:
Code:
mutex.h:62: error: base type ‘pthread_mutex_t’ fails to be a struct or class type

On my system (Ubuntu 10.04), pthread_mutex_t is actually defined in <bits/pthreadtypes.h> as a union, rather than a struct (as it was in older versions of <pthread.h>). You'll need to rework the RawMutex class.
Posted by: techtom

Re: trouble building emptool - 15/11/2013 06:39

Originally Posted By: canuckInOR

On my system (Ubuntu 10.04), pthread_mutex_t is actually defined in <bits/pthreadtypes.h> as a union, rather than a struct (as it was in older versions of <pthread.h>). You'll need to rework the RawMutex class.


Yes. I am on Ubuntu 10 too. I saw the union in bits/pthreads.h but I wasn't sure it was the problem. Can you explain how the RawMutex class would need to be modified to allow a typedef'd union rather than a typedef'd struct?

Thanks,

-Scott
Posted by: Roger

Re: trouble building emptool - 15/11/2013 10:50

Originally Posted By: techtom
I saw the union in bits/pthreads.h but I wasn't sure it was the problem.


You can't inherit from a union. Not sure how to fix this, though.
Posted by: canuckInOR

Re: trouble building emptool - 15/11/2013 15:38

With a cursory 30-second overview of the code (aka, it's highly likely I missed something), it looks like RawMutex simply encapsulates the WIN32/linux cross-platform differences, so I suspect that if you changed the class to use a member variable, that would be sufficient:

Code:
class RawMutex
{
 private:
    pthread_mutex_t m;
 public:
    RawMutex();    // a bit too complex to inline
    ~RawMutex()    { pthread_mutex_destroy(&m); }
    void Lock()    { pthread_mutex_lock(&m); }
    void Unlock()  { pthread_mutex_unlock(&m); }
    bool TryLock() { return pthread_mutex_trylock(&m) == 0; }
};

And then in lib/core/mutex.cpp:
Code:
RawMutex::RawMutex()
{
    pthread_mutexattr_t attr;

    pthread_mutexattr_init(&attr);
#ifdef __USE_UNIX98
    pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
#else
    pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP /*ERRORCHECK_NP*/);
#endif
    int i = pthread_mutex_init(&m, &attr);
    if (i)
    {
#if DEBUG>0
        WARN("Couldn't create mutex at %p.\n", &m);
#endif
        WARN("Result of creating mutex: %d\n", i);
        ASSERT(false);
    }
    pthread_mutexattr_destroy(&attr);
}
Posted by: techtom

Re: trouble building emptool - 15/11/2013 16:38

Originally Posted By: Roger
Originally Posted By: techtom
I saw the union in bits/pthreads.h but I wasn't sure it was the problem.

You can't inherit from a union. Not sure how to fix this, though.


Thanks Roger! Here's what I did. I created my own fix_pthread_mutex_t from one of the structures in the union. Then I modified the code:
Code:
class RawMutex : public fix_pthread_mutex_t
{
 public:
    RawMutex();    // a bit too complex to inline
    ~RawMutex()    { pthread_mutex_destroy((pthread_mutex_t*)this); }
    void Lock()    { pthread_mutex_lock((pthread_mutex_t*)this); }
    void Unlock()  { pthread_mutex_unlock((pthread_mutex_t*)this); }
    bool TryLock() { return pthread_mutex_trylock((pthread_mutex_t*)this) == 0; }
};


The dnew.cpp file compiles now and I am on to the next bug:

Compiling cyclecheck.cpp
In file included from cyclecheck.cpp:17:
cyclecheck2.h: In member function ‘bool CycleChecker<T>::Search(T, T, std::list<T, std::allocator<_Tp1> >&, std::set<T, std::less<_Key>, std::allocator<_Tp1> >&, bool, bool)’:
cyclecheck2.h:90: error: expected ‘;’ before ‘i’
cyclecheck2.h:91: error: ‘i’ was not declared in this scope
cyclecheck2.h:111: error: expected ‘;’ before ‘i’
cyclecheck2.h:112: error: ‘i’ was not declared in this scope
cyclecheck2.h: In member function ‘void CycleChecker<T>::Dump()’:
cyclecheck2.h:132: error: expected ‘;’ before ‘i’
cyclecheck2.h:132: error: ‘i’ was not declared in this scope


Code:
template<typename T> bool CycleChecker<T>::Search( T start,
                                                   T searchfor,
                                                   std::list<T>& result,
                                                   std::set<T>& seen,
                                                   bool weak,
                                                   bool findstrong )
{
    const set_t& children = graph[start];

    seen.insert( start );

    for ( set_t::const_iterator i = children.begin();
          i != children.end();
          ++i )
    {

line 90 is:
Code:
   for ( set_t::const_iterator i = children.begin();

Any ideas?
Posted by: canuckInOR

Re: trouble building emptool - 15/11/2013 18:12

Originally Posted By: techtom
Code:
   for ( set_t::const_iterator i = children.begin();

Any ideas?

I hate futzing with template typedef crap in C++. Change all of those const_iterator definitions to auto:
Code:
    for ( auto i = children.begin();

and, in Make.rules.gcc, around line 184, add the -std=c++0x flag (and remove the -fno-rtti):
Code:
TARGET_COMPILEFLAGS=-c -pipe -Wall -Wundef -W -Wpointer-arith -Wconversion -Wstrict-prototypes -Wwrite-strings $(TARGET_CPUFLAGS) $(TARGET_INCLUDEPATH) $(TARGET_DEFINES) $(TARGET_DBG2) -D_GNU_SOURCE
TARGET_CFLAGS=$(TARGET_COMPILEFLAGS)
ifeq ($(ARCH), arm)
TARGET_CXXFLAGS=-fno-exceptions $(TARGET_COMPILEFLAGS)
else
TARGET_CXXFLAGS=-std=c++0x -m32 $(TARGET_COMPILEFLAGS)
endif
Posted by: techtom

Re: trouble building emptool - 16/11/2013 08:42

Got it working.

Thanks for the help!

-Scott