Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@
},
],
"files.associations": {
"map": "cpp"
"map": "cpp",
"sc_event_subscription.h": "c",
"sc_monitor_private.h": "c",
"sc_types.h": "c",
"sc_list.h": "c",
"sc_memory_params.h": "c",
"sc_mutex.h": "c"
}
}
Binary file added glib-2.76.4.tar.xz
Binary file not shown.
6 changes: 3 additions & 3 deletions sc-kpm/sc-ui/src/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#ifndef _ui_h_
#define _ui_h_

extern "C"
{
//extern "C"
//{
#include <sc-core/sc_memory_headers.h>
}
//}

extern "C"
{
Expand Down
1 change: 1 addition & 0 deletions sc-memory/sc-core/include/sc-container/sc_hash_table.h
34 changes: 34 additions & 0 deletions sc-memory/sc-core/include/sc-core/sc_event_subscription.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#define _sc_event_subscription_h_

#include "sc-core/sc_types.h"
#include "sc_event_queue.h"
#include "sc-core/sc-container/sc_list.h"

typedef struct _sc_event_subscription_manager sc_event_subscription_manager;

Expand Down Expand Up @@ -67,6 +69,16 @@ _SC_EXTERN sc_event_subscription * sc_event_subscription_new(
sc_event_callback callback,
sc_event_subscription_delete_function delete_callback);

_SC_EXTERN sc_event_subscription * sc_complex_event_subscription_new(
sc_memory_context const * ctx,
sc_addr subscription_addr,
sc_event_type event_type_addr,
sc_pointer data,
sc_event_callback callback,
sc_event_subscription_delete_function delete_callback,
sc_bool is_complex_event_subscription,
sc_list* events_list);

/*! Subscribe for events from specified sc-element.
* @param ctx A sc-memory context used to create sc-event subscription.
* @param subscription_addr sc-address of subscribed sc-element events.
Expand All @@ -87,6 +99,17 @@ _SC_EXTERN sc_event_subscription * sc_event_subscription_with_user_new(
sc_event_callback_with_user callback,
sc_event_subscription_delete_function delete_callback);

_SC_EXTERN sc_event_subscription * sc_complex_event_subscription_with_user_new(
sc_memory_context const * ctx,
sc_addr subscription_addr,
sc_event_type event_type_addr,
sc_type event_element_type,
sc_pointer data,
sc_event_callback_with_user callback,
sc_event_subscription_delete_function delete_callback,
sc_bool is_complex_event_subscription,
sc_list* events_list);

/*! Destroys the specified sc-event subscription.
* @param event_subscription Pointer to the sc-event subscription to be destroyed.
* @return Returns SC_RESULT_OK if the operation is successful, SC_RESULT_NO otherwise.
Expand Down Expand Up @@ -117,4 +140,15 @@ _SC_EXTERN sc_addr sc_event_subscription_get_event_type(sc_event_subscription co
*/
_SC_EXTERN sc_addr sc_event_subscription_get_element(sc_event_subscription const * event_subscription);

_SC_EXTERN sc_bool sc_event_subscription_is_complex(sc_event_subscription const * event_subscription);

_SC_EXTERN sc_result start_check_condition_to_activate_complex_event(sc_event_subscription* complex_event_subscription,
sc_memory_context const * ctx,
sc_addr subscription_addr,
sc_event_type event_type_addr,
sc_addr connector_addr,
sc_type connector_type,
sc_addr other_addr,
sc_event_do_after_callback callback,
sc_addr event_addr);
#endif
1 change: 1 addition & 0 deletions sc-memory/sc-core/include/sc_event_queue.h
1 change: 1 addition & 0 deletions sc-memory/sc-core/include/sc_hash_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "sc-core/sc-container/sc_queue.h"

#include "sc_mutex_private.h"
#include "sc-core/sc-base/sc_mutex_private.h"

struct _sc_monitor
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#ifndef _sc_hash_table_h_
#define _sc_hash_table_h_

#include <glib.h>
#include "/usr/include/glib-2.0/glib.h"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid hardcoding the absolute GLib include path. Replace "/usr/include/glib-2.0/glib.h" with <glib.h> and configure include paths in the build system.

Suggested change
#include "/usr/include/glib-2.0/glib.h"
#include <glib.h>

This comment was generated because it violated a code review rule: irule_Ah6kBzD0nPDBJTxk.


typedef GHashTable sc_hash_table;

Expand Down
21 changes: 21 additions & 0 deletions sc-memory/sc-core/src/sc-store/sc-event/sc_event_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

#include "sc-core/sc_event_subscription.h"
#include "sc-core/sc_types.h"
#include "sc-store/sc-base/sc_condition_private.h"
#include "sc-core/sc-container/sc_list.h"


#define SC_EVENT_REQUEST_DESTROY (sc_uint32)(1 << 31)

Expand All @@ -35,8 +38,26 @@ struct _sc_event_subscription
sc_monitor monitor;
//! Count of references (users) of this sc-event subscription
sc_uint32 ref_count;

//! flag: whether the event is complex
sc_bool is_complex_event_subscription;
//! flag for activation regulation
int counter_of_activated_events;
//! value of max activated events to activate complex event
int max_value_of_activated_events;
// counter of functions sc_event_emit and _sc_event_emission_pool_worker execution
int execution_counter;
//! condition for increasing the counter
sc_condition cond_increase;
//! condition for decreasing the counter
sc_condition cond_decrease;

//! Events list
sc_list* events_list;

};


/*! Notify about sc-element deletion.
* @param addr sc-address of deleted sc-element
* @remarks This function call deletion callback function for event.
Expand Down
79 changes: 61 additions & 18 deletions sc-memory/sc-core/src/sc-store/sc-event/sc_event_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include "sc-core/sc_memory.h"

#include "sc-core/sc-base/sc_allocator.h"
#include "sc-store/sc-container/sc_struct_node.h"
#include "sc-core/sc_event_subscription.h"


/*! Structure representing elementary sc-event.
* @note This structure holds information required for processing events in a worker thread.
Expand Down Expand Up @@ -94,7 +97,34 @@ void _sc_event_emission_pool_worker(sc_pointer data, sc_pointer user_data)
event_subscription, event->user_addr, event->connector_addr, event->connector_type, event->other_addr);

sc_storage_end_new_process();


sc_monitor_acquire_write(&event_subscription->monitor);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review the locking protocol: the code acquires a write lock then later releases it and also calls release_read on the same monitor. Confirm that the read/write lock upgrade/downgrade is correctly handled.


if (!sc_event_subscription_is_complex(event_subscription) &&
event_subscription->events_list != null_ptr)
{
if (--event_subscription->execution_counter == 0)
{
sc_struct_node *list_node = event_subscription->events_list->begin;

while (list_node != null_ptr && list_node != event_subscription->events_list->end)
{
sc_event_subscription *complex_event_subscription =
(sc_event_subscription *)list_node->data;

if (complex_event_subscription != null_ptr)
{
sc_monitor_acquire_write(&complex_event_subscription->monitor);
sc_cond_broadcast(&complex_event_subscription->cond_decrease);
sc_monitor_release_write(&complex_event_subscription->monitor);
}

list_node = list_node->next;
}
}
}
sc_monitor_release_write(&event_subscription->monitor);
sc_monitor_release_read(&event_subscription->monitor);

end:
Expand Down Expand Up @@ -189,22 +219,35 @@ void sc_event_emission_manager_shutdown(sc_event_emission_manager * manager)
}

void _sc_event_emission_manager_add(
sc_event_emission_manager * manager,
sc_event_subscription * event_subscription,
sc_addr user_addr,
sc_addr connector_addr,
sc_type connector_type,
sc_addr other_addr,
sc_event_do_after_callback callback,
sc_addr event_addr)
sc_event_emission_manager * manager,
sc_event_subscription * event_subscription,
sc_addr user_addr,
sc_addr connector_addr,
sc_type connector_type,
sc_addr other_addr,
sc_event_do_after_callback callback,
sc_addr event_addr,
sc_memory_context const * ctx, // добавил параметр в эту функцию
sc_event_type event_type_addr) // добавил параметр в эту функцию
{
if (manager == null_ptr)
return;

sc_event * event =
_sc_event_new(event_subscription, user_addr, connector_addr, connector_type, other_addr, callback, event_addr);

sc_monitor_acquire_write(&manager->pool_monitor);
g_thread_pool_push(manager->thread_pool, event, null_ptr);
sc_monitor_release_write(&manager->pool_monitor);
}
if (manager == null_ptr)
return;

sc_event * event =
_sc_event_new(event_subscription, user_addr, connector_addr, connector_type, other_addr, callback, event_addr);

sc_monitor_acquire_write(&manager->pool_monitor);
g_thread_pool_push(manager->thread_pool, event, null_ptr);
sc_monitor_release_write(&manager->pool_monitor);
if (event_subscription->is_complex_event_subscription){
start_check_condition_to_activate_complex_event(event_subscription,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coupling introduced by calling start_check_condition_to_activate_complex_event from within the event manager seems tight. Consider refactoring to separate concerns or clarify dependency.

ctx, // добавленный параметр
event_subscription->subscription_addr,
event_type_addr, // добавленный параметр. Наверное плохо, что такая зависисмость, это надо пересмотреть
connector_addr,
connector_type,
other_addr,
callback,
event_addr);
}
}
8 changes: 5 additions & 3 deletions sc-memory/sc-core/src/sc-store/sc-event/sc_event_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "sc-core/sc-base/sc_mutex.h"
#include "sc-core/sc-base/sc_monitor.h"

#include "sc-store/sc-container/sc_hash_table.h"
#include "sc-store/sc-base/sc_monitor_private.h"
#include "sc_hash_table.h"
#include "sc-core/sc-base/sc_monitor_private.h"

typedef sc_result (*sc_event_do_after_callback)(sc_memory_context const * ctx, sc_addr addr);

Expand Down Expand Up @@ -73,6 +73,8 @@ void _sc_event_emission_manager_add(
sc_type connector_type,
sc_addr other_addr,
sc_event_do_after_callback callback,
sc_addr event_addr);
sc_addr event_addr,
sc_memory_context const * ctx, // добавил параметр в эту функцию
sc_event_type event_type_addr);

#endif
Loading