您必须将本机互斥锁公开给托管代码,如下所示:
C代码:
pthread_mutex_t* managed_get_mutex ()
{
return &db_mutex;
}
void managed_lock_mutex (pthread_mutex_t *mutex)
{
pthread_mutex_lock (mutex):
}
void managed_unlock_mutex (pthread_mutex_t *mutex)
{
phtread_mutex_unlock (mutex);
}
C#代码:
class NativMutex {
[DllImport ("nativeLibrary")]
public static export IntPtr get_managed_mutex ();
[DllImport ("nativeLibrary")]
public static export void managed_lock_mutex (IntPtr mutex);
[DllImport ("nativeLibrary")]
public static export void managed_unlock_mutex (IntPtr mutex);
}