Added examples to headers.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 17 Jul 2007 08:53:12 +0000 (08:53 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 17 Jul 2007 08:53:12 +0000 (08:53 +0000)
lib/silcutil/silcasync.h
lib/silcutil/silcatomic.h
lib/silcutil/silcbuffmt.h
lib/silcutil/silccond.h
lib/silcutil/silcdlist.h
lib/silcutil/silcdll.h
lib/silcutil/silctimer.h

index 2853e9c3d0f02ab79cb3acea7d88f7ed8a924219..0cc2190ecadd7dd23d7705644628e0b9faa5dd21 100644 (file)
  * operation, no callback function will be called back to the upper layer.
  * This must be remembered when implementing the operation layer.
  *
+ * EXAMPLE
+ *
+ * SilcAsyncOperation async_call(Callback callback, void *cb_context)
+ * {
+ *   SilcAsyncOperation op;
+ *   OpContext ctx;
+ *
+ *   // Allocate async operation so that caller can control us, like abort
+ *   op = silc_async_alloc(async_call_abort, NULL, ctx);
+ *   ctx->callback = callback;
+ *
+ *   ...
+ *
+ *   // Return async operation for upper layer
+ *   return op;
+ * }
+ *
+ * // This callback is called when silc_async_abort is called by upper layer.
+ * // The callback given to async_call must not be called after this.
+ * void async_call_abort(SilcAsyncOperation op, void *context)
+ * {
+ *   OpContext ctx = context;
+ *   ctx->aborted = TRUE;
+ *   ctx->callback = NULL;
+ * }
+ *
  ***/
 
 #ifndef SILCASYNC_H
index 3a49aecf07f039d78de8d1241cd13ed470bbe597..5f3ea2e15520d9111b021abf7d86beccccfa10ac 100644 (file)
  *
  * Fast operations are supported on: x86, x86_64, ia64, PPC
  *
+ * EXAMPLE
+ *
+ * SilcAtomic32 refcnt;
+ *
+ * // Initialize atomic variable
+ * silc_atomic_init32(&refcnt, 0);
+ *
+ * // Increment referene counter by one
+ * silc_atomic_add_int32(&refcnt, 1);
+ *
+ * // Uninitialize atomic variable
+ * silc_atomic_uninit32(&refcnt);
+ *
  ***/
 
 #ifndef SILCATOMIC_H
index cd654de55ee6a36151a5e39d58a435070d12c925..fc213001030a9de89db0b5c6c8a605126fe87f4f 100644 (file)
  * in multithreaded environment with a same SilcBuffer context without
  * concurrency control.
  *
+ * EXAMPLE
+ *
+ * SilcBufferStruct buffer;
+ *
+ * memset(&buffer, 0, sizeof(buffer));
+ * ret = silc_buffer_format(&buffer,
+ *                          SILC_STR_UI_INT(intval),
+ *                          SILC_STR_CHAR(charval),
+ *                          SILC_STR_UI_INT(intval),
+ *                          SILC_STR_SHORT(str_len),
+ *                          SILC_STR_DATA(str, str_len),
+ *                          SILC_STR_END);
+ * if (ret < 0)
+ *   error;
+ *
  ***/
 
 #ifndef SILCBUFFMT_H
index 1fe8bb21001512b34086243c48ed8b89ca64c18b..08110d8145b1cbd24c0c1039ffe0c9f34f49cd6f 100644 (file)
  * Condition variables enable threads to suspend execution and yield
  * the processors until some predicate on some shared data is satisfied.
  *
+ * EXAMPLE
+ *
+ * Thread 1:
+ *
+ * // Wait for signal
+ * silc_mutex_lock(lock);
+ * while (c->a == NULL)
+ *   silc_cond_wait(cond, lock);
+ * ...
+ * silc_mutex_unlock(lock);
+ *
+ * Thread 2:
+ *
+ * // Signal
+ * silc_mutex_lock(lock);
+ * c->a = context;
+ * silc_cond_signal(cond);
+ * silc_mutex_unlock(lock);
+ *
  ***/
 
 #ifndef SILCCOND_H
index 238c008e60fd126c7c660ecf88e985e219dba6f0..9c951e49e6cb89be237f4d7f1e2160efb2716099 100644 (file)
  * SILC Dynamic List is not thread-safe.  If the same list context must be
  * used in multithreaded environment concurrency control must be employed.
  *
+ * EXAMPLE
+ *
+ * SilcDList list = silc_dlist_init();
+ *
+ * silc_dlist_add(list, entry1);
+ * silc_dlist_add(list, entry2);
+ *
+ * // Traverse the list from the beginning to the end
+ * silc_dlist_start(list)
+ * while ((entry = silc_dlist_get(list)) != SILC_LIST_END) {
+ *      ...
+ * }
+ *
+ * silc_dlist_uninit(list);
+ *
  ***/
 
 /****s* silcutil/SilcDListAPI/SilcDList
index 3da325b4d96e4c5b09f5c6f74ee6a25c53a48965..d0d2adf873eec489e73a65b7fc8404f2ce114512 100644 (file)
  * Platform independent iterface for loading and using shared objects and
  * dynamically linked libraries (DLLs).
  *
+ * EXAMPLE
+ *
+ * SilcDll dll;
+ * SilcFuncCb function;
+ *
+ * dll = silc_dll_load("/path/to/my.so");
+ * function = silc_dll_getsym(dll, "my_function");
+ *
+ * // Call the funtion
+ * function(arg1, arg2);
+ *
+ * silc_dll_close(dll);
+ *
  ***/
 
 #ifndef SILCDLL_H
index 79c57750da8c013294f89dd76d95291f429adc26..c53da041908c962b8311fcb302798e83c51eed02 100644 (file)
 */
 
 /****h* silcutil/SILC Timer Interface
+ *
+ * DESCRIPTION
  *
  * SILC Timer interface provides a simple way to measure time intervals.
  * The SILC Timer works with microsecond resolution, depending on platform.
  *
+ * EXAMPLE
+ *
+ * SilcTimerStruct timer;
+ *
+ * silc_timer_start(&timer);
+ * ... time passes ...
+ * silc_timer_stop(&timer);
+ * silc_timer_value(&timer, &elapsed_sec, &elapsed_usec);
+ *
  ***/
 
 #ifndef SILCTIMER_H