Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset ebbc8a74 in mainline


Ignore:
Timestamp:
2012-08-16T15:44:27Z (9 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
d6ddeb7
Parents:
dc5aa568
Message:

Remove premature optimizations

Location:
uspace
Files:
5 edited

Legend:

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

    rdc5aa568 rebbc8a74  
    6262#define MESSAGE_BUFFER_SIZE 4096
    6363
    64 FIBRIL_RWLOCK_INITIALIZE(current_observed_level_lock);
    65 log_level_t current_observed_level;
    66 
    6764static int logger_register(async_sess_t *session, const char *prog_name)
    6865{
     
    113110
    114111        return reg_msg_rc;
    115 }
    116 
    117 static void cannot_use_level_changed_monitor(void)
    118 {
    119         fibril_rwlock_write_lock(&current_observed_level_lock);
    120         current_observed_level = LVL_LIMIT;
    121         fibril_rwlock_write_unlock(&current_observed_level_lock);
    122 }
    123 
    124 static int observed_level_changed_monitor(void *arg)
    125 {
    126         async_sess_t *monitor_session = service_connect_blocking(EXCHANGE_SERIALIZE, SERVICE_LOGGER, LOGGER_INTERFACE_SINK, 0);
    127         if (monitor_session == NULL) {
    128                 cannot_use_level_changed_monitor();
    129                 return ENOMEM;
    130         }
    131 
    132         int rc = logger_register(monitor_session, log_prog_name);
    133         if (rc != EOK) {
    134                 cannot_use_level_changed_monitor();
    135                 return rc;
    136         }
    137 
    138         async_exch_t *exchange = async_exchange_begin(monitor_session);
    139         if (exchange == NULL) {
    140                 cannot_use_level_changed_monitor();
    141                 return ENOMEM;
    142         }
    143 
    144         while (true) {
    145                 sysarg_t has_reader;
    146                 sysarg_t msg_rc = async_req_0_1(exchange,
    147                     LOGGER_BLOCK_UNTIL_READER_CHANGED, &has_reader);
    148                 if (msg_rc != EOK) {
    149                         cannot_use_level_changed_monitor();
    150                         break;
    151                 }
    152 
    153                 fibril_rwlock_write_lock(&current_observed_level_lock);
    154                 if ((bool) has_reader) {
    155                         current_observed_level = LVL_LIMIT;
    156                 } else {
    157                         current_observed_level = LVL_NOTE;
    158                 }
    159                 fibril_rwlock_write_unlock(&current_observed_level_lock);
    160         }
    161 
    162         async_exchange_end(exchange);
    163 
    164         return EOK;
    165 }
    166 
    167 static log_level_t get_current_observed_level(void)
    168 {
    169         fibril_rwlock_read_lock(&current_observed_level_lock);
    170         log_level_t level = current_observed_level;
    171         fibril_rwlock_read_unlock(&current_observed_level_lock);
    172         return level;
    173112}
    174113
     
    230169        int rc = logger_register(logger_session, log_prog_name);
    231170
    232         current_observed_level = LVL_NOTE;
    233 
    234         fid_t observed_level_changed_fibril = fibril_create(observed_level_changed_monitor, NULL);
    235         if (observed_level_changed_fibril == 0) {
    236                 cannot_use_level_changed_monitor();
    237         } else {
    238                 fibril_add_ready(observed_level_changed_fibril);
    239         }
    240 
    241171        return rc;
    242172}
     
    266196}
    267197
    268 bool _log_shall_record(log_context_t context, log_level_t level)
    269 {
    270         return get_current_observed_level() >= level;
    271 }
    272 
    273198/** Write an entry to the log.
    274199 *
     
    278203 * @param fmt           Format string (no traling newline).
    279204 */
    280 void _log_ctx_msg(log_context_t ctx, log_level_t level, const char *fmt, ...)
     205void log_ctx_msg(log_context_t ctx, log_level_t level, const char *fmt, ...)
    281206{
    282207        va_list args;
    283208
    284209        va_start(args, fmt);
    285         _log_ctx_msgv(ctx, level, fmt, args);
     210        log_ctx_msgv(ctx, level, fmt, args);
    286211        va_end(args);
    287212}
     
    294219 * @param fmt           Format string (no trailing newline)
    295220 */
    296 void _log_ctx_msgv(log_context_t ctx, log_level_t level, const char *fmt, va_list args)
     221void log_ctx_msgv(log_context_t ctx, log_level_t level, const char *fmt, va_list args)
    297222{
    298223        assert(level < LVL_LIMIT);
    299 
    300         if (get_current_observed_level() < level) {
    301                 return;
    302         }
    303224
    304225        char *message_buffer = malloc(MESSAGE_BUFFER_SIZE);
  • uspace/lib/c/include/io/log.h

    rdc5aa568 rebbc8a74  
    5858extern int log_level_from_str(const char *, log_level_t *);
    5959
    60 extern bool _log_shall_record(log_context_t, log_level_t);
    6160extern int log_init(const char *, log_level_t);
    6261
    6362extern log_context_t log_context_create(const char *);
    64 
    65 #define log_ctx_msg(context, level, format, ...) \
    66         do { \
    67                 if (_log_shall_record((context), (level))) { \
    68                         _log_ctx_msg((context), (level), format, ##__VA_ARGS__); \
    69                 } \
    70         } while (false)
    71 
    72 #define log_ctx_msgv(context, level, format, args) \
    73         do { \
    74                 if (_log_shall_record((context), (level))) { \
    75                         _log_ctx_msgv((context), (level), format, args); \
    76                 } \
    77         } while (false)
    7863
    7964#define log_msg(level, format, ...) \
     
    8267        log_ctx_msgv(LOG_CONTEXT_DEFAULT, (level), (format), (args))
    8368
    84 extern void _log_ctx_msg(log_context_t, log_level_t, const char *, ...);
    85 extern void _log_ctx_msgv(log_context_t, log_level_t, const char *, va_list);
     69extern void log_ctx_msg(log_context_t, log_level_t, const char *, ...);
     70extern void log_ctx_msgv(log_context_t, log_level_t, const char *, va_list);
    8671
    8772#endif
  • uspace/lib/c/include/ipc/logger.h

    rdc5aa568 rebbc8a74  
    4646        LOGGER_REGISTER = IPC_FIRST_USER_METHOD,
    4747        LOGGER_CREATE_CONTEXT,
    48         LOGGER_MESSAGE,
    49         LOGGER_BLOCK_UNTIL_READER_CHANGED
     48        LOGGER_MESSAGE
    5049} logger_sink_request_t;
    5150
  • uspace/srv/logger/logger.h

    rdc5aa568 rebbc8a74  
    5656int namespace_change_level(logging_namespace_t *, log_level_t);
    5757
    58 void namespace_wait_for_reader_change(logging_namespace_t *, bool *);
    5958bool namespace_has_reader(logging_namespace_t *, sysarg_t, log_level_t);
    6059void namespace_add_message(logging_namespace_t *, const char *, sysarg_t, log_level_t);
  • uspace/srv/logger/namespace.c

    rdc5aa568 rebbc8a74  
    5151        fibril_mutex_t guard;
    5252        size_t writers_count;
    53         fibril_condvar_t level_changed_cv;
    5453        FILE *logfile;
    5554        log_level_t level;
     
    135134
    136135        fibril_mutex_initialize(&namespace->guard);
    137         fibril_condvar_initialize(&namespace->level_changed_cv);
    138136        namespace->writers_count = 0;
    139137        link_initialize(&namespace->link);
     
    228226                namespace->context[i].level = level;
    229227        }
    230         fibril_condvar_broadcast(&namespace->level_changed_cv);
    231228        fibril_mutex_unlock(&namespace->guard);
    232229
     
    277274                        namespace->context[i].level = new_level;
    278275                        rc = EOK;
    279                         fibril_condvar_broadcast(&namespace->level_changed_cv);
    280276                        goto leave;
    281277                }
     
    287283        return rc;
    288284}
    289 
    290 void namespace_wait_for_reader_change(logging_namespace_t *namespace, bool *has_reader_now)
    291 {
    292         fibril_mutex_lock(&namespace->guard);
    293         // FIXME: properly watch for state change
    294         fibril_condvar_wait(&namespace->level_changed_cv, &namespace->guard);
    295         *has_reader_now = true;
    296         fibril_mutex_unlock(&namespace->guard);
    297 }
    298 
    299285
    300286void namespace_add_message(logging_namespace_t *namespace, const char *message, sysarg_t context, log_level_t level)
Note: See TracChangeset for help on using the changeset viewer.