[Messaging] Prevent crash on getMessageServices call 28/196828/3
authorPawel Wasowski <p.wasowski2@partner.samsung.com>
Wed, 19 Dec 2018 18:05:20 +0000 (19:05 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Wed, 9 Jan 2019 08:21:23 +0000 (08:21 +0000)
commit72b11a844a35f3dafc652001e1bcfac74c5daf28
tree66ecd682bced56cf7fed9e32dda23d49de1aa775
parentb28a1d398fccfe1eb9c5d2d8ebc51faeb8e8d7c1
[Messaging] Prevent crash on getMessageServices call

Calling tizen.messaging.getMessageServices() multiple times at
short intervals used to cause a crash, due to race condition, occurring
between different threads, modifying the same MessagingManager
instance's fields.
The fix moves execution of the underlying implementation to the main
thread - it is not called concurrently. The function execution time
is typically below 2 ms, so moving it to the main thread should
not worsen user experience.

[Verification] tct-tizen-messaging-email-tests pass rate: 100%
               tct-tizen-messaging-sms-tests pass rate: 100%
               tct-tizen-messaging-mms-tests pass rate: 100%
               A code snippet, that used to cause a crash, does not
               cause crash now:
               for (var i = 0; i < 1000; ++i) {
                   tizen.messaging.getMessageServices('messaging.email',
                                                      s=>{console.log(s);},
                                                      e=>{console.error(e);});
               }

Change-Id: I2f140281e64aeffea1ad9ca15f99ee38378693d3
Signed-off-by: Pawel Wasowski <p.wasowski2@partner.samsung.com>
src/messaging/messaging_manager.cc
src/messaging/messaging_manager.h