Changeset 2e39656 in mainline
- Timestamp:
- 2012-07-14T17:41:01Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ceafd1b
- Parents:
- ef5be68
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/io/log.c
ref5be68 r2e39656 52 52 #define MESSAGE_BUFFER_SIZE 4096 53 53 54 FIBRIL_RWLOCK_INITIALIZE(current_observed_level_lock); 55 log_level_t current_observed_level; 56 54 57 static int logger_register(async_sess_t *session, const char *prog_name) 55 58 { … … 101 104 } 102 105 106 static void cannot_use_level_changed_monitor(void) 107 { 108 assert(false && "not implemented yet"); 109 } 110 111 static 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(¤t_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(¤t_observed_level_lock); 147 } 148 149 async_exchange_end(exchange); 150 151 return EOK; 152 } 153 154 static log_level_t get_current_observed_level(void) 155 { 156 fibril_rwlock_read_lock(¤t_observed_level_lock); 157 log_level_t level = current_observed_level; 158 fibril_rwlock_read_unlock(¤t_observed_level_lock); 159 return level; 160 } 161 103 162 /** Initialize the logging system. 104 163 * … … 120 179 121 180 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 } 122 190 123 191 return rc; … … 151 219 assert(level < LVL_LIMIT); 152 220 221 if (get_current_observed_level() < level) { 222 return; 223 } 224 153 225 char *message_buffer = malloc(MESSAGE_BUFFER_SIZE); 154 226 if (message_buffer == NULL) { -
uspace/lib/c/include/ipc/logger.h
ref5be68 r2e39656 38 38 typedef enum { 39 39 LOGGER_REGISTER = IPC_FIRST_USER_METHOD, 40 LOGGER_MESSAGE 40 LOGGER_MESSAGE, 41 LOGGER_BLOCK_UNTIL_READER_CHANGED 41 42 } logger_sink_request_t; 42 43 -
uspace/srv/logger/logger.h
ref5be68 r2e39656 66 66 void namespace_writer_detach(logging_namespace_t *); 67 67 68 void namespace_wait_for_reader_change(logging_namespace_t *, bool *); 68 69 bool namespace_has_reader(logging_namespace_t *); 69 70 void namespace_add_message(logging_namespace_t *, const char *, log_level_t); -
uspace/srv/logger/namespace.c
ref5be68 r2e39656 43 43 fibril_mutex_t guard; 44 44 size_t writers_count; 45 fibril_condvar_t reader_appeared_cv; 45 46 bool has_reader; 46 47 const char *name; … … 167 168 fibril_mutex_lock(&namespace->guard); 168 169 namespace->has_reader = true; 170 fibril_condvar_broadcast(&namespace->reader_appeared_cv); 169 171 fibril_mutex_unlock(&namespace->guard); 170 172 } … … 200 202 fibril_mutex_lock(&namespace->guard); 201 203 namespace->has_reader = false; 204 fibril_condvar_broadcast(&namespace->reader_appeared_cv); 202 205 fibril_mutex_unlock(&namespace->guard); 203 206 … … 221 224 fibril_mutex_unlock(&namespace->guard); 222 225 return has_reader; 226 } 227 228 void 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); 223 237 } 224 238
Note:
See TracChangeset
for help on using the changeset viewer.