Mutexes in C++ Classes

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Mutexes in C++ Classes

ソリューションへジャンプ
1,490件の閲覧回数
louiemoye
Contributor III

Hi - background dev tool info:  I'm using CW10.6, MQX 4.1, K70 processor, custom BSP cloned from K70 tower board.

I seem to be having issues when trying to initialize a mutex in my C++ class.  I can successfully create a mutex in my main task, however any attempt to create/init a mutex in a C++ class fails and returns !MQX_OK.  I tried several examples deom the MQX manuals, and from the forums, but no success.  My function (below) is successful if called from main, but unsuccessful if called from my C++ class.  I've also tried initializing using a mutex attribute and attribute init:

/***** CODE START *****/

MUTEX_STRUCT_PTR InitMutex()

{

  MUTEX_STRUCT  newMutex;

  // Initialize the mutex 

  if (_mutex_init(&newMutex, 0) != MQX_OK)

  {

  printf("Initialize print mutex failed.\n");

  _task_block();

  }

  // Test the new mutex

  if (_mutex_lock(&newMutex) == MQX_OK)

  {

  printf("Mutex lock worked.\n");

  }

  _mutex_unlock(&newMutex);

  return (MUTEX_STRUCT_PTR)&newMutex;

}

/***** CODE END *****/

Then call with

/***** CODE START *****/

MUTEX_STRUCT_PTR m_ptrQueueMutex = InitMutex();

  if (m_ptrQueueMutex != NULL)

    printf("Got a mutex pointer\n");

/***** CODE END *****/

In main, I get this output:

"Mutex lock worked"

"Got a mutex pointer"

And in my class I get:

"Initialize print mutex failed."

Any help or suggestions will be greatly appreciated.

0 件の賞賛
返信
1 解決策
1,327件の閲覧回数
matthewkendall
Contributor V

Is your object a global, with a constructor that is being called before MQX is started perhaps?

https://community.freescale.com/message/349610

元の投稿で解決策を見る

2 返答(返信)
1,328件の閲覧回数
matthewkendall
Contributor V

Is your object a global, with a constructor that is being called before MQX is started perhaps?

https://community.freescale.com/message/349610

1,327件の閲覧回数
Carlos_Musich
NXP Employee
NXP Employee

Hi Louie,

I assume that you may be able to reproduce the same project using the default K70 BSP. Am I right? Modifying the BSP should not affect the Kernel behavior.

I ask you this because I need to reproduce this issue on my side with K70 default BSP. Can you confirm this and provide the project where you see this problem? It is ok if you create a simple project just to test this case.

Thanks!

Carlos

0 件の賞賛
返信