ml_pipeline *p; \
ml_pipeline_element *elem; \
int ret = ML_ERROR_NONE; \
+ check_feature_state (); \
if ((h) == NULL) { \
ml_loge ("The given handle is invalid"); \
return ML_ERROR_INVALID_PARAMETER; \
{
handle_init (sink, sink, h);
- check_feature_state ();
-
if (elem->handle_id > 0) {
g_signal_handler_disconnect (elem->element, elem->handle_id);
elem->handle_id = 0;
{
handle_init (src, src, h);
- check_feature_state ();
-
elem->handles = g_list_remove (elem->handles, src);
g_free (src);
handle_init (src, src, h);
- check_feature_state ();
-
_data = (ml_tensors_data_s *) data;
if (!_data) {
ml_loge ("The given param data is invalid.");
{
handle_init (src, src, h);
- check_feature_state ();
-
if (info == NULL) {
ret = ML_ERROR_INVALID_PARAMETER;
goto unlock_return;
{
handle_init (switch, swtc, h);
- check_feature_state ();
-
elem->handles = g_list_remove (elem->handles, swtc);
g_free (swtc);
handle_init (switch, swtc, h);
- check_feature_state ();
-
if (pad_name == NULL) {
ml_loge ("The second argument, pad name, is not valid.");
ret = ML_ERROR_INVALID_PARAMETER;
handle_init (switch, swtc, h);
- check_feature_state ();
-
if (list == NULL) {
ml_loge ("The second argument, list, is not valid.");
ret = ML_ERROR_INVALID_PARAMETER;
{
handle_init (valve, valve, h);
- check_feature_state ();
-
elem->handles = g_list_remove (elem->handles, valve);
g_free (valve);
gboolean drop = FALSE;
handle_init (valve, valve, h);
- check_feature_state ();
-
g_object_get (G_OBJECT (elem->element), "drop", &drop, NULL);
if ((open != false) != (drop != FALSE)) {
#include <system_info.h>
#endif
-/** -1: Not checked yet, 0: Not supported, 1: Supported */
-static int feature_enabled = -1;
+/**
+ * @brief Internal struct to control tizen feature support (machine_learning.inference).
+ * -1: Not checked yet, 0: Not supported, 1: Supported
+ */
+typedef struct
+{
+ GMutex mutex;
+ int feature_status;
+} feature_info_s;
+
+static feature_info_s *feature_info = NULL;
+
+/**
+ * @brief Internal function to initialize feature status.
+ */
+static void
+ml_initialize_feature_status (void)
+{
+ if (feature_info == NULL) {
+ feature_info = g_new0 (feature_info_s, 1);
+ g_assert (feature_info);
+
+ g_mutex_init (&feature_info->mutex);
+ feature_info->feature_status = -1;
+ }
+}
/**
* @brief Allocates a tensors information handle with default value.
size_t tensor_size;
gint i;
+ if (ML_ERROR_NONE != ml_get_feature_enabled())
+ return 0;
+
tensors_info = (ml_tensors_info_s *) info;
if (!tensors_info)
/**
* @brief Checks whether machine_learning.inference feature is enabled or not.
*/
-int ml_get_feature_enabled (void)
+int
+ml_get_feature_enabled (void)
{
+ ml_initialize_feature_status ();
+
#if defined(__TIZEN__)
- if (0 == feature_enabled) {
- ml_loge ("machine_learning.inference NOT supported");
- return ML_ERROR_NOT_SUPPORTED;
- } else if (-1 == feature_enabled) {
- bool ml_inf_supported = false;
- if (0 == system_info_get_platform_bool(ML_INF_FEATURE_PATH, &ml_inf_supported)) {
- if (false == ml_inf_supported) {
- ml_loge ("machine_learning.inference NOT supported");
- ml_set_feature_status (0);
- return ML_ERROR_NOT_SUPPORTED;
- }
+ {
+ int feature_enabled;
- ml_set_feature_status (1);
- } else {
- ml_loge ("failed to get feature value of machine_learning.inference");
+ g_mutex_lock (&feature_info->mutex);
+ feature_enabled = feature_info->feature_status;
+ g_mutex_unlock (&feature_info->mutex);
+
+ if (0 == feature_enabled) {
+ ml_loge ("machine_learning.inference NOT supported");
return ML_ERROR_NOT_SUPPORTED;
+ } else if (-1 == feature_enabled) {
+ bool ml_inf_supported = false;
+ if (0 == system_info_get_platform_bool(ML_INF_FEATURE_PATH, &ml_inf_supported)) {
+ if (false == ml_inf_supported) {
+ ml_loge ("machine_learning.inference NOT supported");
+ ml_set_feature_status (0);
+ return ML_ERROR_NOT_SUPPORTED;
+ }
+
+ ml_set_feature_status (1);
+ } else {
+ ml_loge ("failed to get feature value of machine_learning.inference");
+ return ML_ERROR_NOT_SUPPORTED;
+ }
}
}
#endif
/**
* @brief Set the feature status of machine_learning.inference.
*/
-int ml_set_feature_status (int status)
+int
+ml_set_feature_status (int status)
{
- GMutex mutex;
- g_mutex_init (&mutex);
- g_mutex_lock (&mutex);
+ ml_initialize_feature_status ();
+ g_mutex_lock (&feature_info->mutex);
- /** Update feature status
- * -1: Not checked yet, 0: Not supported, 1: Supported
- */
- feature_enabled = status;
+ /**
+ * Update feature status
+ * -1: Not checked yet, 0: Not supported, 1: Supported
+ */
+ feature_info->feature_status = status;
- g_mutex_unlock (&mutex);
- g_mutex_clear (&mutex);
+ g_mutex_unlock (&feature_info->mutex);
return ML_ERROR_NONE;
}