@@ -254,7 +254,28 @@ vx_status Context::loadTarget(const vx_char* targetName)
254254
255255vx_status Context::unloadTarget (const vx_char* targetName)
256256{
257- return VX_ERROR_NOT_IMPLEMENTED;
257+ vx_status status = VX_FAILURE;
258+
259+ for (vx_uint32 t = 0u ; t < context->num_targets ; t++)
260+ {
261+ if (context->targets [t] &&
262+ strncmp (context->targets [t]->name , targetName, VX_MAX_TARGET_NAME) == 0 )
263+ {
264+ memset (&context->targets [t]->funcs , 0xFE , sizeof (vx_target_funcs_t ));
265+ if (context->targets [t]->decrementReference (VX_INTERNAL) == 0 )
266+ {
267+ /* The ReleaseReference() below errors out if the internal index is 0 */
268+ context->targets [t]->incrementReference (VX_INTERNAL);
269+ }
270+ Osal::unloadModule (context->targets [t]->module .handle );
271+ context->targets [t]->module .handle = VX_MODULE_INIT;
272+
273+ memset (context->targets [t]->module .name , 0 , sizeof (context->targets [t]->module .name ));
274+ status = Reference::releaseReference ((vx_reference*)&context->targets [t], VX_TYPE_TARGET, VX_INTERNAL, nullptr );
275+ }
276+ }
277+
278+ return status;
258279}
259280
260281vx_status Context::unloadTarget (vx_uint32 index, vx_bool unload_module)
@@ -758,8 +779,8 @@ VX_API_ENTRY vx_context VX_API_CALL vxCreateContext(void)
758779 if (context->num_targets == 0 )
759780 {
760781 VX_PRINT (VX_ZONE_ERROR, " No targets loaded!\n " );
761- // free(context);
762782 Osal::semPost (&context_lock);
783+ single_context.reset ();
763784 return nullptr ;
764785 }
765786
@@ -774,8 +795,11 @@ VX_API_ENTRY vx_context VX_API_CALL vxCreateContext(void)
774795 {
775796 VX_PRINT (VX_ZONE_WARNING, " Target %s failed to initialize!\n " , context->targets [t]->name );
776797 /* unload this module */
777- context->unloadTarget (t, vx_true_e);
778- break ;
798+ /* @TODO: unload target now or on context release? */
799+ /*
800+ * context->unloadTarget(t, vx_true_e);
801+ * break;
802+ */
779803 }
780804 else
781805 {
@@ -922,7 +946,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxReleaseContext(vx_context* c)
922946 /* de-initialize and unload each target */
923947 for (t = 0u ; t < context->num_targets ; t++)
924948 {
925- if (context->targets [t]->enabled == vx_true_e)
949+ /* if (context->targets[t]->enabled == vx_true_e) */
926950 {
927951 context->targets [t]->funcs .deinit (context->targets [t]);
928952 context->targets [t]->enabled = vx_false_e;
@@ -1118,7 +1142,7 @@ VX_API_ENTRY vx_status VX_API_CALL vxQueryContext(vx_context context, vx_enum at
11181142 case VX_CONTEXT_EXTENSIONS:
11191143 if (size <= sizeof (extensions) && ptr)
11201144 {
1121- strncpy (reinterpret_cast <char *>(ptr), extensions, sizeof (extensions) );
1145+ strncpy (reinterpret_cast <char *>(ptr), extensions, size );
11221146 }
11231147 else
11241148 {
0 commit comments