Changeset 3cf862f in mainline


Ignore:
Timestamp:
2012-08-17T10:41:54Z (12 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f5da671
Parents:
bf9ac4e8
Message:

Add basic locking to logger

Location:
uspace/srv/logger
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/logger/ctl.c

    rbf9ac4e8 r3cf862f  
    5151        }
    5252
    53         logger_log_t *log = find_log_by_name(full_name);
     53        logger_log_t *log = find_log_by_name_and_acquire(full_name);
    5454        free(full_name);
    5555        if (log == NULL)
     
    5757
    5858        log->logged_level = new_level;
     59
     60        log_release(log);
    5961
    6062        return EOK;
  • uspace/srv/logger/initlvl.c

    rbf9ac4e8 r3cf862f  
    6161                return;
    6262
    63         logger_log_t *log = find_or_create_log(key, 0);
     63        logger_log_t *log = find_or_create_log_and_acquire(key, 0);
    6464        if (log == NULL)
    6565                return;
    6666
    6767        log->logged_level = level;
     68
     69        log_release(log);
    6870}
    6971
  • uspace/srv/logger/logger.h

    rbf9ac4e8 r3cf862f  
    5757        link_t link;
    5858
     59        fibril_mutex_t guard;
     60
    5961        char *name;
    6062        char *full_name;
     
    6466};
    6567
    66 logger_log_t *find_log_by_name(const char *name);
    67 logger_log_t *find_or_create_log(const char *name, sysarg_t parent);
    68 logger_log_t *find_log_by_id(sysarg_t);
     68logger_log_t *find_log_by_name_and_acquire(const char *name);
     69logger_log_t *find_or_create_log_and_acquire(const char *name, sysarg_t parent);
     70logger_log_t *find_log_by_id_and_acquire(sysarg_t);
    6971bool shall_log_message(logger_log_t *, log_level_t);
     72void log_release(logger_log_t *);
    7073
    7174log_level_t get_default_logging_level(void);
  • uspace/srv/logger/logs.c

    rbf9ac4e8 r3cf862f  
    6262}
    6363
    64 logger_log_t *find_or_create_log(const char *name, sysarg_t parent_id)
     64logger_log_t *find_or_create_log_and_acquire(const char *name, sysarg_t parent_id)
    6565{
    6666        logger_log_t *result = NULL;
     
    8888        }
    8989        result->parent = parent;
     90        fibril_mutex_initialize(&result->guard);
    9091
    9192        link_initialize(&result->link);
    9293
     94        fibril_mutex_lock(&result->guard);
     95
    9396        list_append(&result->link, &log_list);
    94 
    9597leave:
    9698        fibril_mutex_unlock(&log_list_guard);
     
    99101}
    100102
    101 logger_log_t *find_log_by_name(const char *name)
     103logger_log_t *find_log_by_name_and_acquire(const char *name)
    102104{
    103105        logger_log_t *result = NULL;
     
    107109                logger_log_t *log = list_get_instance(it, logger_log_t, link);
    108110                if (str_cmp(log->full_name, name) == 0) {
     111                        fibril_mutex_lock(&log->guard);
    109112                        result = log;
    110113                        break;
     
    116119}
    117120
    118 logger_log_t *find_log_by_id(sysarg_t id)
     121logger_log_t *find_log_by_id_and_acquire(sysarg_t id)
    119122{
    120123        logger_log_t *result = NULL;
     
    124127                logger_log_t *log = list_get_instance(it, logger_log_t, link);
    125128                if ((sysarg_t) log == id) {
     129                        fibril_mutex_lock(&log->guard);
    126130                        result = log;
    127131                        break;
     
    147151bool shall_log_message(logger_log_t *log, log_level_t level)
    148152{
    149         return level <= get_actual_log_level(log);
     153        fibril_mutex_lock(&log_list_guard);
     154        bool result = level <= get_actual_log_level(log);
     155        fibril_mutex_unlock(&log_list_guard);
     156        return result;
     157}
     158
     159void log_release(logger_log_t *log)
     160{
     161        assert(fibril_mutex_is_locked(&log->guard));
     162        fibril_mutex_unlock(&log->guard);
    150163}
    151164
  • uspace/srv/logger/writer.c

    rbf9ac4e8 r3cf862f  
    5656                return NULL;
    5757
    58         logger_log_t *log = find_or_create_log(name, parent);
     58        logger_log_t *log = find_or_create_log_and_acquire(name, parent);
    5959
    6060        free(name);
     
    6565static int handle_receive_message(sysarg_t log_id, sysarg_t level)
    6666{
    67         logger_log_t *log = find_log_by_id(log_id);
     67        logger_log_t *log = find_log_by_id_and_acquire(log_id);
    6868        if (log == NULL)
    6969                return ENOENT;
    7070
    71         void *message;
     71        void *message = NULL;
    7272        int rc = async_data_write_accept(&message, true, 1, 0, 0, NULL);
    7373        if (rc != EOK)
    74                 return rc;
     74                goto leave;
    7575
    7676        if (!shall_log_message(log, level)) {
    77                 free(message);
    78                 return EOK;
     77                rc = EOK;
     78                goto leave;
    7979        }
    8080
     
    8383            (const char *) message);
    8484
     85        rc = EOK;
     86
     87leave:
     88        log_release(log);
    8589        free(message);
    8690
    87         return EOK;
     91        return rc;
    8892}
    8993
     
    109113                                break;
    110114                        }
     115                        log_release(log);
    111116                        async_answer_1(callid, EOK, (sysarg_t) log);
    112117                        break;
Note: See TracChangeset for help on using the changeset viewer.