Closed GoogleCodeExporter closed 9 years ago
One more thing need to mention, compiling 'ting' under Solaris, we need to add
"-lrt"
to gcc arguments, since all sem_*() is belong to librt.
Original comment by Dancef...@gmail.com
on 3 Aug 2008 at 7:02
Hi Dancefire,
>I'm curious, why not just put #ifdef #elif #endif for platform into
>ting.hpp, rather than ting.cpp?
What I wanted to achieve by doing so is to eliminate dependency of ting.hpp from
other .h files (except std lib headers), so when the lib is compiled as dll the
user
only needs to have ting.hpp and ting.dll and does not necessarily need to have other
stuff as windows.h etc. to compile. Keeping SystemIndependentXxxxxHandle large
should
not make large memory usage impact on modern systems with gigabytes of RAM.
Well, now I see that such approach has its own difficulties, and now I'm not
sure
that a benefit from this is large enough, so I may be considering rewriting the
ting
to have platform #ifdefs in .hpp.
Do you think my initial idea with #ifdefs in .cpp does not have any reason to
exist?
I'm asking because now I'm not sure it really does...
Original comment by igagis@gmail.com
on 3 Aug 2008 at 9:38
I think in most environments under windows, <windows.h> is installed by default.
otherwise, just install PlatformSDK, and the user will got what he need. It
should
not be a problem for a developer, since for most Windows developer, <windows.h>
is
necessary, even if ting doesn't depend on it, the developer will eventually
install
the PlatformSDK or alternative for other components in the projects.
If it's still not acceptable, we can define the type by ourself, such as:
#ifdef (WIN32)
typedef void* semaphore_type;
#else
typedef sem_t semaphore_type;
#endif
since, WinNT.h:typedef void *HANDLE;
And there might be another way to do it, just use void* pointer in the .hpp,
and cast
to the correct type when use it(in .cpp). such as:
[ting.hpp]
class Semaphore{
...
void* handle;
};
[ting.cpp]
#if defined(__WIN32__) || defined(WIN32)
...
typedef HANDLE semaphore_type;
#elif defined(__SYMBIAN32__)
...
typedef RSemaphore semaphore_type;
#else //assume pthread
...
typedef sem_t semaphore_type;
#endif
...
inline static semaphore_type& CastToSemaphore(void* sem){
return reinterpret_cast<semaphore_type>(*sem);
};
...
Semaphore::Semaphore(uint initialValue){
this->handle = new semaphore_type();
semaphore_type& s = CastToSemaphore(this->handle);
#ifdef __WIN32__
s = CreateSemaphore(NULL, initialValue, 0xffffff, NULL);
if(s == NULL){
throw ting::Exc("Semaphore::Semaphore(): creating semaphore failed");
}
#elif defined(__SYMBIAN32__)
if(s.CreateLocal(initialValue) != KErrNone){
throw ting::Exc("Semaphore::Semaphore(): creating semaphore failed");
}
#else //pthread
if( sem_init(&s, 0, initialValue) < 0 ){
throw ting::Exc("Semaphore::Semaphore(): creating semaphore failed");
}
#endif
};
Original comment by Dancef...@gmail.com
on 3 Aug 2008 at 12:49
Hi Dancefire,
I think that it will be better to just use the old good method, i.e. add the
platform
specific #ifdef's into .hpp and get rid of SystemIndependentSemaphoreHandle and
CastToSemaphore things.
By the way, would you join the ting project? I'm not always have enough time to
work
on the project, so I would not refuse some help.
Original comment by igagis@gmail.com
on 4 Aug 2008 at 9:24
Ok, using #ifdefs in hpp should not be a problem.
I don't have a lot of time either, however, I can contribute some of my time to
the
project. So, may I join the project?
Original comment by Dancef...@gmail.com
on 5 Aug 2008 at 7:53
Hi Dancefire,
I added you to the project members.
Original comment by igagis@gmail.com
on 5 Aug 2008 at 9:36
I suppose this issue is no longer visible on the latest trunk revision.
Closing the issue now. If it still exists indicate it there please and the
Issue will
be reopened.
Original comment by igagis@gmail.com
on 10 Nov 2008 at 8:11
Original issue reported on code.google.com by
Dancef...@gmail.com
on 2 Aug 2008 at 4:37