Skip to main content

a specific question about mpeos_sync

3 replies [Last post]
yelin
Offline
Joined: 2010-06-30

I got stuck in pthread_mutex_lock(mutex) in line 150 of function mpeos_mutexAcquire(mpe_Mutex mutex) (in file mpe/os/RI_Linux/mpeos_sync.c).

I used (gdb)print mutex and got "$1={runtime_mutex = 0x0, static_mutex = {pad = '\0' , dummy_double = 0, dummy_pointer = 0x0, dummy_log = 0}}".

Line 150 says "pRet = pthread_mutex_lock(mutex)", so I searched for prototype of pthread_mutex_lock(). In it says "int pthread_mutex_lock(pthread_mutex_t *mutex);" and the definition of pthread_mutex_t is a struct including following fields:
int spinlock
int mutex_type
uint32_t owner_thread_id
uint32_t recursion_counter
int mutex_handle

However, parameter "mutex" is an instance of mpe_Mutex. I found the following information:
typedef os_Mutex mpe_Mutex; (in mpeos_syn.h)
typedef struct _os_Mutex_Struct{
int _opaque;
};
typedef struct _os_Mutex_Struct *os_Mutex;

Can anyone tell me why this line can pass compilation? I'm a little bit confused here because I don't know what's the real prototype of parameter "mutex".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
greg80303
Offline
Joined: 2008-07-03

In mpe/os/RI_Linux/include/os_sync.h, you will find the following definition:

[code]
typedef pthread_mutex_t* os_Mutex;
[/code]

As you pointed out earlier, an mpe_Mutex is actually an os_Mutex. It is up to porting teams to define os_Mutex, to represent a mutex on their target operating system. So, in mpe/os/RI_Linux/mpeos_sync.c, anytime you see mpe_Mutex, we are really operating on a pthread_mutex_t*.

G

yelin
Offline
Joined: 2010-06-30

Thanks Greg.
Now I took JAVA/JNI/MPE layer from somewhere else, but used OCAP-RI's JVM+MPEOS+RI platform. When I tried to launch a HelloWorld app on RI, I got some "seg fault" error. The gdb dump says:
=========================
0x00688c0f in pthread_mutex_lock () from /lib/libpthread.so.0
[b]#0 0x00688c0f in pthread_mutex_lock () from /lib/libpthread.so.0
#1 0x022c7d10 in mpeos_mutexAcquire (mutex=0x2f6414) at ../RI_Linux/mpeos_sync.c:150[/b]
#2 0x022b8604 in mpeos_eventQueueWaitNext (queueId=0x0, eventId=0x9582b370, eventData1=0x9582b36c, eventData2=0x0, eventFlag=0x0, timeout=0) at ../RI_Linux/mpeos_event.c:470
#3 0x0230a3b1 in sitp_siWorkerThread (data=0x0) at mgr/simgr/sitp_si.c:630
#4 0x022c8a5a in threadStart (tls=0x9ec10848) at ../RI_Linux/mpeos_thread.c:282
#5 0x0068751f in start_thread () from /lib/libpthread.so.0
#6 0x005e804e in clone () from /lib/libc.so.6
...
=========================

And I printed out the value of mutex:
(gdb)print mutex
$1={runtime_mutex = 0x0, static_mutex = {pad = '\0' , dummy_double = 0, dummy_pointer = 0x0, dummy_log = 0}}

(gdb)print &mutex
$2=(GStaticMutex *)0x .....

I guess the reason I got seg fault error is that pthread_mutex_lock expecting a mutex of type (pthread_mutex_t *) received a GStaticMutex mutex. GStaticMutex is defined in Glibconfig.h under glib lib, but I'm not sure why here mutex is not treated/defined as (pthread_mutex_t *)... >_< Any idea? (Does it have something to do with the Makefile under mpe/os/RI_Linux?)

Message was edited by: yelin

Message was edited by: yelin

greg80303
Offline
Joined: 2008-07-03

I'm not sure I can help too much. What you are describing is very complex mixture of code. I'm not sure how you're combining pieces of the stack from multiple sources, but there is certainly some potential problems that can arise if its not done correctly. That is, if it can even be done at all -- I'm pretty sure nobody on the development team has tried it.

G