Changeset e2a6b72 in mainline for uspace/lib/c/include
- Timestamp:
- 2012-10-15T16:28:58Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b3ab8f7
- Parents:
- 7eb49f4 (diff), c4c2406 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- uspace/lib/c/include
- Files:
-
- 4 added
- 8 edited
- 1 moved
-
adt/hash.h (added)
-
adt/hash_table.h (modified) (2 diffs)
-
adt/list.h (modified) (1 diff)
-
ddi.h (modified) (2 diffs)
-
device/battery_dev.h (added)
-
device/clock_dev.h (added)
-
io/log.h (modified) (2 diffs)
-
io/logctl.h (added)
-
ipc/dev_iface.h (modified) (1 diff)
-
ipc/logger.h (moved) (moved from uspace/lib/c/include/adt/hash_set.h ) (2 diffs)
-
ipc/services.h (modified) (1 diff)
-
macros.h (modified) (1 diff)
-
sys/time.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/include/adt/hash_table.h
r7eb49f4 re2a6b72 1 1 /* 2 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2012 Adam Hraska 4 * 3 5 * All rights reserved. 4 6 * … … 39 41 #include <unistd.h> 40 42 #include <bool.h> 43 #include <macros.h> 41 44 42 typedef unsigned long hash_count_t; 43 typedef unsigned long hash_index_t; 45 /** Opaque hash table link type. */ 46 typedef struct ht_link { 47 link_t link; 48 } ht_link_t; 44 49 45 50 /** Set of operations for hash table. */ 46 51 typedef struct { 47 /** Hash function. 48 * 49 * @param key Array of keys needed to compute hash index. 50 * All keys must be passed. 51 * 52 * @return Index into hash table. 53 * 54 */ 55 hash_index_t (*hash)(unsigned long key[]); 52 /** Returns the hash of the key stored in the item (ie its lookup key). */ 53 size_t (*hash)(const ht_link_t *item); 56 54 57 /** Hash table item comparison function. 58 * 59 * @param key Array of keys that will be compared with item. It is 60 * not necessary to pass all keys. 61 * 62 * @return True if the keys match, false otherwise. 63 * 64 */ 65 int (*compare)(unsigned long key[], hash_count_t keys, link_t *item); 55 /** Returns the hash of the key. */ 56 size_t (*key_hash)(void *key); 66 57 58 /** True if the items are equal (have the same lookup keys). */ 59 bool (*equal)(const ht_link_t *item1, const ht_link_t *item2); 60 61 /** Returns true if the key is equal to the item's lookup key. */ 62 bool (*key_equal)(void *key, const ht_link_t *item); 63 67 64 /** Hash table item removal callback. 65 * 66 * Must not invoke any mutating functions of the hash table. 68 67 * 69 68 * @param item Item that was removed from the hash table. 70 *71 69 */ 72 void (*remove_callback)( link_t *item);73 } hash_table_op erations_t;70 void (*remove_callback)(ht_link_t *item); 71 } hash_table_ops_t; 74 72 75 73 /** Hash table structure. */ 76 74 typedef struct { 77 list_t *entry; 78 hash_count_t entries; 79 hash_count_t max_keys; 80 hash_table_operations_t *op; 75 hash_table_ops_t *op; 76 list_t *bucket; 77 size_t bucket_cnt; 78 size_t full_item_cnt; 79 size_t item_cnt; 80 size_t max_load; 81 bool apply_ongoing; 81 82 } hash_table_t; 82 83 83 #define hash_table_get_inst ance(item, type, member) \84 list_get_instance((item), type, member)84 #define hash_table_get_inst(item, type, member) \ 85 member_to_inst((item), type, member) 85 86 86 extern bool hash_table_create(hash_table_t *, hash_count_t, hash_count_t, 87 hash_table_operations_t *); 87 extern bool hash_table_create(hash_table_t *, size_t, size_t, 88 hash_table_ops_t *); 89 extern void hash_table_destroy(hash_table_t *); 90 91 extern bool hash_table_empty(hash_table_t *); 92 extern size_t hash_table_size(hash_table_t *); 93 88 94 extern void hash_table_clear(hash_table_t *); 89 extern void hash_table_insert(hash_table_t *, unsigned long [], link_t *); 90 extern link_t *hash_table_find(hash_table_t *, unsigned long []); 91 extern void hash_table_remove(hash_table_t *, unsigned long [], hash_count_t); 92 extern void hash_table_destroy(hash_table_t *); 93 extern void hash_table_apply(hash_table_t *, void (*)(link_t *, void *), 94 void *); 95 extern void hash_table_insert(hash_table_t *, ht_link_t *); 96 extern bool hash_table_insert_unique(hash_table_t *, ht_link_t *); 97 extern ht_link_t *hash_table_find(const hash_table_t *, void *); 98 extern ht_link_t *hash_table_find_next(const hash_table_t *, ht_link_t *); 99 extern size_t hash_table_remove(hash_table_t *, void *); 100 extern void hash_table_remove_item(hash_table_t *, ht_link_t *); 101 extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *), 102 void *); 103 95 104 96 105 #endif -
uspace/lib/c/include/adt/list.h
r7eb49f4 re2a6b72 71 71 iterator != &(list).head; iterator = iterator->next) 72 72 73 /** Unlike list_foreach(), allows removing items while traversing a list. 74 * 75 * @code 76 * list_t mylist; 77 * typedef struct item { 78 * int value; 79 * link_t item_link; 80 * } item_t; 81 * 82 * //.. 83 * 84 * // Print each list element's value and remove the element from the list. 85 * list_foreach_safe(mylist, cur_link, next_link) { 86 * item_t *cur_item = list_get_instance(cur_link, item_t, item_link); 87 * printf("%d\n", cur_item->value); 88 * list_remove(cur_link); 89 * } 90 * @endcode 91 * 92 * @param list List to traverse. 93 * @param iterator Iterator to the current element of the list. 94 * The item this iterator points may be safely removed 95 * from the list. 96 * @param next_iter Iterator to the next element of the list. 97 */ 98 #define list_foreach_safe(list, iterator, next_iter) \ 99 for (link_t *iterator = (list).head.next, \ 100 *next_iter = iterator->next; \ 101 iterator != &(list).head; \ 102 iterator = next_iter, next_iter = iterator->next) 103 73 104 #define assert_link_not_used(link) \ 74 105 assert(((link)->prev == NULL) && ((link)->next == NULL)) 106 107 /** Returns true if the link is definitely part of a list. False if not sure. */ 108 static inline int link_in_use(link_t *link) 109 { 110 return link->prev != NULL && link->next != NULL; 111 } 75 112 76 113 /** Initialize doubly-linked circular list link -
uspace/lib/c/include/ddi.h
r7eb49f4 re2a6b72 36 36 #define LIBC_DDI_H_ 37 37 38 #include <bool.h> 38 39 #include <sys/types.h> 40 #include <sys/time.h> 39 41 #include <abi/ddi/irq.h> 40 42 #include <task.h> … … 50 52 extern int dmamem_unmap_anonymous(void *); 51 53 52 extern int iospace_enable(task_id_t, void *, unsigned long);53 54 extern int pio_enable(void *, size_t, void **); 55 56 typedef void (*trace_fnc)(volatile void *place, uint32_t val, 57 volatile void* base, size_t size, void *data, bool write); 58 59 extern int pio_trace_enable(void *, size_t, trace_fnc, void *); 60 extern void pio_trace_log(volatile void *, uint32_t val, bool write); 61 extern void pio_trace_disable(void *); 62 63 extern void pio_write_8(ioport8_t *, uint8_t); 64 extern void pio_write_16(ioport16_t *, uint16_t); 65 extern void pio_write_32(ioport32_t *, uint32_t); 66 67 extern uint8_t pio_read_8(ioport8_t *); 68 extern uint16_t pio_read_16(ioport16_t *); 69 extern uint32_t pio_read_32(ioport32_t *); 70 71 static inline uint8_t pio_change_8( 72 ioport8_t *reg, uint8_t val, uint8_t mask, useconds_t delay) 73 { 74 uint8_t v = pio_read_8(reg); 75 udelay(delay); 76 pio_write_8(reg, (v & ~mask) | val); 77 return v; 78 } 79 80 static inline uint16_t pio_change_16( 81 ioport16_t *reg, uint16_t val, uint16_t mask, useconds_t delay) 82 { 83 uint16_t v = pio_read_16(reg); 84 udelay(delay); 85 pio_write_16(reg, (v & ~mask) | val); 86 return v; 87 } 88 89 static inline uint32_t pio_change_32( 90 ioport32_t *reg, uint32_t val, uint32_t mask, useconds_t delay) 91 { 92 uint32_t v = pio_read_32(reg); 93 udelay(delay); 94 pio_write_32(reg, (v & ~mask) | val); 95 return v; 96 } 97 98 static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, useconds_t d) 99 { 100 return pio_change_8(r, v, 0, d); 101 } 102 static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, useconds_t d) 103 { 104 return pio_change_16(r, v, 0, d); 105 } 106 static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, useconds_t d) 107 { 108 return pio_change_32(r, v, 0, d); 109 } 110 111 static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, useconds_t d) 112 { 113 return pio_change_8(r, 0, v, d); 114 } 115 static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, useconds_t d) 116 { 117 return pio_change_16(r, 0, v, d); 118 } 119 static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, useconds_t d) 120 { 121 return pio_change_32(r, 0, v, d); 122 } 54 123 55 124 extern int irq_register(int, int, int, irq_code_t *); -
uspace/lib/c/include/io/log.h
r7eb49f4 re2a6b72 36 36 37 37 #include <stdarg.h> 38 #include <inttypes.h> 38 39 #include <io/verify.h> 39 40 41 /** Log message level. */ 40 42 typedef enum { 43 /** Fatal error, program is not able to recover at all. */ 41 44 LVL_FATAL, 45 /** Serious error but the program can recover from it. */ 42 46 LVL_ERROR, 47 /** Easily recoverable problem. */ 43 48 LVL_WARN, 49 /** Information message that ought to be printed by default. */ 44 50 LVL_NOTE, 51 /** Debugging purpose message. */ 45 52 LVL_DEBUG, 53 /** More detailed debugging message. */ 46 54 LVL_DEBUG2, 47 55 … … 50 58 } log_level_t; 51 59 52 extern int log_init(const char *, log_level_t); 53 extern void log_msg(log_level_t, const char *, ...) 54 PRINTF_ATTRIBUTE(2, 3); 55 extern void log_msgv(log_level_t, const char *, va_list); 60 /** Log itself (logging target). */ 61 typedef sysarg_t log_t; 62 /** Formatting directive for printing log_t. */ 63 #define PRIlogctx PRIxn 64 65 /** Default log (target). */ 66 #define LOG_DEFAULT ((log_t) -1) 67 68 /** Use when creating new top-level log. */ 69 #define LOG_NO_PARENT ((log_t) 0) 70 71 extern const char *log_level_str(log_level_t); 72 extern int log_level_from_str(const char *, log_level_t *); 73 74 extern int log_init(const char *); 75 extern log_t log_create(const char *, log_t); 76 77 extern void log_msg(log_t, log_level_t, const char *, ...) 78 PRINTF_ATTRIBUTE(3, 4); 79 extern void log_msgv(log_t, log_level_t, const char *, va_list); 56 80 57 81 #endif -
uspace/lib/c/include/ipc/dev_iface.h
r7eb49f4 re2a6b72 54 54 /** Interface provided by USB HID devices. */ 55 55 USBHID_DEV_IFACE, 56 /** Interface provided by Real Time Clock devices */ 57 CLOCK_DEV_IFACE, 58 /** Interface provided by battery powered devices */ 59 BATTERY_DEV_IFACE, 56 60 /** Interface provided by AHCI devices. */ 57 61 AHCI_DEV_IFACE, -
uspace/lib/c/include/ipc/logger.h
r7eb49f4 re2a6b72 1 1 /* 2 * Copyright (c) 2006 Jakub Jermar 3 * Copyright (c) 2011 Radim Vansa 2 * Copyright (c) 2012 Vojtech Horky 4 3 * All rights reserved. 5 4 * … … 31 30 * @{ 32 31 */ 33 /** @file34 */35 32 36 #ifndef LIBC_ HASH_SET_H_37 #define LIBC_ HASH_SET_H_33 #ifndef LIBC_IPC_LOGGER_H_ 34 #define LIBC_IPC_LOGGER_H_ 38 35 39 #include <adt/list.h> 40 #include <unistd.h> 36 #include <ipc/common.h> 41 37 42 #define HASH_SET_MIN_SIZE 8 38 typedef enum { 39 /** Set (global) default displayed logging level. 40 * 41 * Arguments: new log level. 42 * Returns: error code 43 */ 44 LOGGER_CONTROL_SET_DEFAULT_LEVEL = IPC_FIRST_USER_METHOD, 45 /** Set displayed level for given log. 46 * 47 * Arguments: new log level. 48 * Returns: error code 49 * Followed by: string with full log name. 50 */ 51 LOGGER_CONTROL_SET_LOG_LEVEL 52 } logger_control_request_t; 43 53 44 typedef unsigned long (*hash_set_hash)(const link_t *); 45 typedef int (*hash_set_equals)(const link_t *, const link_t *); 54 typedef enum { 55 /** Create new log. 56 * 57 * Arguments: parent log id (0 for top-level log). 58 * Returns: error code, log id 59 * Followed by: string with log name. 60 */ 61 LOGGER_WRITER_CREATE_LOG = IPC_FIRST_USER_METHOD, 62 /** Write a message to a given log. 63 * 64 * Arguments: log id, message severity level (log_level_t) 65 * Returns: error code 66 * Followed by: string with the message. 67 */ 68 LOGGER_WRITER_MESSAGE 69 } logger_writer_request_t; 46 70 47 /** Hash table structure. */ 48 typedef struct { 49 list_t *table; 50 51 /** Current table size */ 52 size_t size; 53 54 /** 55 * Current number of entries. If count > size, 56 * the table is rehashed into table with double 57 * size. If (4 * count < size) && (size > min_size), 58 * the table is rehashed into table with half the size. 59 */ 60 size_t count; 61 62 /** Hash function */ 63 hash_set_hash hash; 64 65 /** Hash table item equals function */ 66 hash_set_equals equals; 67 } hash_set_t; 68 69 extern int hash_set_init(hash_set_t *, hash_set_hash, hash_set_equals, size_t); 70 extern int hash_set_insert(hash_set_t *, link_t *); 71 extern link_t *hash_set_find(hash_set_t *, const link_t *); 72 extern int hash_set_contains(const hash_set_t *, const link_t *); 73 extern size_t hash_set_count(const hash_set_t *); 74 extern link_t *hash_set_remove(hash_set_t *, const link_t *); 75 extern void hash_set_remove_selected(hash_set_t *, 76 int (*)(link_t *, void *), void *); 77 extern void hash_set_destroy(hash_set_t *); 78 extern void hash_set_apply(hash_set_t *, void (*)(link_t *, void *), void *); 79 extern void hash_set_clear(hash_set_t *, void (*)(link_t *, void *), void *); 71 typedef enum { 72 /** Interface for controlling logger behavior. */ 73 LOGGER_INTERFACE_CONTROL, 74 /** Interface for servers writing to the log. */ 75 LOGGER_INTERFACE_WRITER 76 } logger_interface_t; 80 77 81 78 #endif -
uspace/lib/c/include/ipc/services.h
r7eb49f4 re2a6b72 45 45 SERVICE_VFS = FOURCC('v', 'f', 's', ' '), 46 46 SERVICE_LOC = FOURCC('l', 'o', 'c', ' '), 47 SERVICE_LOGGER = FOURCC('l', 'o', 'g', 'g'), 47 48 SERVICE_DEVMAN = FOURCC('d', 'e', 'v', 'n'), 48 49 SERVICE_IRC = FOURCC('i', 'r', 'c', ' '), -
uspace/lib/c/include/macros.h
r7eb49f4 re2a6b72 52 52 | ((((uint64_t) (up)) & 0xffffffff) << 32)) 53 53 54 #ifndef member_to_inst 55 #define member_to_inst(ptr_member, type, member_identif) \ 56 ((type*) (((void*)(ptr_member)) - ((void*)&(((type*)0)->member_identif)))) 57 #endif 58 59 54 60 #endif 55 61 -
uspace/lib/c/include/sys/time.h
r7eb49f4 re2a6b72 1 1 /* 2 2 * Copyright (c) 2006 Ondrej Palkovsky 3 * Copyright (c) 2011 Petr Koupy 4 * Copyright (c) 2011 Jiri Zarevucky 3 5 * All rights reserved. 4 6 * … … 39 41 40 42 #define DST_NONE 0 43 #define ASCTIME_BUF_LEN 26 41 44 42 45 typedef long time_t; … … 45 48 typedef uint32_t useconds_t; 46 49 typedef uint32_t mseconds_t; 50 51 struct tm { 52 int tm_sec; /* Seconds [0,60]. */ 53 int tm_min; /* Minutes [0,59]. */ 54 int tm_hour; /* Hour [0,23]. */ 55 int tm_mday; /* Day of month [1,31]. */ 56 int tm_mon; /* Month of year [0,11]. */ 57 int tm_year; /* Years since 1900. */ 58 int tm_wday; /* Day of week [0,6] (Sunday = 0). */ 59 int tm_yday; /* Day of year [0,365]. */ 60 int tm_isdst; /* Daylight Savings flag. */ 61 }; 47 62 48 63 struct timeval { … … 61 76 extern int tv_gteq(struct timeval *tv1, struct timeval *tv2); 62 77 extern int gettimeofday(struct timeval *tv, struct timezone *tz); 78 extern int getuptime(struct timeval *tv); 63 79 64 80 extern void udelay(useconds_t); 81 82 extern time_t mktime(struct tm *tm); 83 extern int time_utc2tm(const time_t time, struct tm *result); 84 extern int time_utc2str(const time_t time, char *buf); 85 extern void time_tm2str(const struct tm *timeptr, char *buf); 86 extern int time_local2tm(const time_t time, struct tm *result); 87 extern int time_local2str(const time_t time, char *buf); 88 extern double difftime(time_t time1, time_t time0); 89 extern size_t strftime(char *restrict s, size_t maxsize, 90 const char *restrict format, const struct tm *restrict tm); 65 91 66 92 #endif
Note:
See TracChangeset
for help on using the changeset viewer.
