Changeset 2e39656 in mainline


Ignore:
Timestamp:
2012-07-14T17:41:01Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ceafd1b
Parents:
ef5be68
Message:

Check for log readers in separate fibril

Do not even try to send when no reader was announced.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/io/log.c

    ref5be68 r2e39656  
    5252#define MESSAGE_BUFFER_SIZE 4096
    5353
     54FIBRIL_RWLOCK_INITIALIZE(current_observed_level_lock);
     55log_level_t current_observed_level;
     56
    5457static int logger_register(async_sess_t *session, const char *prog_name)
    5558{
     
    101104}
    102105
     106static void cannot_use_level_changed_monitor(void)
     107{
     108        assert(false && "not implemented yet");
     109}
     110
     111static int observed_level_changed_monitor(void *arg)
     112{
     113        async_sess_t *monitor_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_SINK, 0);
     114        if (monitor_session == NULL) {
     115                cannot_use_level_changed_monitor();
     116                return ENOMEM;
     117        }
     118
     119        int rc = logger_register(monitor_session, log_prog_name);
     120        if (rc != EOK) {
     121                cannot_use_level_changed_monitor();
     122                return rc;
     123        }
     124
     125        async_exch_t *exchange = async_exchange_begin(monitor_session);
     126        if (exchange == NULL) {
     127                cannot_use_level_changed_monitor();
     128                return ENOMEM;
     129        }
     130
     131        while (true) {
     132                sysarg_t has_reader;
     133                sysarg_t msg_rc = async_req_0_1(exchange,
     134                    LOGGER_BLOCK_UNTIL_READER_CHANGED, &has_reader);
     135                if (msg_rc != EOK) {
     136                        cannot_use_level_changed_monitor();
     137                        break;
     138                }
     139
     140                fibril_rwlock_write_lock(&current_observed_level_lock);
     141                if ((bool) has_reader) {
     142                        current_observed_level = LVL_LIMIT;
     143                } else {
     144                        current_observed_level = LVL_NOTE;
     145                }
     146                fibril_rwlock_write_unlock(&current_observed_level_lock);
     147        }
     148
     149        async_exchange_end(exchange);
     150
     151        return EOK;
     152}
     153
     154static log_level_t get_current_observed_level(void)
     155{
     156        fibril_rwlock_read_lock(&current_observed_level_lock);
     157        log_level_t level = current_observed_level;
     158        fibril_rwlock_read_unlock(&current_observed_level_lock);
     159        return level;
     160}
     161
    103162/** Initialize the logging system.
    104163 *
     
    120179
    121180        int rc = logger_register(logger_session, log_prog_name);
     181
     182        current_observed_level = LVL_NOTE;
     183
     184        fid_t observed_level_changed_fibril = fibril_create(observed_level_changed_monitor, NULL);
     185        if (observed_level_changed_fibril == 0) {
     186                cannot_use_level_changed_monitor();
     187        } else {
     188                fibril_add_ready(observed_level_changed_fibril);
     189        }
    122190
    123191        return rc;
     
    151219        assert(level < LVL_LIMIT);
    152220
     221        if (get_current_observed_level() < level) {
     222                return;
     223        }
     224
    153225        char *message_buffer = malloc(MESSAGE_BUFFER_SIZE);
    154226        if (message_buffer == NULL) {
  • uspace/lib/c/include/ipc/logger.h

    ref5be68 r2e39656  
    3838typedef enum {
    3939        LOGGER_REGISTER = IPC_FIRST_USER_METHOD,
    40         LOGGER_MESSAGE
     40        LOGGER_MESSAGE,
     41        LOGGER_BLOCK_UNTIL_READER_CHANGED
    4142} logger_sink_request_t;
    4243
  • uspace/srv/logger/logger.h

    ref5be68 r2e39656  
    6666void namespace_writer_detach(logging_namespace_t *);
    6767
     68void namespace_wait_for_reader_change(logging_namespace_t *, bool *);
    6869bool namespace_has_reader(logging_namespace_t *);
    6970void namespace_add_message(logging_namespace_t *, const char *, log_level_t);
  • uspace/srv/logger/namespace.c

    ref5be68 r2e39656  
    4343        fibril_mutex_t guard;
    4444        size_t writers_count;
     45        fibril_condvar_t reader_appeared_cv;
    4546        bool has_reader;
    4647        const char *name;
     
    167168                fibril_mutex_lock(&namespace->guard);
    168169                namespace->has_reader = true;
     170                fibril_condvar_broadcast(&namespace->reader_appeared_cv);
    169171                fibril_mutex_unlock(&namespace->guard);
    170172        }
     
    200202        fibril_mutex_lock(&namespace->guard);
    201203        namespace->has_reader = false;
     204        fibril_condvar_broadcast(&namespace->reader_appeared_cv);
    202205        fibril_mutex_unlock(&namespace->guard);
    203206
     
    221224        fibril_mutex_unlock(&namespace->guard);
    222225        return has_reader;
     226}
     227
     228void namespace_wait_for_reader_change(logging_namespace_t *namespace, bool *has_reader_now)
     229{
     230        fibril_mutex_lock(&namespace->guard);
     231        bool had_reader = namespace->has_reader;
     232        while (had_reader == namespace->has_reader) {
     233                fibril_condvar_wait(&namespace->reader_appeared_cv, &namespace->guard);
     234        }
     235        *has_reader_now = namespace->has_reader;
     236        fibril_mutex_unlock(&namespace->guard);
    223237}
    224238
Note: See TracChangeset for help on using the changeset viewer.