Changeset ae2c925 in mainline
- Timestamp:
- 2012-08-17T11:47:03Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 52c4264
- Parents:
- 90dc458
- Location:
- uspace/srv/logger
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/logger/initlvl.c
r90dc458 rae2c925 62 62 return; 63 63 64 logger_log_t *log; 65 rc = find_or_create_log_and_acquire(key, 0, &log); 66 if (rc != EOK) 64 logger_log_t *log = find_or_create_log_and_acquire(key, 0); 65 if (log == NULL) 67 66 return; 68 67 -
uspace/srv/logger/logger.h
r90dc458 rae2c925 69 69 70 70 logger_log_t *find_log_by_name_and_acquire(const char *name); 71 int find_or_create_log_and_acquire(const char *, sysarg_t, logger_log_t **);71 logger_log_t *find_or_create_log_and_acquire(const char *, sysarg_t); 72 72 logger_log_t *find_log_by_id_and_acquire(sysarg_t); 73 73 bool shall_log_message(logger_log_t *, log_level_t); -
uspace/srv/logger/logs.c
r90dc458 rae2c925 42 42 43 43 44 static logger_log_t *find_log_by_name_and_parent_no_list_lock _and_acquire(const char *name, logger_log_t *parent)44 static logger_log_t *find_log_by_name_and_parent_no_list_lock(const char *name, logger_log_t *parent) 45 45 { 46 46 list_foreach(log_list, it) { 47 47 logger_log_t *log = list_get_instance(it, logger_log_t, link); 48 if ((parent == log->parent) && (str_cmp(log->name, name) == 0)) { 49 fibril_mutex_lock(&log->guard); 48 if ((parent == log->parent) && (str_cmp(log->name, name) == 0)) 50 49 return log; 51 }52 50 } 53 51 … … 71 69 } 72 70 73 int find_or_create_log_and_acquire(const char *name, sysarg_t parent_id, logger_log_t **log_out) 74 { 75 int rc; 76 logger_log_t *result = NULL; 77 logger_log_t *parent = (logger_log_t *) parent_id; 78 79 fibril_mutex_lock(&log_list_guard); 80 81 result = find_log_by_name_and_parent_no_list_lock_and_acquire(name, parent); 82 if (result != NULL) { 83 rc = EOK; 84 goto leave; 85 } 86 87 result = calloc(1, sizeof(logger_log_t)); 88 if (result == NULL) { 89 rc = ENOMEM; 90 goto leave; 91 } 92 93 result->logged_level = LOG_LEVEL_USE_DEFAULT; 71 static logger_log_t *create_log_no_locking(const char *name, logger_log_t *parent) 72 { 73 logger_log_t *result = calloc(1, sizeof(logger_log_t)); 74 if (result == NULL) 75 return NULL; 76 94 77 result->name = str_dup(name); 78 if (result->name == NULL) 79 goto error; 80 81 /* 82 * Notice that we create new dest as the last 83 * operation that can fail and thus there is no code 84 * to deallocate dest. 85 */ 95 86 if (parent == NULL) { 96 87 result->full_name = str_dup(name); 97 rc = create_dest(name, &result->dest); 88 if (result->full_name == NULL) 89 goto error; 90 int rc = create_dest(name, &result->dest); 98 91 if (rc != EOK) 99 goto error _result_allocated;92 goto error; 100 93 } else { 101 rc = asprintf(&result->full_name, "%s/%s",94 int rc = asprintf(&result->full_name, "%s/%s", 102 95 parent->full_name, name); 103 96 if (rc < 0) 104 goto error _result_allocated;97 goto error; 105 98 result->dest = parent->dest; 106 99 } 100 101 /* Following initializations cannot fail. */ 102 result->logged_level = LOG_LEVEL_USE_DEFAULT; 103 fibril_mutex_initialize(&result->guard); 104 link_initialize(&result->link); 107 105 result->parent = parent; 108 fibril_mutex_initialize(&result->guard); 109 110 link_initialize(&result->link); 111 112 fibril_mutex_lock(&result->guard); 113 114 list_append(&result->link, &log_list); 115 116 117 leave: 118 fibril_mutex_unlock(&log_list_guard); 119 120 if (rc == EOK) { 121 assert(fibril_mutex_is_locked(&result->guard)); 122 *log_out = result; 123 } 124 125 return rc; 126 127 error_result_allocated: 106 107 return result; 108 109 error: 128 110 free(result->name); 129 111 free(result->full_name); 130 112 free(result); 131 132 fibril_mutex_unlock(&log_list_guard); 133 134 return rc; 113 return NULL; 114 115 } 116 117 logger_log_t *find_or_create_log_and_acquire(const char *name, sysarg_t parent_id) 118 { 119 logger_log_t *result = NULL; 120 logger_log_t *parent = (logger_log_t *) parent_id; 121 122 fibril_mutex_lock(&log_list_guard); 123 124 result = find_log_by_name_and_parent_no_list_lock(name, parent); 125 if (result == NULL) { 126 result = create_log_no_locking(name, parent); 127 if (result == NULL) 128 goto leave; 129 } 130 131 fibril_mutex_lock(&result->guard); 132 133 list_append(&result->link, &log_list); 134 135 leave: 136 fibril_mutex_unlock(&log_list_guard); 137 138 return result; 135 139 } 136 140 -
uspace/srv/logger/writer.c
r90dc458 rae2c925 56 56 return NULL; 57 57 58 logger_log_t *log = NULL; 59 rc = find_or_create_log_and_acquire(name, parent, &log); 60 if (rc) 58 logger_log_t *log = find_or_create_log_and_acquire(name, parent); 61 59 62 60 free(name);
Note:
See TracChangeset
for help on using the changeset viewer.