hexsha
stringlengths 40
40
| repo
stringlengths 5
105
| path
stringlengths 3
173
| license
sequence | language
stringclasses 1
value | identifier
stringlengths 1
438
| return_type
stringlengths 1
106
⌀ | original_string
stringlengths 21
40.7k
| original_docstring
stringlengths 18
13.4k
| docstring
stringlengths 11
3.24k
| docstring_tokens
sequence | code
stringlengths 14
20.4k
| code_tokens
sequence | short_docstring
stringlengths 0
4.36k
| short_docstring_tokens
sequence | comment
sequence | parameters
list | docstring_params
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
5cf18cc577d0ce770db4220c4dad025a827a56d2 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_main.c | [
"Apache-2.0"
] | C | gupcr_init | void | static void
gupcr_init (void)
{
int run_threads_count;
upc_shared_ptr_t heap_region_base;
size_t heap_region_size;
/* Initialize Runtime. */
if (gupcr_runtime_init ())
{
/* Report an error to stderr as the GUPC error reporting
is not initialized yet. Note: all threads report
this error. */
fprintf (stderr, "Unable to initialize runtime.\n");
abort ();
}
/* Get the thread number. */
MYTHREAD = gupcr_runtime_get_rank ();
#if GUPCR_HAVE_OMP_CHECKS
/* Each UPC thread is OMP master thread. */
__upc_omp_master_id = pthread_self ();
#endif
/* Set up debugging, tracing, statistics, and timing support. */
gupcr_utils_init ();
/* Initialize Portals. */
gupcr_portals_init ();
/* Validate program info. */
gupcr_validate_pgm_info ();
run_threads_count = gupcr_get_threads_count ();
/* THREADS == -1, dynamic number of threads
THREADS != -1, static number of threads and
number of running and compiled threads must match. */
if (THREADS == -1)
THREADS = run_threads_count;
else if (THREADS != run_threads_count)
gupcr_abort_with_msg ("number of running threads (%d) is "
"not equal to compiled threads (%d)",
run_threads_count, THREADS);
gupcr_assert (THREADS >= 1);
#if HAVE_UPC_BACKTRACE
/* Initialize backtrace support. */
gupcr_backtrace_init (gupcr_get_pgm_name () );
#endif
/* Initialize the Portals Network Interface. */
gupcr_portals_ni_init ();
/* Initialize this thread's multi-node tree position. */
gupcr_nodetree_setup ();
/* Initialize various runtime components. */
gupcr_node_init ();
gupcr_gmem_init ();
gupcr_lock_init ();
gupcr_barrier_init ();
gupcr_broadcast_init ();
gupcr_coll_init ();
gupcr_atomic_init ();
gupcr_nb_init ();
gupcr_shutdown_init ();
GUPCR_PTS_SET_NULL_SHARED (heap_region_base);
GUPCR_PTS_SET_THREAD (heap_region_base, MYTHREAD);
GUPCR_PTS_SET_VADDR (heap_region_base, gupcr_gmem_heap_base_offset);
heap_region_size = gupcr_gmem_heap_size;
gupcr_alloc_init (heap_region_base, heap_region_size);
/* Indicate that runtime initialization is complete. */
gupcr_init_complete ();
/* It is ok to call the finalization routines. */
gupcr_finalize_ok = 1;
} | /**
* Initialize UPC runtime.
*
* All hardware/software components of the Portals4 interface
* are initialized in this routine.
*/ | Initialize UPC runtime.
All hardware/software components of the Portals4 interface
are initialized in this routine. | [
"Initialize",
"UPC",
"runtime",
".",
"All",
"hardware",
"/",
"software",
"components",
"of",
"the",
"Portals4",
"interface",
"are",
"initialized",
"in",
"this",
"routine",
"."
] | static void
gupcr_init (void)
{
int run_threads_count;
upc_shared_ptr_t heap_region_base;
size_t heap_region_size;
if (gupcr_runtime_init ())
{
fprintf (stderr, "Unable to initialize runtime.\n");
abort ();
}
MYTHREAD = gupcr_runtime_get_rank ();
#if GUPCR_HAVE_OMP_CHECKS
__upc_omp_master_id = pthread_self ();
#endif
gupcr_utils_init ();
gupcr_portals_init ();
gupcr_validate_pgm_info ();
run_threads_count = gupcr_get_threads_count ();
if (THREADS == -1)
THREADS = run_threads_count;
else if (THREADS != run_threads_count)
gupcr_abort_with_msg ("number of running threads (%d) is "
"not equal to compiled threads (%d)",
run_threads_count, THREADS);
gupcr_assert (THREADS >= 1);
#if HAVE_UPC_BACKTRACE
gupcr_backtrace_init (gupcr_get_pgm_name () );
#endif
gupcr_portals_ni_init ();
gupcr_nodetree_setup ();
gupcr_node_init ();
gupcr_gmem_init ();
gupcr_lock_init ();
gupcr_barrier_init ();
gupcr_broadcast_init ();
gupcr_coll_init ();
gupcr_atomic_init ();
gupcr_nb_init ();
gupcr_shutdown_init ();
GUPCR_PTS_SET_NULL_SHARED (heap_region_base);
GUPCR_PTS_SET_THREAD (heap_region_base, MYTHREAD);
GUPCR_PTS_SET_VADDR (heap_region_base, gupcr_gmem_heap_base_offset);
heap_region_size = gupcr_gmem_heap_size;
gupcr_alloc_init (heap_region_base, heap_region_size);
gupcr_init_complete ();
gupcr_finalize_ok = 1;
} | [
"static",
"void",
"gupcr_init",
"(",
"void",
")",
"{",
"int",
"run_threads_count",
";",
"upc_shared_ptr_t",
"heap_region_base",
";",
"size_t",
"heap_region_size",
";",
"if",
"(",
"gupcr_runtime_init",
"(",
")",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\n",
"\"",
")",
";",
"abort",
"(",
")",
";",
"}",
"MYTHREAD",
"=",
"gupcr_runtime_get_rank",
"(",
")",
";",
"#if",
"GUPCR_HAVE_OMP_CHECKS",
"\n",
"__upc_omp_master_id",
"=",
"pthread_self",
"(",
")",
";",
"#endif",
"gupcr_utils_init",
"(",
")",
";",
"gupcr_portals_init",
"(",
")",
";",
"gupcr_validate_pgm_info",
"(",
")",
";",
"run_threads_count",
"=",
"gupcr_get_threads_count",
"(",
")",
";",
"if",
"(",
"THREADS",
"==",
"-1",
")",
"THREADS",
"=",
"run_threads_count",
";",
"else",
"if",
"(",
"THREADS",
"!=",
"run_threads_count",
")",
"gupcr_abort_with_msg",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"run_threads_count",
",",
"THREADS",
")",
";",
"gupcr_assert",
"(",
"THREADS",
">=",
"1",
")",
";",
"#if",
"HAVE_UPC_BACKTRACE",
"\n",
"gupcr_backtrace_init",
"(",
"gupcr_get_pgm_name",
"(",
")",
")",
";",
"#endif",
"gupcr_portals_ni_init",
"(",
")",
";",
"gupcr_nodetree_setup",
"(",
")",
";",
"gupcr_node_init",
"(",
")",
";",
"gupcr_gmem_init",
"(",
")",
";",
"gupcr_lock_init",
"(",
")",
";",
"gupcr_barrier_init",
"(",
")",
";",
"gupcr_broadcast_init",
"(",
")",
";",
"gupcr_coll_init",
"(",
")",
";",
"gupcr_atomic_init",
"(",
")",
";",
"gupcr_nb_init",
"(",
")",
";",
"gupcr_shutdown_init",
"(",
")",
";",
"GUPCR_PTS_SET_NULL_SHARED",
"(",
"heap_region_base",
")",
";",
"GUPCR_PTS_SET_THREAD",
"(",
"heap_region_base",
",",
"MYTHREAD",
")",
";",
"GUPCR_PTS_SET_VADDR",
"(",
"heap_region_base",
",",
"gupcr_gmem_heap_base_offset",
")",
";",
"heap_region_size",
"=",
"gupcr_gmem_heap_size",
";",
"gupcr_alloc_init",
"(",
"heap_region_base",
",",
"heap_region_size",
")",
";",
"gupcr_init_complete",
"(",
")",
";",
"gupcr_finalize_ok",
"=",
"1",
";",
"}"
] | Initialize UPC runtime. | [
"Initialize",
"UPC",
"runtime",
"."
] | [
"/* Initialize Runtime. */",
"/* Report an error to stderr as the GUPC error reporting\n\t is not initialized yet. Note: all threads report\n\t this error. */",
"/* Get the thread number. */",
"/* Each UPC thread is OMP master thread. */",
"/* Set up debugging, tracing, statistics, and timing support. */",
"/* Initialize Portals. */",
"/* Validate program info. */",
"/* THREADS == -1, dynamic number of threads\n THREADS != -1, static number of threads and\n number of running and compiled threads must match. */",
"/* Initialize backtrace support. */",
"/* Initialize the Portals Network Interface. */",
"/* Initialize this thread's multi-node tree position. */",
"/* Initialize various runtime components. */",
"/* Indicate that runtime initialization is complete. */",
"/* It is ok to call the finalization routines. */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
5cf18cc577d0ce770db4220c4dad025a827a56d2 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_main.c | [
"Apache-2.0"
] | C | gupcr_fini | void | void
gupcr_fini (void)
{
gupcr_shutdown_fini ();
gupcr_nb_fini ();
gupcr_atomic_fini ();
gupcr_broadcast_fini ();
gupcr_barrier_fini ();
gupcr_lock_fini ();
gupcr_gmem_fini ();
gupcr_node_fini ();
gupcr_coll_fini ();
gupcr_portals_ni_fini ();
gupcr_portals_fini ();
gupcr_runtime_fini ();
gupcr_utils_fini ();
} | /**
* UPC runtime finalization.
*
* All previously allocated Portals4 resources are released.
*/ | UPC runtime finalization.
All previously allocated Portals4 resources are released. | [
"UPC",
"runtime",
"finalization",
".",
"All",
"previously",
"allocated",
"Portals4",
"resources",
"are",
"released",
"."
] | void
gupcr_fini (void)
{
gupcr_shutdown_fini ();
gupcr_nb_fini ();
gupcr_atomic_fini ();
gupcr_broadcast_fini ();
gupcr_barrier_fini ();
gupcr_lock_fini ();
gupcr_gmem_fini ();
gupcr_node_fini ();
gupcr_coll_fini ();
gupcr_portals_ni_fini ();
gupcr_portals_fini ();
gupcr_runtime_fini ();
gupcr_utils_fini ();
} | [
"void",
"gupcr_fini",
"(",
"void",
")",
"{",
"gupcr_shutdown_fini",
"(",
")",
";",
"gupcr_nb_fini",
"(",
")",
";",
"gupcr_atomic_fini",
"(",
")",
";",
"gupcr_broadcast_fini",
"(",
")",
";",
"gupcr_barrier_fini",
"(",
")",
";",
"gupcr_lock_fini",
"(",
")",
";",
"gupcr_gmem_fini",
"(",
")",
";",
"gupcr_node_fini",
"(",
")",
";",
"gupcr_coll_fini",
"(",
")",
";",
"gupcr_portals_ni_fini",
"(",
")",
";",
"gupcr_portals_fini",
"(",
")",
";",
"gupcr_runtime_fini",
"(",
")",
";",
"gupcr_utils_fini",
"(",
")",
";",
"}"
] | UPC runtime finalization. | [
"UPC",
"runtime",
"finalization",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
5cf18cc577d0ce770db4220c4dad025a827a56d2 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_main.c | [
"Apache-2.0"
] | C | gupcr_per_thread_init | void | static void
gupcr_per_thread_init (void)
{
typedef void (*func_ptr_t) (void);
extern func_ptr_t GUPCR_INIT_ARRAY_START[];
extern func_ptr_t GUPCR_INIT_ARRAY_END[];
const int n_init = (int) (GUPCR_INIT_ARRAY_END - GUPCR_INIT_ARRAY_START);
int i;
for (i = 0; i < n_init; ++i)
{
func_ptr_t init_func = GUPCR_INIT_ARRAY_START[i];
/* Skip zero words, possibly introduced by a section marker,
or by the linker. */
if (init_func)
(*init_func) ();
}
} | /**
* Per thread initialization.
*
* The following pre-requisites must be met, before calling this routine:
* - the runtime system has been initialized.
* - the UPC heap manager has been initialized.
*
* The barrier that is executed subsequent to calling this
* per thread initialization procedure and prior to
* calling the main program ensures that the initialization
* completes before the main program runs.
*/ | Per thread initialization.
The following pre-requisites must be met, before calling this routine:
- the runtime system has been initialized.
- the UPC heap manager has been initialized.
The barrier that is executed subsequent to calling this
per thread initialization procedure and prior to
calling the main program ensures that the initialization
completes before the main program runs. | [
"Per",
"thread",
"initialization",
".",
"The",
"following",
"pre",
"-",
"requisites",
"must",
"be",
"met",
"before",
"calling",
"this",
"routine",
":",
"-",
"the",
"runtime",
"system",
"has",
"been",
"initialized",
".",
"-",
"the",
"UPC",
"heap",
"manager",
"has",
"been",
"initialized",
".",
"The",
"barrier",
"that",
"is",
"executed",
"subsequent",
"to",
"calling",
"this",
"per",
"thread",
"initialization",
"procedure",
"and",
"prior",
"to",
"calling",
"the",
"main",
"program",
"ensures",
"that",
"the",
"initialization",
"completes",
"before",
"the",
"main",
"program",
"runs",
"."
] | static void
gupcr_per_thread_init (void)
{
typedef void (*func_ptr_t) (void);
extern func_ptr_t GUPCR_INIT_ARRAY_START[];
extern func_ptr_t GUPCR_INIT_ARRAY_END[];
const int n_init = (int) (GUPCR_INIT_ARRAY_END - GUPCR_INIT_ARRAY_START);
int i;
for (i = 0; i < n_init; ++i)
{
func_ptr_t init_func = GUPCR_INIT_ARRAY_START[i];
if (init_func)
(*init_func) ();
}
} | [
"static",
"void",
"gupcr_per_thread_init",
"(",
"void",
")",
"{",
"typedef",
"void",
"(",
"*",
"func_ptr_t",
")",
"(",
"void",
")",
";",
"extern",
"func_ptr_t",
"GUPCR_INIT_ARRAY_START",
"[",
"]",
";",
"extern",
"func_ptr_t",
"GUPCR_INIT_ARRAY_END",
"[",
"]",
";",
"const",
"int",
"n_init",
"=",
"(",
"int",
")",
"(",
"GUPCR_INIT_ARRAY_END",
"-",
"GUPCR_INIT_ARRAY_START",
")",
";",
"int",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"n_init",
";",
"++",
"i",
")",
"{",
"func_ptr_t",
"init_func",
"=",
"GUPCR_INIT_ARRAY_START",
"[",
"i",
"]",
";",
"if",
"(",
"init_func",
")",
"(",
"*",
"init_func",
")",
"(",
")",
";",
"}",
"}"
] | Per thread initialization. | [
"Per",
"thread",
"initialization",
"."
] | [
"/* Skip zero words, possibly introduced by a section marker,\n or by the linker. */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
5cf18cc577d0ce770db4220c4dad025a827a56d2 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_main.c | [
"Apache-2.0"
] | C | __upc_omp_check | void | void
__upc_omp_check (void)
{
if (__upc_omp_master_id != pthread_self ())
gupcr_fatal_error ("UPC runtime calls are allowed only from the UPC threads");;
} | /**
* Check for UPC runtime calls from OMP threads.
*/ | Check for UPC runtime calls from OMP threads. | [
"Check",
"for",
"UPC",
"runtime",
"calls",
"from",
"OMP",
"threads",
"."
] | void
__upc_omp_check (void)
{
if (__upc_omp_master_id != pthread_self ())
gupcr_fatal_error ("UPC runtime calls are allowed only from the UPC threads");;
} | [
"void",
"__upc_omp_check",
"(",
"void",
")",
"{",
"if",
"(",
"__upc_omp_master_id",
"!=",
"pthread_self",
"(",
")",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
";",
"}"
] | Check for UPC runtime calls from OMP threads. | [
"Check",
"for",
"UPC",
"runtime",
"calls",
"from",
"OMP",
"threads",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
5cf18cc577d0ce770db4220c4dad025a827a56d2 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_main.c | [
"Apache-2.0"
] | C | upc_global_exit | void | void
upc_global_exit (int status)
{
/* Send exit signal to all other threads. */
gupcr_signal_exit (status);
/* It is NOT ok to call the finalization routines as there might
be outstanding Portals transactions. */
gupcr_finalize_ok = 0;
exit (status);
} | /**
* Exit program with given status and terminate all other threads.
*
* A special "shutdown" PTE is used to send a signal to
* other threads that they should exit.
* @param [in] status Status code for return
* @ingroup UPC-LIBRARY UPC Library Interface
*/ | Exit program with given status and terminate all other threads.
A special "shutdown" PTE is used to send a signal to
other threads that they should exit.
@param [in] status Status code for return
@ingroup UPC-LIBRARY UPC Library Interface | [
"Exit",
"program",
"with",
"given",
"status",
"and",
"terminate",
"all",
"other",
"threads",
".",
"A",
"special",
"\"",
"shutdown",
"\"",
"PTE",
"is",
"used",
"to",
"send",
"a",
"signal",
"to",
"other",
"threads",
"that",
"they",
"should",
"exit",
".",
"@param",
"[",
"in",
"]",
"status",
"Status",
"code",
"for",
"return",
"@ingroup",
"UPC",
"-",
"LIBRARY",
"UPC",
"Library",
"Interface"
] | void
upc_global_exit (int status)
{
gupcr_signal_exit (status);
gupcr_finalize_ok = 0;
exit (status);
} | [
"void",
"upc_global_exit",
"(",
"int",
"status",
")",
"{",
"gupcr_signal_exit",
"(",
"status",
")",
";",
"gupcr_finalize_ok",
"=",
"0",
";",
"exit",
"(",
"status",
")",
";",
"}"
] | Exit program with given status and terminate all other threads. | [
"Exit",
"program",
"with",
"given",
"status",
"and",
"terminate",
"all",
"other",
"threads",
"."
] | [
"/* Send exit signal to all other threads. */",
"/* It is NOT ok to call the finalization routines as there might\n be outstanding Portals transactions. */"
] | [
{
"param": "status",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "status",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
178bc56a955c8e185cba56a9566d511cf0c1f8c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_env.c | [
"Apache-2.0"
] | C | gupcr_facility_mask_for_name | gupcr_facility_t | static gupcr_facility_t
gupcr_facility_mask_for_name (const char *const facility)
{
unsigned i;
for (i = 0; i < GUPCR_FC_TBL_SIZE; ++i)
{
if (!strcasecmp (gupcr_facility_table[i].name, facility))
return gupcr_facility_table[i].mask;
}
return FC_NONE;
} | /* Look up the name given by FACILITY and return the facility mask value
associated with that name. */ | Look up the name given by FACILITY and return the facility mask value
associated with that name. | [
"Look",
"up",
"the",
"name",
"given",
"by",
"FACILITY",
"and",
"return",
"the",
"facility",
"mask",
"value",
"associated",
"with",
"that",
"name",
"."
] | static gupcr_facility_t
gupcr_facility_mask_for_name (const char *const facility)
{
unsigned i;
for (i = 0; i < GUPCR_FC_TBL_SIZE; ++i)
{
if (!strcasecmp (gupcr_facility_table[i].name, facility))
return gupcr_facility_table[i].mask;
}
return FC_NONE;
} | [
"static",
"gupcr_facility_t",
"gupcr_facility_mask_for_name",
"(",
"const",
"char",
"*",
"const",
"facility",
")",
"{",
"unsigned",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"GUPCR_FC_TBL_SIZE",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"strcasecmp",
"(",
"gupcr_facility_table",
"[",
"i",
"]",
".",
"name",
",",
"facility",
")",
")",
"return",
"gupcr_facility_table",
"[",
"i",
"]",
".",
"mask",
";",
"}",
"return",
"FC_NONE",
";",
"}"
] | Look up the name given by FACILITY and return the facility mask value
associated with that name. | [
"Look",
"up",
"the",
"name",
"given",
"by",
"FACILITY",
"and",
"return",
"the",
"facility",
"mask",
"value",
"associated",
"with",
"that",
"name",
"."
] | [] | [
{
"param": "facility",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "facility",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
178bc56a955c8e185cba56a9566d511cf0c1f8c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_env.c | [
"Apache-2.0"
] | C | gupcr_env_kind_for_var | gupcr_env_kind | static gupcr_env_kind
gupcr_env_kind_for_var (const char *const env_var_arg)
{
gupcr_env_kind env_kind = ENV_NONE;
unsigned i;
char *env_var_dup, *env_var;
gupcr_strdup (env_var_dup, env_var_arg);
env_var = strtok (env_var_dup, "=");
gupcr_assert (env_var != NULL);
for (i = 0; i < GUPCR_ENV_VAR_TBL_SIZE; ++i)
{
if (!strcmp (gupcr_env_var_table[i].name, env_var))
return gupcr_env_var_table[i].kind;
}
gupcr_free (env_var_dup);
return env_kind;
} | /* Extract the environment variable name appearing before the
first '=' sign in ENV_VAR_ARG; look it up in the list of
known "UPC_" environment variables and return an
integer value that is used to identify this particular
environment variable name. */ | Extract the environment variable name appearing before the
first '=' sign in ENV_VAR_ARG; look it up in the list of
known "UPC_" environment variables and return an
integer value that is used to identify this particular
environment variable name. | [
"Extract",
"the",
"environment",
"variable",
"name",
"appearing",
"before",
"the",
"first",
"'",
"=",
"'",
"sign",
"in",
"ENV_VAR_ARG",
";",
"look",
"it",
"up",
"in",
"the",
"list",
"of",
"known",
"\"",
"UPC_",
"\"",
"environment",
"variables",
"and",
"return",
"an",
"integer",
"value",
"that",
"is",
"used",
"to",
"identify",
"this",
"particular",
"environment",
"variable",
"name",
"."
] | static gupcr_env_kind
gupcr_env_kind_for_var (const char *const env_var_arg)
{
gupcr_env_kind env_kind = ENV_NONE;
unsigned i;
char *env_var_dup, *env_var;
gupcr_strdup (env_var_dup, env_var_arg);
env_var = strtok (env_var_dup, "=");
gupcr_assert (env_var != NULL);
for (i = 0; i < GUPCR_ENV_VAR_TBL_SIZE; ++i)
{
if (!strcmp (gupcr_env_var_table[i].name, env_var))
return gupcr_env_var_table[i].kind;
}
gupcr_free (env_var_dup);
return env_kind;
} | [
"static",
"gupcr_env_kind",
"gupcr_env_kind_for_var",
"(",
"const",
"char",
"*",
"const",
"env_var_arg",
")",
"{",
"gupcr_env_kind",
"env_kind",
"=",
"ENV_NONE",
";",
"unsigned",
"i",
";",
"char",
"*",
"env_var_dup",
",",
"*",
"env_var",
";",
"gupcr_strdup",
"(",
"env_var_dup",
",",
"env_var_arg",
")",
";",
"env_var",
"=",
"strtok",
"(",
"env_var_dup",
",",
"\"",
"\"",
")",
";",
"gupcr_assert",
"(",
"env_var",
"!=",
"NULL",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"GUPCR_ENV_VAR_TBL_SIZE",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"strcmp",
"(",
"gupcr_env_var_table",
"[",
"i",
"]",
".",
"name",
",",
"env_var",
")",
")",
"return",
"gupcr_env_var_table",
"[",
"i",
"]",
".",
"kind",
";",
"}",
"gupcr_free",
"(",
"env_var_dup",
")",
";",
"return",
"env_kind",
";",
"}"
] | Extract the environment variable name appearing before the
first '=' sign in ENV_VAR_ARG; look it up in the list of
known "UPC_" environment variables and return an
integer value that is used to identify this particular
environment variable name. | [
"Extract",
"the",
"environment",
"variable",
"name",
"appearing",
"before",
"the",
"first",
"'",
"=",
"'",
"sign",
"in",
"ENV_VAR_ARG",
";",
"look",
"it",
"up",
"in",
"the",
"list",
"of",
"known",
"\"",
"UPC_",
"\"",
"environment",
"variables",
"and",
"return",
"an",
"integer",
"value",
"that",
"is",
"used",
"to",
"identify",
"this",
"particular",
"environment",
"variable",
"name",
"."
] | [] | [
{
"param": "env_var_arg",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "env_var_arg",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
178bc56a955c8e185cba56a9566d511cf0c1f8c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_env.c | [
"Apache-2.0"
] | C | gupcr_env_facility_list | gupcr_facility_t | gupcr_facility_t
gupcr_env_facility_list (const char *const env_var_arg)
{
gupcr_facility_t facility_mask = FC_NONE;
char *env_var_dup, *env_var, *facility_name;
gupcr_strdup (env_var_dup, env_var_arg);
if ((env_var = strtok (env_var_dup, "=")))
{
while ((facility_name = strtok (NULL, ",")))
{
gupcr_facility_t facility;
facility = gupcr_facility_mask_for_name (facility_name);
if (!facility)
gupcr_error ("invalid facility name `%s' found in "
"environment variable: `%s'",
facility_name, env_var_arg);
facility_mask |= facility;
}
}
else
gupcr_error ("invalid UPC environment variable syntax: `%s'", env_var);
gupcr_free (env_var_dup);
return facility_mask;
} | /* Process the comma separated list of facility names that
appear after the '=' sign. Return a mask value indicating
which facility names were specified. */ | Process the comma separated list of facility names that
appear after the '=' sign. Return a mask value indicating
which facility names were specified. | [
"Process",
"the",
"comma",
"separated",
"list",
"of",
"facility",
"names",
"that",
"appear",
"after",
"the",
"'",
"=",
"'",
"sign",
".",
"Return",
"a",
"mask",
"value",
"indicating",
"which",
"facility",
"names",
"were",
"specified",
"."
] | gupcr_facility_t
gupcr_env_facility_list (const char *const env_var_arg)
{
gupcr_facility_t facility_mask = FC_NONE;
char *env_var_dup, *env_var, *facility_name;
gupcr_strdup (env_var_dup, env_var_arg);
if ((env_var = strtok (env_var_dup, "=")))
{
while ((facility_name = strtok (NULL, ",")))
{
gupcr_facility_t facility;
facility = gupcr_facility_mask_for_name (facility_name);
if (!facility)
gupcr_error ("invalid facility name `%s' found in "
"environment variable: `%s'",
facility_name, env_var_arg);
facility_mask |= facility;
}
}
else
gupcr_error ("invalid UPC environment variable syntax: `%s'", env_var);
gupcr_free (env_var_dup);
return facility_mask;
} | [
"gupcr_facility_t",
"gupcr_env_facility_list",
"(",
"const",
"char",
"*",
"const",
"env_var_arg",
")",
"{",
"gupcr_facility_t",
"facility_mask",
"=",
"FC_NONE",
";",
"char",
"*",
"env_var_dup",
",",
"*",
"env_var",
",",
"*",
"facility_name",
";",
"gupcr_strdup",
"(",
"env_var_dup",
",",
"env_var_arg",
")",
";",
"if",
"(",
"(",
"env_var",
"=",
"strtok",
"(",
"env_var_dup",
",",
"\"",
"\"",
")",
")",
")",
"{",
"while",
"(",
"(",
"facility_name",
"=",
"strtok",
"(",
"NULL",
",",
"\"",
"\"",
")",
")",
")",
"{",
"gupcr_facility_t",
"facility",
";",
"facility",
"=",
"gupcr_facility_mask_for_name",
"(",
"facility_name",
")",
";",
"if",
"(",
"!",
"facility",
")",
"gupcr_error",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"facility_name",
",",
"env_var_arg",
")",
";",
"facility_mask",
"|=",
"facility",
";",
"}",
"}",
"else",
"gupcr_error",
"(",
"\"",
"\"",
",",
"env_var",
")",
";",
"gupcr_free",
"(",
"env_var_dup",
")",
";",
"return",
"facility_mask",
";",
"}"
] | Process the comma separated list of facility names that
appear after the '=' sign. | [
"Process",
"the",
"comma",
"separated",
"list",
"of",
"facility",
"names",
"that",
"appear",
"after",
"the",
"'",
"=",
"'",
"sign",
"."
] | [] | [
{
"param": "env_var_arg",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "env_var_arg",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
178bc56a955c8e185cba56a9566d511cf0c1f8c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_env.c | [
"Apache-2.0"
] | C | gupcr_env_init | void | void
gupcr_env_init (void)
{
/* System environment, see: environ (7). */
extern char **environ;
const char *env_var;
unsigned i;
for (i = 0; (env_var = environ[i]); ++i)
{
if (!strncmp (env_var, "UPC_", 4))
{
const int env_kind = gupcr_env_kind_for_var (env_var);
gupcr_facility_t facility_mask;
const char *filename;
size_t heap_size;
switch (env_kind)
{
case ENV_UPC_BACKTRACE:
gupcr_set_backtrace (gupcr_env_boolean (env_var));
break;
case ENV_UPC_DEBUG:
facility_mask = gupcr_env_facility_list (env_var);
if (facility_mask)
gupcr_set_debug_facility (facility_mask);
break;
case ENV_UPC_DEBUGFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_debug_filename (filename);
break;
case ENV_UPC_FIRSTTOUCH:
/* no-op */
break;
case ENV_UPC_FORCETOUCH:
gupcr_set_forcetouch (gupcr_env_boolean (env_var));
break;
case ENV_UPC_LOG:
facility_mask = gupcr_env_facility_list (env_var);
if (facility_mask)
gupcr_set_log_facility (facility_mask);
break;
case ENV_UPC_LOGFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_log_filename (filename);
break;
case ENV_UPC_NO_WARN:
gupcr_no_warn ();
break;
case ENV_UPC_NODE_LOCAL_MEM:
gupcr_set_node_local_memory (gupcr_env_boolean (env_var));
break;
case ENV_UPC_NODES:
/* no-op */
break;
case ENV_UPC_POLITE:
/* no-op */
break;
case ENV_UPC_QUIET:
gupcr_be_quiet ();
break;
case ENV_UPC_SHARED_HEAP_SIZE:
heap_size = (size_t) gupcr_env_size (env_var,
GUPCR_MAX_HEAP_SIZE);
gupcr_set_shared_heap_size (heap_size);
break;
case ENV_UPC_STATS:
facility_mask = gupcr_env_facility_list (env_var);
gupcr_set_stats_facility (facility_mask);
break;
case ENV_UPC_STATSFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_stats_filename (filename);
break;
case ENV_UPC_TRACE:
facility_mask = gupcr_env_facility_list (env_var);
gupcr_set_trace_facility (facility_mask);
break;
case ENV_UPC_TRACEFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_trace_filename (filename);
break;
case ENV_UPC_REQUIRE_SHARED_SIZE:
/* no-op */
break;
case ENV_NONE:
gupcr_warn ("unknown UPC environment variable: %s", env_var);
break;
default:
gupcr_fatal_error ("env variable case value out of range");
}
}
}
} | /* Process all variables in the environment that begin with "UPC_".
Make various calls back into "gupcr_utils.c" to implement
the actions associated with each given environment variable. */ | Process all variables in the environment that begin with "UPC_".
Make various calls back into "gupcr_utils.c" to implement
the actions associated with each given environment variable. | [
"Process",
"all",
"variables",
"in",
"the",
"environment",
"that",
"begin",
"with",
"\"",
"UPC_",
"\"",
".",
"Make",
"various",
"calls",
"back",
"into",
"\"",
"gupcr_utils",
".",
"c",
"\"",
"to",
"implement",
"the",
"actions",
"associated",
"with",
"each",
"given",
"environment",
"variable",
"."
] | void
gupcr_env_init (void)
{
extern char **environ;
const char *env_var;
unsigned i;
for (i = 0; (env_var = environ[i]); ++i)
{
if (!strncmp (env_var, "UPC_", 4))
{
const int env_kind = gupcr_env_kind_for_var (env_var);
gupcr_facility_t facility_mask;
const char *filename;
size_t heap_size;
switch (env_kind)
{
case ENV_UPC_BACKTRACE:
gupcr_set_backtrace (gupcr_env_boolean (env_var));
break;
case ENV_UPC_DEBUG:
facility_mask = gupcr_env_facility_list (env_var);
if (facility_mask)
gupcr_set_debug_facility (facility_mask);
break;
case ENV_UPC_DEBUGFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_debug_filename (filename);
break;
case ENV_UPC_FIRSTTOUCH:
break;
case ENV_UPC_FORCETOUCH:
gupcr_set_forcetouch (gupcr_env_boolean (env_var));
break;
case ENV_UPC_LOG:
facility_mask = gupcr_env_facility_list (env_var);
if (facility_mask)
gupcr_set_log_facility (facility_mask);
break;
case ENV_UPC_LOGFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_log_filename (filename);
break;
case ENV_UPC_NO_WARN:
gupcr_no_warn ();
break;
case ENV_UPC_NODE_LOCAL_MEM:
gupcr_set_node_local_memory (gupcr_env_boolean (env_var));
break;
case ENV_UPC_NODES:
break;
case ENV_UPC_POLITE:
break;
case ENV_UPC_QUIET:
gupcr_be_quiet ();
break;
case ENV_UPC_SHARED_HEAP_SIZE:
heap_size = (size_t) gupcr_env_size (env_var,
GUPCR_MAX_HEAP_SIZE);
gupcr_set_shared_heap_size (heap_size);
break;
case ENV_UPC_STATS:
facility_mask = gupcr_env_facility_list (env_var);
gupcr_set_stats_facility (facility_mask);
break;
case ENV_UPC_STATSFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_stats_filename (filename);
break;
case ENV_UPC_TRACE:
facility_mask = gupcr_env_facility_list (env_var);
gupcr_set_trace_facility (facility_mask);
break;
case ENV_UPC_TRACEFILE:
filename = gupcr_env_filename (env_var);
if (filename)
gupcr_set_trace_filename (filename);
break;
case ENV_UPC_REQUIRE_SHARED_SIZE:
break;
case ENV_NONE:
gupcr_warn ("unknown UPC environment variable: %s", env_var);
break;
default:
gupcr_fatal_error ("env variable case value out of range");
}
}
}
} | [
"void",
"gupcr_env_init",
"(",
"void",
")",
"{",
"extern",
"char",
"*",
"*",
"environ",
";",
"const",
"char",
"*",
"env_var",
";",
"unsigned",
"i",
";",
"for",
"(",
"i",
"=",
"0",
";",
"(",
"env_var",
"=",
"environ",
"[",
"i",
"]",
")",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"strncmp",
"(",
"env_var",
",",
"\"",
"\"",
",",
"4",
")",
")",
"{",
"const",
"int",
"env_kind",
"=",
"gupcr_env_kind_for_var",
"(",
"env_var",
")",
";",
"gupcr_facility_t",
"facility_mask",
";",
"const",
"char",
"*",
"filename",
";",
"size_t",
"heap_size",
";",
"switch",
"(",
"env_kind",
")",
"{",
"case",
"ENV_UPC_BACKTRACE",
":",
"gupcr_set_backtrace",
"(",
"gupcr_env_boolean",
"(",
"env_var",
")",
")",
";",
"break",
";",
"case",
"ENV_UPC_DEBUG",
":",
"facility_mask",
"=",
"gupcr_env_facility_list",
"(",
"env_var",
")",
";",
"if",
"(",
"facility_mask",
")",
"gupcr_set_debug_facility",
"(",
"facility_mask",
")",
";",
"break",
";",
"case",
"ENV_UPC_DEBUGFILE",
":",
"filename",
"=",
"gupcr_env_filename",
"(",
"env_var",
")",
";",
"if",
"(",
"filename",
")",
"gupcr_set_debug_filename",
"(",
"filename",
")",
";",
"break",
";",
"case",
"ENV_UPC_FIRSTTOUCH",
":",
"break",
";",
"case",
"ENV_UPC_FORCETOUCH",
":",
"gupcr_set_forcetouch",
"(",
"gupcr_env_boolean",
"(",
"env_var",
")",
")",
";",
"break",
";",
"case",
"ENV_UPC_LOG",
":",
"facility_mask",
"=",
"gupcr_env_facility_list",
"(",
"env_var",
")",
";",
"if",
"(",
"facility_mask",
")",
"gupcr_set_log_facility",
"(",
"facility_mask",
")",
";",
"break",
";",
"case",
"ENV_UPC_LOGFILE",
":",
"filename",
"=",
"gupcr_env_filename",
"(",
"env_var",
")",
";",
"if",
"(",
"filename",
")",
"gupcr_set_log_filename",
"(",
"filename",
")",
";",
"break",
";",
"case",
"ENV_UPC_NO_WARN",
":",
"gupcr_no_warn",
"(",
")",
";",
"break",
";",
"case",
"ENV_UPC_NODE_LOCAL_MEM",
":",
"gupcr_set_node_local_memory",
"(",
"gupcr_env_boolean",
"(",
"env_var",
")",
")",
";",
"break",
";",
"case",
"ENV_UPC_NODES",
":",
"break",
";",
"case",
"ENV_UPC_POLITE",
":",
"break",
";",
"case",
"ENV_UPC_QUIET",
":",
"gupcr_be_quiet",
"(",
")",
";",
"break",
";",
"case",
"ENV_UPC_SHARED_HEAP_SIZE",
":",
"heap_size",
"=",
"(",
"size_t",
")",
"gupcr_env_size",
"(",
"env_var",
",",
"GUPCR_MAX_HEAP_SIZE",
")",
";",
"gupcr_set_shared_heap_size",
"(",
"heap_size",
")",
";",
"break",
";",
"case",
"ENV_UPC_STATS",
":",
"facility_mask",
"=",
"gupcr_env_facility_list",
"(",
"env_var",
")",
";",
"gupcr_set_stats_facility",
"(",
"facility_mask",
")",
";",
"break",
";",
"case",
"ENV_UPC_STATSFILE",
":",
"filename",
"=",
"gupcr_env_filename",
"(",
"env_var",
")",
";",
"if",
"(",
"filename",
")",
"gupcr_set_stats_filename",
"(",
"filename",
")",
";",
"break",
";",
"case",
"ENV_UPC_TRACE",
":",
"facility_mask",
"=",
"gupcr_env_facility_list",
"(",
"env_var",
")",
";",
"gupcr_set_trace_facility",
"(",
"facility_mask",
")",
";",
"break",
";",
"case",
"ENV_UPC_TRACEFILE",
":",
"filename",
"=",
"gupcr_env_filename",
"(",
"env_var",
")",
";",
"if",
"(",
"filename",
")",
"gupcr_set_trace_filename",
"(",
"filename",
")",
";",
"break",
";",
"case",
"ENV_UPC_REQUIRE_SHARED_SIZE",
":",
"break",
";",
"case",
"ENV_NONE",
":",
"gupcr_warn",
"(",
"\"",
"\"",
",",
"env_var",
")",
";",
"break",
";",
"default",
":",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"}",
"}",
"}",
"}"
] | Process all variables in the environment that begin with "UPC_". | [
"Process",
"all",
"variables",
"in",
"the",
"environment",
"that",
"begin",
"with",
"\"",
"UPC_",
"\"",
"."
] | [
"/* System environment, see: environ (7). */",
"/* no-op */",
"/* no-op */",
"/* no-op */",
"/* no-op */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
7d0fdc13cc0bed2fdfb0b41f26d3e2352e0484af | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_node.c | [
"Apache-2.0"
] | C | gupcr_mem_check | void | static void
gupcr_mem_check (char *mem, size_t size, int thread)
{
char temp;
struct sigaction action;
struct sigaction old_action;
/* Set file name for better diagnostic. */
gupcr_check_thread = thread;
/* Install new SIGBUS handler to catch memory faults. */
action.sa_handler = gupcr_mem_sigbus;
sigemptyset (&action.sa_mask);
action.sa_flags = 0;
sigaction (SIGBUS, &action, &old_action);
if (gupcr_is_forcetouch_enabled ())
{
volatile char *memp = (volatile char *) mem;
while (memp < mem + size)
{
temp = *memp;
*memp = temp;
memp += GUPCR_MEMORY_PAGE_SIZE;
}
}
else
{
/* Only check the first and the last page. */
temp = *(volatile char *) mem;
*(volatile char *) mem = temp;
temp = *(volatile char *) (mem + size - 16);
*(volatile char *) (mem + size - 16) = temp;
}
/* Restore SIGBUS handler. */
sigaction (SIGBUS, &old_action, NULL);
} | /**
* Shared memory check.
*
* Check that memory at the specified address and with the
* specified size can be accessed. As memory might not
* accessible, this procedure installs its own SIGBUS handler
* in order to provide the user with better diagnostic.
*/ | Shared memory check.
Check that memory at the specified address and with the
specified size can be accessed. As memory might not
accessible, this procedure installs its own SIGBUS handler
in order to provide the user with better diagnostic. | [
"Shared",
"memory",
"check",
".",
"Check",
"that",
"memory",
"at",
"the",
"specified",
"address",
"and",
"with",
"the",
"specified",
"size",
"can",
"be",
"accessed",
".",
"As",
"memory",
"might",
"not",
"accessible",
"this",
"procedure",
"installs",
"its",
"own",
"SIGBUS",
"handler",
"in",
"order",
"to",
"provide",
"the",
"user",
"with",
"better",
"diagnostic",
"."
] | static void
gupcr_mem_check (char *mem, size_t size, int thread)
{
char temp;
struct sigaction action;
struct sigaction old_action;
gupcr_check_thread = thread;
action.sa_handler = gupcr_mem_sigbus;
sigemptyset (&action.sa_mask);
action.sa_flags = 0;
sigaction (SIGBUS, &action, &old_action);
if (gupcr_is_forcetouch_enabled ())
{
volatile char *memp = (volatile char *) mem;
while (memp < mem + size)
{
temp = *memp;
*memp = temp;
memp += GUPCR_MEMORY_PAGE_SIZE;
}
}
else
{
temp = *(volatile char *) mem;
*(volatile char *) mem = temp;
temp = *(volatile char *) (mem + size - 16);
*(volatile char *) (mem + size - 16) = temp;
}
sigaction (SIGBUS, &old_action, NULL);
} | [
"static",
"void",
"gupcr_mem_check",
"(",
"char",
"*",
"mem",
",",
"size_t",
"size",
",",
"int",
"thread",
")",
"{",
"char",
"temp",
";",
"struct",
"sigaction",
"action",
";",
"struct",
"sigaction",
"old_action",
";",
"gupcr_check_thread",
"=",
"thread",
";",
"action",
".",
"sa_handler",
"=",
"gupcr_mem_sigbus",
";",
"sigemptyset",
"(",
"&",
"action",
".",
"sa_mask",
")",
";",
"action",
".",
"sa_flags",
"=",
"0",
";",
"sigaction",
"(",
"SIGBUS",
",",
"&",
"action",
",",
"&",
"old_action",
")",
";",
"if",
"(",
"gupcr_is_forcetouch_enabled",
"(",
")",
")",
"{",
"volatile",
"char",
"*",
"memp",
"=",
"(",
"volatile",
"char",
"*",
")",
"mem",
";",
"while",
"(",
"memp",
"<",
"mem",
"+",
"size",
")",
"{",
"temp",
"=",
"*",
"memp",
";",
"*",
"memp",
"=",
"temp",
";",
"memp",
"+=",
"GUPCR_MEMORY_PAGE_SIZE",
";",
"}",
"}",
"else",
"{",
"temp",
"=",
"*",
"(",
"volatile",
"char",
"*",
")",
"mem",
";",
"*",
"(",
"volatile",
"char",
"*",
")",
"mem",
"=",
"temp",
";",
"temp",
"=",
"*",
"(",
"volatile",
"char",
"*",
")",
"(",
"mem",
"+",
"size",
"-",
"16",
")",
";",
"*",
"(",
"volatile",
"char",
"*",
")",
"(",
"mem",
"+",
"size",
"-",
"16",
")",
"=",
"temp",
";",
"}",
"sigaction",
"(",
"SIGBUS",
",",
"&",
"old_action",
",",
"NULL",
")",
";",
"}"
] | Shared memory check. | [
"Shared",
"memory",
"check",
"."
] | [
"/* Set file name for better diagnostic. */",
"/* Install new SIGBUS handler to catch memory faults. */",
"/* Only check the first and the last page. */",
"/* Restore SIGBUS handler. */"
] | [
{
"param": "mem",
"type": "char"
},
{
"param": "size",
"type": "size_t"
},
{
"param": "thread",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "thread",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
7d0fdc13cc0bed2fdfb0b41f26d3e2352e0484af | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_node.c | [
"Apache-2.0"
] | C | gupcr_mem_private | char | char *
gupcr_mem_private (size_t size)
{
char *memaddr;
memaddr = mmap (NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, OFFSET_ZERO);
if (!memaddr || memaddr == MAP_ERROR)
gupcr_fatal_error
("cannot mmap 0x%lx bytes of node's private shared memory (%s)",
(long unsigned) size, strerror (errno));
gupcr_log (FC_MEM, "using private mapping for shared space");
gupcr_mem_check (memaddr, size, MYTHREAD);
return memaddr;
} | /**
* Allocate memory for a thread's shared space.
*
* This memory is never shared with other threads
* on the same node and is visible through Portals
* functions only.
*
* @retval Memory address of mapping
*/ | Allocate memory for a thread's shared space.
This memory is never shared with other threads
on the same node and is visible through Portals
functions only.
@retval Memory address of mapping | [
"Allocate",
"memory",
"for",
"a",
"thread",
"'",
"s",
"shared",
"space",
".",
"This",
"memory",
"is",
"never",
"shared",
"with",
"other",
"threads",
"on",
"the",
"same",
"node",
"and",
"is",
"visible",
"through",
"Portals",
"functions",
"only",
".",
"@retval",
"Memory",
"address",
"of",
"mapping"
] | char *
gupcr_mem_private (size_t size)
{
char *memaddr;
memaddr = mmap (NULL, size, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, OFFSET_ZERO);
if (!memaddr || memaddr == MAP_ERROR)
gupcr_fatal_error
("cannot mmap 0x%lx bytes of node's private shared memory (%s)",
(long unsigned) size, strerror (errno));
gupcr_log (FC_MEM, "using private mapping for shared space");
gupcr_mem_check (memaddr, size, MYTHREAD);
return memaddr;
} | [
"char",
"*",
"gupcr_mem_private",
"(",
"size_t",
"size",
")",
"{",
"char",
"*",
"memaddr",
";",
"memaddr",
"=",
"mmap",
"(",
"NULL",
",",
"size",
",",
"PROT_READ",
"|",
"PROT_WRITE",
",",
"MAP_PRIVATE",
"|",
"MAP_ANONYMOUS",
",",
"-1",
",",
"OFFSET_ZERO",
")",
";",
"if",
"(",
"!",
"memaddr",
"||",
"memaddr",
"==",
"MAP_ERROR",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
",",
"(",
"long",
"unsigned",
")",
"size",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"gupcr_log",
"(",
"FC_MEM",
",",
"\"",
"\"",
")",
";",
"gupcr_mem_check",
"(",
"memaddr",
",",
"size",
",",
"MYTHREAD",
")",
";",
"return",
"memaddr",
";",
"}"
] | Allocate memory for a thread's shared space. | [
"Allocate",
"memory",
"for",
"a",
"thread",
"'",
"s",
"shared",
"space",
"."
] | [] | [
{
"param": "size",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
7d0fdc13cc0bed2fdfb0b41f26d3e2352e0484af | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_node.c | [
"Apache-2.0"
] | C | gupcr_node_local_alloc | char | char *
gupcr_node_local_alloc (size_t size)
{
/* Allocate zero initialized space for node local memory map. */
gupcr_node_map = calloc (THREADS, sizeof (char *));
if (!gupcr_node_map)
gupcr_fatal_error ("cannot allocate space for node local memory map");
#if GUPCR_NODE_LOCAL_MEM
/* Node Local Memory can be disabled by env variable. */
if (gupcr_is_node_local_memory_enabled ())
{
int i;
/* Create mapping for this thread. */
gupcr_node_map[MYTHREAD] = gupcr_mem_local_map (MYTHREAD, size);
/* Verify that we can access memory. */
gupcr_mem_check (gupcr_node_map[MYTHREAD], size, MYTHREAD);
/* Wait for all other threads to complete the same. */
gupcr_runtime_barrier ();
/* Map shared memory of other threads on the same node. */
{
int nid = gupcr_get_rank_nid (MYTHREAD);
for (i = 0; i < THREADS; i++)
{
if (i != MYTHREAD && nid == gupcr_get_rank_nid (i))
{
gupcr_node_map[i] = gupcr_mem_local_map (i, size);
}
}
}
/* Make sure everybody completed their mappings. */
gupcr_runtime_barrier ();
/* At this point it is safe to cleanup. */
gupcr_mem_local_unlink ();
}
else
{
/* The node local shared memory optimization has been
disabled (via an environment variable).
Create and map only the shared memory contribution of this node. */
gupcr_node_map[MYTHREAD] = gupcr_mem_private (size);
}
#else
/* The node local shared memory optimization has been
disabled (via a configuration option).
Create and map only the shared memory contribution of this node. */
gupcr_node_map[MYTHREAD] = gupcr_mem_private (size);
#endif /* GUPCR_NODE_LOCAL_MEM */
return gupcr_node_map[MYTHREAD];
} | /**
* Shared space allocation and mapping.
*
* Allocate and map each thread's node local shared space.
* Learn and map the shared space of other threads that reside on
* the same node.
*
* @in size Size of the shared space.
* @retval Address of the shared space.
*/ | Shared space allocation and mapping.
Allocate and map each thread's node local shared space.
Learn and map the shared space of other threads that reside on
the same node.
@in size Size of the shared space.
@retval Address of the shared space. | [
"Shared",
"space",
"allocation",
"and",
"mapping",
".",
"Allocate",
"and",
"map",
"each",
"thread",
"'",
"s",
"node",
"local",
"shared",
"space",
".",
"Learn",
"and",
"map",
"the",
"shared",
"space",
"of",
"other",
"threads",
"that",
"reside",
"on",
"the",
"same",
"node",
".",
"@in",
"size",
"Size",
"of",
"the",
"shared",
"space",
".",
"@retval",
"Address",
"of",
"the",
"shared",
"space",
"."
] | char *
gupcr_node_local_alloc (size_t size)
{
gupcr_node_map = calloc (THREADS, sizeof (char *));
if (!gupcr_node_map)
gupcr_fatal_error ("cannot allocate space for node local memory map");
#if GUPCR_NODE_LOCAL_MEM
if (gupcr_is_node_local_memory_enabled ())
{
int i;
gupcr_node_map[MYTHREAD] = gupcr_mem_local_map (MYTHREAD, size);
gupcr_mem_check (gupcr_node_map[MYTHREAD], size, MYTHREAD);
gupcr_runtime_barrier ();
{
int nid = gupcr_get_rank_nid (MYTHREAD);
for (i = 0; i < THREADS; i++)
{
if (i != MYTHREAD && nid == gupcr_get_rank_nid (i))
{
gupcr_node_map[i] = gupcr_mem_local_map (i, size);
}
}
}
gupcr_runtime_barrier ();
gupcr_mem_local_unlink ();
}
else
{
gupcr_node_map[MYTHREAD] = gupcr_mem_private (size);
}
#else
gupcr_node_map[MYTHREAD] = gupcr_mem_private (size);
#endif
return gupcr_node_map[MYTHREAD];
} | [
"char",
"*",
"gupcr_node_local_alloc",
"(",
"size_t",
"size",
")",
"{",
"gupcr_node_map",
"=",
"calloc",
"(",
"THREADS",
",",
"sizeof",
"(",
"char",
"*",
")",
")",
";",
"if",
"(",
"!",
"gupcr_node_map",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"#if",
"GUPCR_NODE_LOCAL_MEM",
"\n",
"if",
"(",
"gupcr_is_node_local_memory_enabled",
"(",
")",
")",
"{",
"int",
"i",
";",
"gupcr_node_map",
"[",
"MYTHREAD",
"]",
"=",
"gupcr_mem_local_map",
"(",
"MYTHREAD",
",",
"size",
")",
";",
"gupcr_mem_check",
"(",
"gupcr_node_map",
"[",
"MYTHREAD",
"]",
",",
"size",
",",
"MYTHREAD",
")",
";",
"gupcr_runtime_barrier",
"(",
")",
";",
"{",
"int",
"nid",
"=",
"gupcr_get_rank_nid",
"(",
"MYTHREAD",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"THREADS",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"!=",
"MYTHREAD",
"&&",
"nid",
"==",
"gupcr_get_rank_nid",
"(",
"i",
")",
")",
"{",
"gupcr_node_map",
"[",
"i",
"]",
"=",
"gupcr_mem_local_map",
"(",
"i",
",",
"size",
")",
";",
"}",
"}",
"}",
"gupcr_runtime_barrier",
"(",
")",
";",
"gupcr_mem_local_unlink",
"(",
")",
";",
"}",
"else",
"{",
"gupcr_node_map",
"[",
"MYTHREAD",
"]",
"=",
"gupcr_mem_private",
"(",
"size",
")",
";",
"}",
"#else",
"gupcr_node_map",
"[",
"MYTHREAD",
"]",
"=",
"gupcr_mem_private",
"(",
"size",
")",
";",
"#endif",
"return",
"gupcr_node_map",
"[",
"MYTHREAD",
"]",
";",
"}"
] | Shared space allocation and mapping. | [
"Shared",
"space",
"allocation",
"and",
"mapping",
"."
] | [
"/* Allocate zero initialized space for node local memory map. */",
"/* Node Local Memory can be disabled by env variable. */",
"/* Create mapping for this thread. */",
"/* Verify that we can access memory. */",
"/* Wait for all other threads to complete the same. */",
"/* Map shared memory of other threads on the same node. */",
"/* Make sure everybody completed their mappings. */",
"/* At this point it is safe to cleanup. */",
"/* The node local shared memory optimization has been\n disabled (via an environment variable).\n\t Create and map only the shared memory contribution of this node. */",
"/* The node local shared memory optimization has been\n disabled (via a configuration option).\n Create and map only the shared memory contribution of this node. */",
"/* GUPCR_NODE_LOCAL_MEM */"
] | [
{
"param": "size",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "size",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3d06efc4eef6311f7ded546a2e2c97a0b7661717 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_addr.c | [
"Apache-2.0"
] | C | upc_threadof | size_t | size_t
upc_threadof (upc_shared_ptr_t p)
{
if ((int) GUPCR_PTS_THREAD (p) >= THREADS)
gupcr_fatal_error ("thread number %d in shared address is out of range",
(int) GUPCR_PTS_THREAD (p));
return (size_t) GUPCR_PTS_THREAD (p);
} | /**
* Return the thread of a pointer-to-shared value.
*
* The upc_threadof function returns the index of the thread
* that has affinity to the shared object pointed to by the argument.
* @param [in] p Pointer-to-shared argument
* @retval Thread ID of the argument
*/ | Return the thread of a pointer-to-shared value.
The upc_threadof function returns the index of the thread
that has affinity to the shared object pointed to by the argument.
@param [in] p Pointer-to-shared argument
@retval Thread ID of the argument | [
"Return",
"the",
"thread",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
".",
"The",
"upc_threadof",
"function",
"returns",
"the",
"index",
"of",
"the",
"thread",
"that",
"has",
"affinity",
"to",
"the",
"shared",
"object",
"pointed",
"to",
"by",
"the",
"argument",
".",
"@param",
"[",
"in",
"]",
"p",
"Pointer",
"-",
"to",
"-",
"shared",
"argument",
"@retval",
"Thread",
"ID",
"of",
"the",
"argument"
] | size_t
upc_threadof (upc_shared_ptr_t p)
{
if ((int) GUPCR_PTS_THREAD (p) >= THREADS)
gupcr_fatal_error ("thread number %d in shared address is out of range",
(int) GUPCR_PTS_THREAD (p));
return (size_t) GUPCR_PTS_THREAD (p);
} | [
"size_t",
"upc_threadof",
"(",
"upc_shared_ptr_t",
"p",
")",
"{",
"if",
"(",
"(",
"int",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
">=",
"THREADS",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
",",
"(",
"int",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
")",
";",
"return",
"(",
"size_t",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
";",
"}"
] | Return the thread of a pointer-to-shared value. | [
"Return",
"the",
"thread",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
"."
] | [] | [
{
"param": "p",
"type": "upc_shared_ptr_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "upc_shared_ptr_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3d06efc4eef6311f7ded546a2e2c97a0b7661717 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_addr.c | [
"Apache-2.0"
] | C | upc_phaseof | size_t | size_t
upc_phaseof (upc_shared_ptr_t p)
{
if ((int) GUPCR_PTS_THREAD (p) >= THREADS)
gupcr_fatal_error ("thread number %d in shared address is out of range",
(int) GUPCR_PTS_THREAD (p));
return (size_t) GUPCR_PTS_PHASE (p);
} | /**
* Return the phase of a pointer-to-shared value.
*
* The upc_phaseof function returns the phase component of the
* pointer-to-shared argument.
* @param [in] p Pointer-to-shared argument
* @retval Phase of the argument
*/ | Return the phase of a pointer-to-shared value.
The upc_phaseof function returns the phase component of the
pointer-to-shared argument.
@param [in] p Pointer-to-shared argument
@retval Phase of the argument | [
"Return",
"the",
"phase",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
".",
"The",
"upc_phaseof",
"function",
"returns",
"the",
"phase",
"component",
"of",
"the",
"pointer",
"-",
"to",
"-",
"shared",
"argument",
".",
"@param",
"[",
"in",
"]",
"p",
"Pointer",
"-",
"to",
"-",
"shared",
"argument",
"@retval",
"Phase",
"of",
"the",
"argument"
] | size_t
upc_phaseof (upc_shared_ptr_t p)
{
if ((int) GUPCR_PTS_THREAD (p) >= THREADS)
gupcr_fatal_error ("thread number %d in shared address is out of range",
(int) GUPCR_PTS_THREAD (p));
return (size_t) GUPCR_PTS_PHASE (p);
} | [
"size_t",
"upc_phaseof",
"(",
"upc_shared_ptr_t",
"p",
")",
"{",
"if",
"(",
"(",
"int",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
">=",
"THREADS",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
",",
"(",
"int",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
")",
";",
"return",
"(",
"size_t",
")",
"GUPCR_PTS_PHASE",
"(",
"p",
")",
";",
"}"
] | Return the phase of a pointer-to-shared value. | [
"Return",
"the",
"phase",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
"."
] | [] | [
{
"param": "p",
"type": "upc_shared_ptr_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "upc_shared_ptr_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3d06efc4eef6311f7ded546a2e2c97a0b7661717 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_addr.c | [
"Apache-2.0"
] | C | upc_resetphase | upc_shared_ptr_t | upc_shared_ptr_t
upc_resetphase (upc_shared_ptr_t p)
{
upc_shared_ptr_t result;
result = p;
GUPCR_PTS_SET_PHASE (result, 0);
return result;
} | /**
* Reset the phase field of a pointer-to-shared value.
*
* The upc_resetphase function returns a pointer-to-shared value which
* is identical to its input except that it has zero phase.
* @param [in] p Pointer-to-shared argument
* @retval Pointer-to-shared with zero phase
*/ | Reset the phase field of a pointer-to-shared value.
The upc_resetphase function returns a pointer-to-shared value which
is identical to its input except that it has zero phase.
@param [in] p Pointer-to-shared argument
@retval Pointer-to-shared with zero phase | [
"Reset",
"the",
"phase",
"field",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
".",
"The",
"upc_resetphase",
"function",
"returns",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
"which",
"is",
"identical",
"to",
"its",
"input",
"except",
"that",
"it",
"has",
"zero",
"phase",
".",
"@param",
"[",
"in",
"]",
"p",
"Pointer",
"-",
"to",
"-",
"shared",
"argument",
"@retval",
"Pointer",
"-",
"to",
"-",
"shared",
"with",
"zero",
"phase"
] | upc_shared_ptr_t
upc_resetphase (upc_shared_ptr_t p)
{
upc_shared_ptr_t result;
result = p;
GUPCR_PTS_SET_PHASE (result, 0);
return result;
} | [
"upc_shared_ptr_t",
"upc_resetphase",
"(",
"upc_shared_ptr_t",
"p",
")",
"{",
"upc_shared_ptr_t",
"result",
";",
"result",
"=",
"p",
";",
"GUPCR_PTS_SET_PHASE",
"(",
"result",
",",
"0",
")",
";",
"return",
"result",
";",
"}"
] | Reset the phase field of a pointer-to-shared value. | [
"Reset",
"the",
"phase",
"field",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
"."
] | [] | [
{
"param": "p",
"type": "upc_shared_ptr_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "upc_shared_ptr_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3d06efc4eef6311f7ded546a2e2c97a0b7661717 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_addr.c | [
"Apache-2.0"
] | C | upc_addrfield | size_t | size_t
upc_addrfield (upc_shared_ptr_t p)
{
if ((int) GUPCR_PTS_THREAD (p) >= THREADS)
gupcr_fatal_error ("thread number %d in shared address is out of range",
(int) GUPCR_PTS_THREAD (p));
return (size_t) GUPCR_PTS_VADDR (p);
} | /**
* Return the address field of a pointer-to-shared value.
*
* The upc_addrfield function returns an implementation-defined
* value reflecting the 'local address' of the object pointed to
* by the pointer-to-shared argument.
* @param [in] p Pointer-to-shared argument
* @retval Address field of the argument
*/ | Return the address field of a pointer-to-shared value.
The upc_addrfield function returns an implementation-defined
value reflecting the 'local address' of the object pointed to
by the pointer-to-shared argument.
@param [in] p Pointer-to-shared argument
@retval Address field of the argument | [
"Return",
"the",
"address",
"field",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
".",
"The",
"upc_addrfield",
"function",
"returns",
"an",
"implementation",
"-",
"defined",
"value",
"reflecting",
"the",
"'",
"local",
"address",
"'",
"of",
"the",
"object",
"pointed",
"to",
"by",
"the",
"pointer",
"-",
"to",
"-",
"shared",
"argument",
".",
"@param",
"[",
"in",
"]",
"p",
"Pointer",
"-",
"to",
"-",
"shared",
"argument",
"@retval",
"Address",
"field",
"of",
"the",
"argument"
] | size_t
upc_addrfield (upc_shared_ptr_t p)
{
if ((int) GUPCR_PTS_THREAD (p) >= THREADS)
gupcr_fatal_error ("thread number %d in shared address is out of range",
(int) GUPCR_PTS_THREAD (p));
return (size_t) GUPCR_PTS_VADDR (p);
} | [
"size_t",
"upc_addrfield",
"(",
"upc_shared_ptr_t",
"p",
")",
"{",
"if",
"(",
"(",
"int",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
">=",
"THREADS",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
",",
"(",
"int",
")",
"GUPCR_PTS_THREAD",
"(",
"p",
")",
")",
";",
"return",
"(",
"size_t",
")",
"GUPCR_PTS_VADDR",
"(",
"p",
")",
";",
"}"
] | Return the address field of a pointer-to-shared value. | [
"Return",
"the",
"address",
"field",
"of",
"a",
"pointer",
"-",
"to",
"-",
"shared",
"value",
"."
] | [] | [
{
"param": "p",
"type": "upc_shared_ptr_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "p",
"type": "upc_shared_ptr_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3d06efc4eef6311f7ded546a2e2c97a0b7661717 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_addr.c | [
"Apache-2.0"
] | C | upc_affinitysize | size_t | size_t
upc_affinitysize (size_t totalsize, size_t nbytes, size_t threadid)
{
size_t result;
if (nbytes == 0 || totalsize == 0 || nbytes >= totalsize)
result = (size_t) (threadid == 0 ? totalsize : 0);
else
{
size_t const nblocks = (totalsize / nbytes);
size_t const cutoff = (nblocks % THREADS);
if (threadid < cutoff)
result = (size_t) ((nblocks + THREADS - 1) / THREADS) * nbytes;
else if (threadid > cutoff)
result = (size_t) (nblocks / THREADS) * nbytes;
else
result = (size_t) ((nblocks / THREADS) * nbytes)
+ totalsize - nblocks * nbytes;
}
return result;
} | /**
* Return the size of the local portion of the shared data
* with a layout described by the input parameters.
*
* A convenience function which calculates the exact size
* of the local portion of the data in a shared object with affinity to
* the thread identified by the 'threadid' parameter.
* @param [in] totalsize Size of the shared data
* @param [in] nbytes Size of the block
* @param [in] threadid Requested thread number
* @retval Size of the shared space described by the function arguments
*/ | Return the size of the local portion of the shared data
with a layout described by the input parameters.
A convenience function which calculates the exact size
of the local portion of the data in a shared object with affinity to
the thread identified by the 'threadid' parameter.
@param [in] totalsize Size of the shared data
@param [in] nbytes Size of the block
@param [in] threadid Requested thread number
@retval Size of the shared space described by the function arguments | [
"Return",
"the",
"size",
"of",
"the",
"local",
"portion",
"of",
"the",
"shared",
"data",
"with",
"a",
"layout",
"described",
"by",
"the",
"input",
"parameters",
".",
"A",
"convenience",
"function",
"which",
"calculates",
"the",
"exact",
"size",
"of",
"the",
"local",
"portion",
"of",
"the",
"data",
"in",
"a",
"shared",
"object",
"with",
"affinity",
"to",
"the",
"thread",
"identified",
"by",
"the",
"'",
"threadid",
"'",
"parameter",
".",
"@param",
"[",
"in",
"]",
"totalsize",
"Size",
"of",
"the",
"shared",
"data",
"@param",
"[",
"in",
"]",
"nbytes",
"Size",
"of",
"the",
"block",
"@param",
"[",
"in",
"]",
"threadid",
"Requested",
"thread",
"number",
"@retval",
"Size",
"of",
"the",
"shared",
"space",
"described",
"by",
"the",
"function",
"arguments"
] | size_t
upc_affinitysize (size_t totalsize, size_t nbytes, size_t threadid)
{
size_t result;
if (nbytes == 0 || totalsize == 0 || nbytes >= totalsize)
result = (size_t) (threadid == 0 ? totalsize : 0);
else
{
size_t const nblocks = (totalsize / nbytes);
size_t const cutoff = (nblocks % THREADS);
if (threadid < cutoff)
result = (size_t) ((nblocks + THREADS - 1) / THREADS) * nbytes;
else if (threadid > cutoff)
result = (size_t) (nblocks / THREADS) * nbytes;
else
result = (size_t) ((nblocks / THREADS) * nbytes)
+ totalsize - nblocks * nbytes;
}
return result;
} | [
"size_t",
"upc_affinitysize",
"(",
"size_t",
"totalsize",
",",
"size_t",
"nbytes",
",",
"size_t",
"threadid",
")",
"{",
"size_t",
"result",
";",
"if",
"(",
"nbytes",
"==",
"0",
"||",
"totalsize",
"==",
"0",
"||",
"nbytes",
">=",
"totalsize",
")",
"result",
"=",
"(",
"size_t",
")",
"(",
"threadid",
"==",
"0",
"?",
"totalsize",
":",
"0",
")",
";",
"else",
"{",
"size_t",
"const",
"nblocks",
"=",
"(",
"totalsize",
"/",
"nbytes",
")",
";",
"size_t",
"const",
"cutoff",
"=",
"(",
"nblocks",
"%",
"THREADS",
")",
";",
"if",
"(",
"threadid",
"<",
"cutoff",
")",
"result",
"=",
"(",
"size_t",
")",
"(",
"(",
"nblocks",
"+",
"THREADS",
"-",
"1",
")",
"/",
"THREADS",
")",
"*",
"nbytes",
";",
"else",
"if",
"(",
"threadid",
">",
"cutoff",
")",
"result",
"=",
"(",
"size_t",
")",
"(",
"nblocks",
"/",
"THREADS",
")",
"*",
"nbytes",
";",
"else",
"result",
"=",
"(",
"size_t",
")",
"(",
"(",
"nblocks",
"/",
"THREADS",
")",
"*",
"nbytes",
")",
"+",
"totalsize",
"-",
"nblocks",
"*",
"nbytes",
";",
"}",
"return",
"result",
";",
"}"
] | Return the size of the local portion of the shared data
with a layout described by the input parameters. | [
"Return",
"the",
"size",
"of",
"the",
"local",
"portion",
"of",
"the",
"shared",
"data",
"with",
"a",
"layout",
"described",
"by",
"the",
"input",
"parameters",
"."
] | [] | [
{
"param": "totalsize",
"type": "size_t"
},
{
"param": "nbytes",
"type": "size_t"
},
{
"param": "threadid",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "totalsize",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "threadid",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5a6cb0ee9233a863452eaf40539c6f11a9084c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_broadcast.c | [
"Apache-2.0"
] | C | gupcr_broadcast_get | void | void
gupcr_broadcast_get (void *value, size_t nbytes)
{
GUPCR_OMP_CHECK();
if (!MYTHREAD)
gupcr_fatal_error ("called from thread 0");
if (nbytes > GUPCR_MAX_BROADCAST_SIZE)
gupcr_fatal_error ("size of broadcast message (%ld) is greater then "
"the maximum allowed (%d)",
(long int) nbytes, GUPCR_MAX_BROADCAST_SIZE);
/* Wait to receive the broadcast message. */
gupcr_bcast_recv (value, nbytes);
} | /**
* Receive the broadcast value.
*
* A thread signals to its parent (by writing to its parent's UP PTE)
* that it is ready to receive a broadcast value, and then waits on
* its down LE counting event until the message arrives.
* @param [in] value Pointer to received value
* @param [in] nbytes Number of bytes to receive
*/ | Receive the broadcast value.
A thread signals to its parent (by writing to its parent's UP PTE)
that it is ready to receive a broadcast value, and then waits on
its down LE counting event until the message arrives.
@param [in] value Pointer to received value
@param [in] nbytes Number of bytes to receive | [
"Receive",
"the",
"broadcast",
"value",
".",
"A",
"thread",
"signals",
"to",
"its",
"parent",
"(",
"by",
"writing",
"to",
"its",
"parent",
"'",
"s",
"UP",
"PTE",
")",
"that",
"it",
"is",
"ready",
"to",
"receive",
"a",
"broadcast",
"value",
"and",
"then",
"waits",
"on",
"its",
"down",
"LE",
"counting",
"event",
"until",
"the",
"message",
"arrives",
".",
"@param",
"[",
"in",
"]",
"value",
"Pointer",
"to",
"received",
"value",
"@param",
"[",
"in",
"]",
"nbytes",
"Number",
"of",
"bytes",
"to",
"receive"
] | void
gupcr_broadcast_get (void *value, size_t nbytes)
{
GUPCR_OMP_CHECK();
if (!MYTHREAD)
gupcr_fatal_error ("called from thread 0");
if (nbytes > GUPCR_MAX_BROADCAST_SIZE)
gupcr_fatal_error ("size of broadcast message (%ld) is greater then "
"the maximum allowed (%d)",
(long int) nbytes, GUPCR_MAX_BROADCAST_SIZE);
gupcr_bcast_recv (value, nbytes);
} | [
"void",
"gupcr_broadcast_get",
"(",
"void",
"*",
"value",
",",
"size_t",
"nbytes",
")",
"{",
"GUPCR_OMP_CHECK",
"(",
")",
";",
"if",
"(",
"!",
"MYTHREAD",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"nbytes",
">",
"GUPCR_MAX_BROADCAST_SIZE",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"(",
"long",
"int",
")",
"nbytes",
",",
"GUPCR_MAX_BROADCAST_SIZE",
")",
";",
"gupcr_bcast_recv",
"(",
"value",
",",
"nbytes",
")",
";",
"}"
] | Receive the broadcast value. | [
"Receive",
"the",
"broadcast",
"value",
"."
] | [
"/* Wait to receive the broadcast message. */"
] | [
{
"param": "value",
"type": "void"
},
{
"param": "nbytes",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "value",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5a6cb0ee9233a863452eaf40539c6f11a9084c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_broadcast.c | [
"Apache-2.0"
] | C | gupcr_broadcast_put | void | void
gupcr_broadcast_put (void *value, size_t nbytes)
{
GUPCR_OMP_CHECK();
if (THREADS == 1)
return;
if (MYTHREAD)
gupcr_fatal_error ("called from thread other then 0");
if (nbytes > GUPCR_MAX_BROADCAST_SIZE)
gupcr_fatal_error ("size of broadcast message (%ld) is greater then "
"maximum allowed (%d)",
(long int) nbytes, GUPCR_MAX_BROADCAST_SIZE);
/* Send the broadcast message to the children of the root thread. */
gupcr_bcast_send (value, nbytes);
} | /**
* Send the broadcast value. This function must be called
* only by thread 0 (the root thread). The broadcast value
* is pushed down the tree by first sending the value
* to the children of the root thread.
*
* @param [in] value Pointer to send value
* @param [in] nbytes Number of bytes to send
*/ | Send the broadcast value. This function must be called
only by thread 0 (the root thread). The broadcast value
is pushed down the tree by first sending the value
to the children of the root thread.
@param [in] value Pointer to send value
@param [in] nbytes Number of bytes to send | [
"Send",
"the",
"broadcast",
"value",
".",
"This",
"function",
"must",
"be",
"called",
"only",
"by",
"thread",
"0",
"(",
"the",
"root",
"thread",
")",
".",
"The",
"broadcast",
"value",
"is",
"pushed",
"down",
"the",
"tree",
"by",
"first",
"sending",
"the",
"value",
"to",
"the",
"children",
"of",
"the",
"root",
"thread",
".",
"@param",
"[",
"in",
"]",
"value",
"Pointer",
"to",
"send",
"value",
"@param",
"[",
"in",
"]",
"nbytes",
"Number",
"of",
"bytes",
"to",
"send"
] | void
gupcr_broadcast_put (void *value, size_t nbytes)
{
GUPCR_OMP_CHECK();
if (THREADS == 1)
return;
if (MYTHREAD)
gupcr_fatal_error ("called from thread other then 0");
if (nbytes > GUPCR_MAX_BROADCAST_SIZE)
gupcr_fatal_error ("size of broadcast message (%ld) is greater then "
"maximum allowed (%d)",
(long int) nbytes, GUPCR_MAX_BROADCAST_SIZE);
gupcr_bcast_send (value, nbytes);
} | [
"void",
"gupcr_broadcast_put",
"(",
"void",
"*",
"value",
",",
"size_t",
"nbytes",
")",
"{",
"GUPCR_OMP_CHECK",
"(",
")",
";",
"if",
"(",
"THREADS",
"==",
"1",
")",
"return",
";",
"if",
"(",
"MYTHREAD",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"nbytes",
">",
"GUPCR_MAX_BROADCAST_SIZE",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"(",
"long",
"int",
")",
"nbytes",
",",
"GUPCR_MAX_BROADCAST_SIZE",
")",
";",
"gupcr_bcast_send",
"(",
"value",
",",
"nbytes",
")",
";",
"}"
] | Send the broadcast value. | [
"Send",
"the",
"broadcast",
"value",
"."
] | [
"/* Send the broadcast message to the children of the root thread. */"
] | [
{
"param": "value",
"type": "void"
},
{
"param": "nbytes",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "value",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f5a6cb0ee9233a863452eaf40539c6f11a9084c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_broadcast.c | [
"Apache-2.0"
] | C | gupcr_broadcast_init | void | void
gupcr_broadcast_init (void)
{
gupcr_log (FC_BROADCAST, "broadcast init called");
} | /**
* Initialize broadcast resources.
* @ingroup INIT
*/ | Initialize broadcast resources.
@ingroup INIT | [
"Initialize",
"broadcast",
"resources",
".",
"@ingroup",
"INIT"
] | void
gupcr_broadcast_init (void)
{
gupcr_log (FC_BROADCAST, "broadcast init called");
} | [
"void",
"gupcr_broadcast_init",
"(",
"void",
")",
"{",
"gupcr_log",
"(",
"FC_BROADCAST",
",",
"\"",
"\"",
")",
";",
"}"
] | Initialize broadcast resources. | [
"Initialize",
"broadcast",
"resources",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
f5a6cb0ee9233a863452eaf40539c6f11a9084c5 | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_broadcast.c | [
"Apache-2.0"
] | C | gupcr_broadcast_fini | void | void
gupcr_broadcast_fini (void)
{
gupcr_log (FC_BROADCAST, "broadcast fini called");
} | /**
* Release broadcast resources.
* @ingroup INIT
*/ | Release broadcast resources.
@ingroup INIT | [
"Release",
"broadcast",
"resources",
".",
"@ingroup",
"INIT"
] | void
gupcr_broadcast_fini (void)
{
gupcr_log (FC_BROADCAST, "broadcast fini called");
} | [
"void",
"gupcr_broadcast_fini",
"(",
"void",
")",
"{",
"gupcr_log",
"(",
"FC_BROADCAST",
",",
"\"",
"\"",
")",
";",
"}"
] | Release broadcast resources. | [
"Release",
"broadcast",
"resources",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_tree_setup | void | void
gupcr_coll_tree_setup (size_t newroot, size_t start, int nthreads)
{
/* Convert from/to 0-(THREADS-1) to start-(nthreads-1) range. */
#define NEWID(id,first) ((id - first + THREADS) % THREADS)
#define OLDID(nid,first) ((nid + first) % THREADS)
/* Remap into the new root (from root 0 to "root"). */
#define NEWIDROOT(id,top,cnt) ((cnt + id - top) % cnt)
#define OLDIDROOT(nid,top,cnt) ((nid + top) % cnt)
int i;
int ok_to_root = 0;
int myid;
int root = NEWID (newroot, start);
gupcr_debug (FC_COLL, "newroot: %lu, start: %lu nthreads: %d",
(long unsigned) newroot, (long unsigned) start, nthreads);
/* Check if root node is participating. If yes, use that for the
root, otherwise 0. */
if (root < nthreads)
ok_to_root = 1;
/* Get myid - first convert into the new range (0-nthreads),
then, if needed and possible, into the range where newroot becomes 0. */
myid = NEWID (MYTHREAD, start);
if (ok_to_root)
myid = NEWIDROOT (myid, root, nthreads);
/* Calculate the thread id's of the children and parent. */
gupcr_coll_child_cnt = 0;
for (i = 0; i < GUPCR_TREE_FANOUT; i++)
{
int child = (GUPCR_TREE_FANOUT * myid + i + 1);
if (child < nthreads)
{
++gupcr_coll_child_cnt;
if (ok_to_root)
child = OLDIDROOT (child, root, nthreads);
gupcr_coll_child[i] = OLDID (child, start);
}
}
if (myid)
{
gupcr_coll_parent_thread = (myid - 1) / GUPCR_TREE_FANOUT;
gupcr_coll_child_index =
myid - gupcr_coll_parent_thread * GUPCR_TREE_FANOUT - 1;
if (ok_to_root)
gupcr_coll_parent_thread =
OLDIDROOT (gupcr_coll_parent_thread, root, nthreads);
gupcr_coll_parent_thread = OLDID (gupcr_coll_parent_thread, start);
}
else
gupcr_coll_parent_thread = ROOT_PARENT;
} | /**
* Initialize collectives thread tree.
*
* A collectives tree starts from the "start" thread number and
* includes only "nthreads" (e.g. threads involved in
* the reduce process). The simplest case is when all the
* threads are involved in which case start=0 and
* nthreads=THREADS (e.g. used for broadcast).
*
* The collectives thread tree can be organized in a
* form where the "newroot" value identitifies
* the root thread (only if the "newroot" thread
* is participating in the operation).
* @param [in] newroot A hint for the tree root thread.
* @param [in] start Start thread for reduce
* @param [in] nthreads Number of threads participating
*
*/ | Initialize collectives thread tree.
A collectives tree starts from the "start" thread number and
includes only "nthreads" . The simplest case is when all the
threads are involved in which case start=0 and
nthreads=THREADS .
The collectives thread tree can be organized in a
form where the "newroot" value identitifies
the root thread (only if the "newroot" thread
is participating in the operation).
@param [in] newroot A hint for the tree root thread.
@param [in] start Start thread for reduce
@param [in] nthreads Number of threads participating | [
"Initialize",
"collectives",
"thread",
"tree",
".",
"A",
"collectives",
"tree",
"starts",
"from",
"the",
"\"",
"start",
"\"",
"thread",
"number",
"and",
"includes",
"only",
"\"",
"nthreads",
"\"",
".",
"The",
"simplest",
"case",
"is",
"when",
"all",
"the",
"threads",
"are",
"involved",
"in",
"which",
"case",
"start",
"=",
"0",
"and",
"nthreads",
"=",
"THREADS",
".",
"The",
"collectives",
"thread",
"tree",
"can",
"be",
"organized",
"in",
"a",
"form",
"where",
"the",
"\"",
"newroot",
"\"",
"value",
"identitifies",
"the",
"root",
"thread",
"(",
"only",
"if",
"the",
"\"",
"newroot",
"\"",
"thread",
"is",
"participating",
"in",
"the",
"operation",
")",
".",
"@param",
"[",
"in",
"]",
"newroot",
"A",
"hint",
"for",
"the",
"tree",
"root",
"thread",
".",
"@param",
"[",
"in",
"]",
"start",
"Start",
"thread",
"for",
"reduce",
"@param",
"[",
"in",
"]",
"nthreads",
"Number",
"of",
"threads",
"participating"
] | void
gupcr_coll_tree_setup (size_t newroot, size_t start, int nthreads)
{
#define NEWID(id,first) ((id - first + THREADS) % THREADS)
#define OLDID(nid,first) ((nid + first) % THREADS)
#define NEWIDROOT(id,top,cnt) ((cnt + id - top) % cnt)
#define OLDIDROOT(nid,top,cnt) ((nid + top) % cnt)
int i;
int ok_to_root = 0;
int myid;
int root = NEWID (newroot, start);
gupcr_debug (FC_COLL, "newroot: %lu, start: %lu nthreads: %d",
(long unsigned) newroot, (long unsigned) start, nthreads);
if (root < nthreads)
ok_to_root = 1;
myid = NEWID (MYTHREAD, start);
if (ok_to_root)
myid = NEWIDROOT (myid, root, nthreads);
gupcr_coll_child_cnt = 0;
for (i = 0; i < GUPCR_TREE_FANOUT; i++)
{
int child = (GUPCR_TREE_FANOUT * myid + i + 1);
if (child < nthreads)
{
++gupcr_coll_child_cnt;
if (ok_to_root)
child = OLDIDROOT (child, root, nthreads);
gupcr_coll_child[i] = OLDID (child, start);
}
}
if (myid)
{
gupcr_coll_parent_thread = (myid - 1) / GUPCR_TREE_FANOUT;
gupcr_coll_child_index =
myid - gupcr_coll_parent_thread * GUPCR_TREE_FANOUT - 1;
if (ok_to_root)
gupcr_coll_parent_thread =
OLDIDROOT (gupcr_coll_parent_thread, root, nthreads);
gupcr_coll_parent_thread = OLDID (gupcr_coll_parent_thread, start);
}
else
gupcr_coll_parent_thread = ROOT_PARENT;
} | [
"void",
"gupcr_coll_tree_setup",
"(",
"size_t",
"newroot",
",",
"size_t",
"start",
",",
"int",
"nthreads",
")",
"{",
"#define",
"NEWID",
"(",
"id",
",",
"first",
")",
" ((id - first + THREADS) % THREADS)",
"\n",
"#define",
"OLDID",
"(",
"nid",
",",
"first",
")",
" ((nid + first) % THREADS)",
"\n\n",
"#define",
"NEWIDROOT",
"(",
"id",
",",
"top",
",",
"cnt",
")",
" ((cnt + id - top) % cnt)",
"\n",
"#define",
"OLDIDROOT",
"(",
"nid",
",",
"top",
",",
"cnt",
")",
" ((nid + top) % cnt)",
"\n",
"int",
"i",
";",
"int",
"ok_to_root",
"=",
"0",
";",
"int",
"myid",
";",
"int",
"root",
"=",
"NEWID",
"(",
"newroot",
",",
"start",
")",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"(",
"long",
"unsigned",
")",
"newroot",
",",
"(",
"long",
"unsigned",
")",
"start",
",",
"nthreads",
")",
";",
"if",
"(",
"root",
"<",
"nthreads",
")",
"ok_to_root",
"=",
"1",
";",
"myid",
"=",
"NEWID",
"(",
"MYTHREAD",
",",
"start",
")",
";",
"if",
"(",
"ok_to_root",
")",
"myid",
"=",
"NEWIDROOT",
"(",
"myid",
",",
"root",
",",
"nthreads",
")",
";",
"gupcr_coll_child_cnt",
"=",
"0",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"GUPCR_TREE_FANOUT",
";",
"i",
"++",
")",
"{",
"int",
"child",
"=",
"(",
"GUPCR_TREE_FANOUT",
"*",
"myid",
"+",
"i",
"+",
"1",
")",
";",
"if",
"(",
"child",
"<",
"nthreads",
")",
"{",
"++",
"gupcr_coll_child_cnt",
";",
"if",
"(",
"ok_to_root",
")",
"child",
"=",
"OLDIDROOT",
"(",
"child",
",",
"root",
",",
"nthreads",
")",
";",
"gupcr_coll_child",
"[",
"i",
"]",
"=",
"OLDID",
"(",
"child",
",",
"start",
")",
";",
"}",
"}",
"if",
"(",
"myid",
")",
"{",
"gupcr_coll_parent_thread",
"=",
"(",
"myid",
"-",
"1",
")",
"/",
"GUPCR_TREE_FANOUT",
";",
"gupcr_coll_child_index",
"=",
"myid",
"-",
"gupcr_coll_parent_thread",
"*",
"GUPCR_TREE_FANOUT",
"-",
"1",
";",
"if",
"(",
"ok_to_root",
")",
"gupcr_coll_parent_thread",
"=",
"OLDIDROOT",
"(",
"gupcr_coll_parent_thread",
",",
"root",
",",
"nthreads",
")",
";",
"gupcr_coll_parent_thread",
"=",
"OLDID",
"(",
"gupcr_coll_parent_thread",
",",
"start",
")",
";",
"}",
"else",
"gupcr_coll_parent_thread",
"=",
"ROOT_PARENT",
";",
"}"
] | Initialize collectives thread tree. | [
"Initialize",
"collectives",
"thread",
"tree",
"."
] | [
"/* Convert from/to 0-(THREADS-1) to start-(nthreads-1) range. */",
"/* Remap into the new root (from root 0 to \"root\"). */",
"/* Check if root node is participating. If yes, use that for the\n root, otherwise 0. */",
"/* Get myid - first convert into the new range (0-nthreads),\n then, if needed and possible, into the range where newroot becomes 0. */",
"/* Calculate the thread id's of the children and parent. */"
] | [
{
"param": "newroot",
"type": "size_t"
},
{
"param": "start",
"type": "size_t"
},
{
"param": "nthreads",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "newroot",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "start",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nthreads",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_put | void | void
gupcr_coll_put (size_t dthread, size_t doffset, size_t soffset, size_t nbytes)
{
ptl_process_t rpid;
gupcr_debug (FC_COLL, "%d:0x%lx %lu:0x%lx %lu",
MYTHREAD, (long unsigned) soffset,
(long unsigned) dthread, (long unsigned) doffset,
(long unsigned) nbytes);
rpid.rank = dthread;
gupcr_portals_call (PtlPut,
(gupcr_coll_md, soffset, nbytes, PTL_ACK_REQ, rpid,
GUPCR_PTL_PTE_COLL, PTL_NO_MATCH_BITS, doffset,
PTL_NULL_USER_PTR, PTL_NULL_HDR_DATA));
} | /**
* Collective PUT operation
*
* @param [in] dthread Destination thread
* @param [in] doffset Destination offset in the shared space
* @param [in] soffset Source offset in the shared space
* @param [in] nbytes Number of bytes to copy
*/ | Collective PUT operation
@param [in] dthread Destination thread
@param [in] doffset Destination offset in the shared space
@param [in] soffset Source offset in the shared space
@param [in] nbytes Number of bytes to copy | [
"Collective",
"PUT",
"operation",
"@param",
"[",
"in",
"]",
"dthread",
"Destination",
"thread",
"@param",
"[",
"in",
"]",
"doffset",
"Destination",
"offset",
"in",
"the",
"shared",
"space",
"@param",
"[",
"in",
"]",
"soffset",
"Source",
"offset",
"in",
"the",
"shared",
"space",
"@param",
"[",
"in",
"]",
"nbytes",
"Number",
"of",
"bytes",
"to",
"copy"
] | void
gupcr_coll_put (size_t dthread, size_t doffset, size_t soffset, size_t nbytes)
{
ptl_process_t rpid;
gupcr_debug (FC_COLL, "%d:0x%lx %lu:0x%lx %lu",
MYTHREAD, (long unsigned) soffset,
(long unsigned) dthread, (long unsigned) doffset,
(long unsigned) nbytes);
rpid.rank = dthread;
gupcr_portals_call (PtlPut,
(gupcr_coll_md, soffset, nbytes, PTL_ACK_REQ, rpid,
GUPCR_PTL_PTE_COLL, PTL_NO_MATCH_BITS, doffset,
PTL_NULL_USER_PTR, PTL_NULL_HDR_DATA));
} | [
"void",
"gupcr_coll_put",
"(",
"size_t",
"dthread",
",",
"size_t",
"doffset",
",",
"size_t",
"soffset",
",",
"size_t",
"nbytes",
")",
"{",
"ptl_process_t",
"rpid",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"MYTHREAD",
",",
"(",
"long",
"unsigned",
")",
"soffset",
",",
"(",
"long",
"unsigned",
")",
"dthread",
",",
"(",
"long",
"unsigned",
")",
"doffset",
",",
"(",
"long",
"unsigned",
")",
"nbytes",
")",
";",
"rpid",
".",
"rank",
"=",
"dthread",
";",
"gupcr_portals_call",
"(",
"PtlPut",
",",
"(",
"gupcr_coll_md",
",",
"soffset",
",",
"nbytes",
",",
"PTL_ACK_REQ",
",",
"rpid",
",",
"GUPCR_PTL_PTE_COLL",
",",
"PTL_NO_MATCH_BITS",
",",
"doffset",
",",
"PTL_NULL_USER_PTR",
",",
"PTL_NULL_HDR_DATA",
")",
")",
";",
"}"
] | Collective PUT operation
@param [in] dthread Destination thread
@param [in] doffset Destination offset in the shared space
@param [in] soffset Source offset in the shared space
@param [in] nbytes Number of bytes to copy | [
"Collective",
"PUT",
"operation",
"@param",
"[",
"in",
"]",
"dthread",
"Destination",
"thread",
"@param",
"[",
"in",
"]",
"doffset",
"Destination",
"offset",
"in",
"the",
"shared",
"space",
"@param",
"[",
"in",
"]",
"soffset",
"Source",
"offset",
"in",
"the",
"shared",
"space",
"@param",
"[",
"in",
"]",
"nbytes",
"Number",
"of",
"bytes",
"to",
"copy"
] | [] | [
{
"param": "dthread",
"type": "size_t"
},
{
"param": "doffset",
"type": "size_t"
},
{
"param": "soffset",
"type": "size_t"
},
{
"param": "nbytes",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dthread",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "doffset",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "soffset",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_trigput | void | void
gupcr_coll_trigput (size_t dthread, size_t doffset, size_t soffset,
size_t nbytes, size_t cnt)
{
ptl_process_t rpid;
gupcr_debug (FC_COLL, "%d:0x%lx -> %lu:0x%lx %lu trig %lu",
MYTHREAD, (long unsigned) soffset,
(long unsigned) dthread, (long unsigned) doffset,
(long unsigned) nbytes, (long unsigned) cnt);
rpid.rank = dthread;
gupcr_portals_call (PtlTriggeredPut,
(gupcr_coll_md, soffset, nbytes, PTL_ACK_REQ, rpid,
GUPCR_PTL_PTE_COLL, PTL_NO_MATCH_BITS, doffset,
PTL_NULL_USER_PTR, PTL_NULL_HDR_DATA, gupcr_coll_le_ct,
gupcr_coll_signal_cnt + cnt));
} | /**
* Collective triggered PUT operation
*
* Schedule put operation once number of signals reaches
* the specified value.
*
* @param [in] dthread Destination thread
* @param [in] doffset Destination offset in the shared space
* @param [in] soffset Source offset in the shared space
* @param [in] nbytes Number of bytes to copy
* @param [in] cnt Trigger count
*/ | Collective triggered PUT operation
Schedule put operation once number of signals reaches
the specified value.
| [
"Collective",
"triggered",
"PUT",
"operation",
"Schedule",
"put",
"operation",
"once",
"number",
"of",
"signals",
"reaches",
"the",
"specified",
"value",
"."
] | void
gupcr_coll_trigput (size_t dthread, size_t doffset, size_t soffset,
size_t nbytes, size_t cnt)
{
ptl_process_t rpid;
gupcr_debug (FC_COLL, "%d:0x%lx -> %lu:0x%lx %lu trig %lu",
MYTHREAD, (long unsigned) soffset,
(long unsigned) dthread, (long unsigned) doffset,
(long unsigned) nbytes, (long unsigned) cnt);
rpid.rank = dthread;
gupcr_portals_call (PtlTriggeredPut,
(gupcr_coll_md, soffset, nbytes, PTL_ACK_REQ, rpid,
GUPCR_PTL_PTE_COLL, PTL_NO_MATCH_BITS, doffset,
PTL_NULL_USER_PTR, PTL_NULL_HDR_DATA, gupcr_coll_le_ct,
gupcr_coll_signal_cnt + cnt));
} | [
"void",
"gupcr_coll_trigput",
"(",
"size_t",
"dthread",
",",
"size_t",
"doffset",
",",
"size_t",
"soffset",
",",
"size_t",
"nbytes",
",",
"size_t",
"cnt",
")",
"{",
"ptl_process_t",
"rpid",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"MYTHREAD",
",",
"(",
"long",
"unsigned",
")",
"soffset",
",",
"(",
"long",
"unsigned",
")",
"dthread",
",",
"(",
"long",
"unsigned",
")",
"doffset",
",",
"(",
"long",
"unsigned",
")",
"nbytes",
",",
"(",
"long",
"unsigned",
")",
"cnt",
")",
";",
"rpid",
".",
"rank",
"=",
"dthread",
";",
"gupcr_portals_call",
"(",
"PtlTriggeredPut",
",",
"(",
"gupcr_coll_md",
",",
"soffset",
",",
"nbytes",
",",
"PTL_ACK_REQ",
",",
"rpid",
",",
"GUPCR_PTL_PTE_COLL",
",",
"PTL_NO_MATCH_BITS",
",",
"doffset",
",",
"PTL_NULL_USER_PTR",
",",
"PTL_NULL_HDR_DATA",
",",
"gupcr_coll_le_ct",
",",
"gupcr_coll_signal_cnt",
"+",
"cnt",
")",
")",
";",
"}"
] | Collective triggered PUT operation
Schedule put operation once number of signals reaches
the specified value. | [
"Collective",
"triggered",
"PUT",
"operation",
"Schedule",
"put",
"operation",
"once",
"number",
"of",
"signals",
"reaches",
"the",
"specified",
"value",
"."
] | [] | [
{
"param": "dthread",
"type": "size_t"
},
{
"param": "doffset",
"type": "size_t"
},
{
"param": "soffset",
"type": "size_t"
},
{
"param": "nbytes",
"type": "size_t"
},
{
"param": "cnt",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dthread",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "doffset",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "soffset",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cnt",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_trigput_atomic | void | void
gupcr_coll_trigput_atomic (size_t dthread, size_t doffset, size_t soffset,
size_t nbytes, ptl_op_t op,
ptl_datatype_t datatype, size_t cnt)
{
ptl_process_t rpid;
gupcr_debug (FC_COLL, "%d:0x%lx %lu:0x%lx %lu %s %s trig %lu",
MYTHREAD, (long unsigned) soffset,
(long unsigned) dthread, (long unsigned) doffset,
(long unsigned) nbytes,
gupcr_strptlop (op), gupcr_strptldatatype (datatype),
(long unsigned) cnt);
rpid.rank = dthread;
gupcr_portals_call (PtlTriggeredAtomic,
(gupcr_coll_md, soffset,
nbytes, PTL_ACK_REQ, rpid, GUPCR_PTL_PTE_COLL,
PTL_NO_MATCH_BITS, doffset, PTL_NULL_USER_PTR,
PTL_NULL_HDR_DATA, op, datatype, gupcr_coll_le_ct,
cnt));
} | /**
* Collective triggered atomic PUT operation.
*
* Schedule atomic put operation once number of signals reaches
* the specified value.
*
* @param [in] dthread Destination thread
* @param [in] doffset Destination offset in the shared space
* @param [in] soffset Source offset in the shared space
* @param [in] nbytes Number of bytes to copy
* @param [in] op Portals atomic operation
* @param [in] datatype Portals atomic data type
* @param [in] cnt Number of signals that triggers
*/ | Collective triggered atomic PUT operation.
Schedule atomic put operation once number of signals reaches
the specified value.
| [
"Collective",
"triggered",
"atomic",
"PUT",
"operation",
".",
"Schedule",
"atomic",
"put",
"operation",
"once",
"number",
"of",
"signals",
"reaches",
"the",
"specified",
"value",
"."
] | void
gupcr_coll_trigput_atomic (size_t dthread, size_t doffset, size_t soffset,
size_t nbytes, ptl_op_t op,
ptl_datatype_t datatype, size_t cnt)
{
ptl_process_t rpid;
gupcr_debug (FC_COLL, "%d:0x%lx %lu:0x%lx %lu %s %s trig %lu",
MYTHREAD, (long unsigned) soffset,
(long unsigned) dthread, (long unsigned) doffset,
(long unsigned) nbytes,
gupcr_strptlop (op), gupcr_strptldatatype (datatype),
(long unsigned) cnt);
rpid.rank = dthread;
gupcr_portals_call (PtlTriggeredAtomic,
(gupcr_coll_md, soffset,
nbytes, PTL_ACK_REQ, rpid, GUPCR_PTL_PTE_COLL,
PTL_NO_MATCH_BITS, doffset, PTL_NULL_USER_PTR,
PTL_NULL_HDR_DATA, op, datatype, gupcr_coll_le_ct,
cnt));
} | [
"void",
"gupcr_coll_trigput_atomic",
"(",
"size_t",
"dthread",
",",
"size_t",
"doffset",
",",
"size_t",
"soffset",
",",
"size_t",
"nbytes",
",",
"ptl_op_t",
"op",
",",
"ptl_datatype_t",
"datatype",
",",
"size_t",
"cnt",
")",
"{",
"ptl_process_t",
"rpid",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"MYTHREAD",
",",
"(",
"long",
"unsigned",
")",
"soffset",
",",
"(",
"long",
"unsigned",
")",
"dthread",
",",
"(",
"long",
"unsigned",
")",
"doffset",
",",
"(",
"long",
"unsigned",
")",
"nbytes",
",",
"gupcr_strptlop",
"(",
"op",
")",
",",
"gupcr_strptldatatype",
"(",
"datatype",
")",
",",
"(",
"long",
"unsigned",
")",
"cnt",
")",
";",
"rpid",
".",
"rank",
"=",
"dthread",
";",
"gupcr_portals_call",
"(",
"PtlTriggeredAtomic",
",",
"(",
"gupcr_coll_md",
",",
"soffset",
",",
"nbytes",
",",
"PTL_ACK_REQ",
",",
"rpid",
",",
"GUPCR_PTL_PTE_COLL",
",",
"PTL_NO_MATCH_BITS",
",",
"doffset",
",",
"PTL_NULL_USER_PTR",
",",
"PTL_NULL_HDR_DATA",
",",
"op",
",",
"datatype",
",",
"gupcr_coll_le_ct",
",",
"cnt",
")",
")",
";",
"}"
] | Collective triggered atomic PUT operation. | [
"Collective",
"triggered",
"atomic",
"PUT",
"operation",
"."
] | [] | [
{
"param": "dthread",
"type": "size_t"
},
{
"param": "doffset",
"type": "size_t"
},
{
"param": "soffset",
"type": "size_t"
},
{
"param": "nbytes",
"type": "size_t"
},
{
"param": "op",
"type": "ptl_op_t"
},
{
"param": "datatype",
"type": "ptl_datatype_t"
},
{
"param": "cnt",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "dthread",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "doffset",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "soffset",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbytes",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "op",
"type": "ptl_op_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "datatype",
"type": "ptl_datatype_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cnt",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_ack_wait | void | void
gupcr_coll_ack_wait (size_t cnt)
{
ptl_ct_event_t ct;
gupcr_debug (FC_COLL, "wait for %lu (%lu)",
(long unsigned) cnt,
(long unsigned) (gupcr_coll_ack_cnt + cnt));
gupcr_portals_call (PtlCTWait,
(gupcr_coll_md_ct, gupcr_coll_ack_cnt + cnt, &ct));
if (ct.failure)
{
gupcr_process_fail_events (gupcr_coll_md_eq);
gupcr_fatal_error ("received an error on collective MD");
}
gupcr_coll_ack_cnt += cnt;
} | /**
* Collectives wait for operation completion
* This function is used in cases where threads needs to wait
* for the completion of remote operations.
*
* @param [in] cnt Wait count
*/ | Collectives wait for operation completion
This function is used in cases where threads needs to wait
for the completion of remote operations.
@param [in] cnt Wait count | [
"Collectives",
"wait",
"for",
"operation",
"completion",
"This",
"function",
"is",
"used",
"in",
"cases",
"where",
"threads",
"needs",
"to",
"wait",
"for",
"the",
"completion",
"of",
"remote",
"operations",
".",
"@param",
"[",
"in",
"]",
"cnt",
"Wait",
"count"
] | void
gupcr_coll_ack_wait (size_t cnt)
{
ptl_ct_event_t ct;
gupcr_debug (FC_COLL, "wait for %lu (%lu)",
(long unsigned) cnt,
(long unsigned) (gupcr_coll_ack_cnt + cnt));
gupcr_portals_call (PtlCTWait,
(gupcr_coll_md_ct, gupcr_coll_ack_cnt + cnt, &ct));
if (ct.failure)
{
gupcr_process_fail_events (gupcr_coll_md_eq);
gupcr_fatal_error ("received an error on collective MD");
}
gupcr_coll_ack_cnt += cnt;
} | [
"void",
"gupcr_coll_ack_wait",
"(",
"size_t",
"cnt",
")",
"{",
"ptl_ct_event_t",
"ct",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"(",
"long",
"unsigned",
")",
"cnt",
",",
"(",
"long",
"unsigned",
")",
"(",
"gupcr_coll_ack_cnt",
"+",
"cnt",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlCTWait",
",",
"(",
"gupcr_coll_md_ct",
",",
"gupcr_coll_ack_cnt",
"+",
"cnt",
",",
"&",
"ct",
")",
")",
";",
"if",
"(",
"ct",
".",
"failure",
")",
"{",
"gupcr_process_fail_events",
"(",
"gupcr_coll_md_eq",
")",
";",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"}",
"gupcr_coll_ack_cnt",
"+=",
"cnt",
";",
"}"
] | Collectives wait for operation completion
This function is used in cases where threads needs to wait
for the completion of remote operations. | [
"Collectives",
"wait",
"for",
"operation",
"completion",
"This",
"function",
"is",
"used",
"in",
"cases",
"where",
"threads",
"needs",
"to",
"wait",
"for",
"the",
"completion",
"of",
"remote",
"operations",
"."
] | [] | [
{
"param": "cnt",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cnt",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_signal_wait | void | void
gupcr_coll_signal_wait (size_t cnt)
{
ptl_ct_event_t ct;
gupcr_debug (FC_COLL, "wait for %lu (%lu)",
(long unsigned) cnt,
(long unsigned) (gupcr_coll_signal_cnt + cnt));
gupcr_portals_call (PtlCTWait,
(gupcr_coll_le_ct, gupcr_coll_signal_cnt + cnt, &ct));
if (ct.failure)
{
gupcr_process_fail_events (gupcr_coll_le_eq);
gupcr_fatal_error ("received an error on collective LE");
}
gupcr_coll_signal_cnt += cnt;
} | /**
* Collectives wait for signaling events
* This function is used to wait for other threads to complete
* operations in the thread's shared space (e.g. children performing
* atomic ops in the parent's shared space).
*
* @param [in] cnt Wait count
*/ | Collectives wait for signaling events
This function is used to wait for other threads to complete
operations in the thread's shared space .
@param [in] cnt Wait count | [
"Collectives",
"wait",
"for",
"signaling",
"events",
"This",
"function",
"is",
"used",
"to",
"wait",
"for",
"other",
"threads",
"to",
"complete",
"operations",
"in",
"the",
"thread",
"'",
"s",
"shared",
"space",
".",
"@param",
"[",
"in",
"]",
"cnt",
"Wait",
"count"
] | void
gupcr_coll_signal_wait (size_t cnt)
{
ptl_ct_event_t ct;
gupcr_debug (FC_COLL, "wait for %lu (%lu)",
(long unsigned) cnt,
(long unsigned) (gupcr_coll_signal_cnt + cnt));
gupcr_portals_call (PtlCTWait,
(gupcr_coll_le_ct, gupcr_coll_signal_cnt + cnt, &ct));
if (ct.failure)
{
gupcr_process_fail_events (gupcr_coll_le_eq);
gupcr_fatal_error ("received an error on collective LE");
}
gupcr_coll_signal_cnt += cnt;
} | [
"void",
"gupcr_coll_signal_wait",
"(",
"size_t",
"cnt",
")",
"{",
"ptl_ct_event_t",
"ct",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"(",
"long",
"unsigned",
")",
"cnt",
",",
"(",
"long",
"unsigned",
")",
"(",
"gupcr_coll_signal_cnt",
"+",
"cnt",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlCTWait",
",",
"(",
"gupcr_coll_le_ct",
",",
"gupcr_coll_signal_cnt",
"+",
"cnt",
",",
"&",
"ct",
")",
")",
";",
"if",
"(",
"ct",
".",
"failure",
")",
"{",
"gupcr_process_fail_events",
"(",
"gupcr_coll_le_eq",
")",
";",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"}",
"gupcr_coll_signal_cnt",
"+=",
"cnt",
";",
"}"
] | Collectives wait for signaling events
This function is used to wait for other threads to complete
operations in the thread's shared space (e.g. | [
"Collectives",
"wait",
"for",
"signaling",
"events",
"This",
"function",
"is",
"used",
"to",
"wait",
"for",
"other",
"threads",
"to",
"complete",
"operations",
"in",
"the",
"thread",
"'",
"s",
"shared",
"space",
"(",
"e",
".",
"g",
"."
] | [] | [
{
"param": "cnt",
"type": "size_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cnt",
"type": "size_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_init | void | void
gupcr_coll_init (void)
{
ptl_md_t md;
ptl_pt_index_t pte;
ptl_le_t le;
gupcr_log (FC_COLL, "coll init called");
/* Allocate the Portals PTE that is used for collectives. */
gupcr_portals_call (PtlEQAlloc, (gupcr_ptl_ni, 1, &gupcr_coll_le_eq));
gupcr_portals_call (PtlPTAlloc, (gupcr_ptl_ni, 0,
gupcr_coll_le_eq, GUPCR_PTL_PTE_COLL,
&pte));
if (pte != GUPCR_PTL_PTE_COLL)
gupcr_fatal_error ("cannot allocate PTE GUPCR_PTL_PTE_COLL.");
gupcr_debug (FC_COLL, "Collectives PTE allocated: %d", GUPCR_PTL_PTE_COLL);
/* Allocate the Portals LE that is used for collectives. */
gupcr_portals_call (PtlCTAlloc, (gupcr_ptl_ni, &gupcr_coll_le_ct));
le.start = gupcr_gmem_base;
le.length = gupcr_gmem_size;
le.ct_handle = gupcr_coll_le_ct;
le.uid = PTL_UID_ANY;
le.options = PTL_LE_OP_PUT | PTL_LE_OP_GET | PTL_LE_EVENT_CT_COMM |
PTL_LE_EVENT_SUCCESS_DISABLE | PTL_LE_EVENT_LINK_DISABLE;
gupcr_portals_call (PtlLEAppend, (gupcr_ptl_ni, GUPCR_PTL_PTE_COLL, &le,
PTL_PRIORITY_LIST, NULL, &gupcr_coll_le));
gupcr_debug (FC_COLL, "Collectives LE created at 0x%lx size 0x%lx",
(long unsigned) gupcr_gmem_base,
(long unsigned) gupcr_gmem_size);
/* Setup the Portals MD for local source/destination copying.
We need to map only the shared memory space. */
gupcr_portals_call (PtlCTAlloc, (gupcr_ptl_ni, &gupcr_coll_md_ct));
gupcr_portals_call (PtlEQAlloc, (gupcr_ptl_ni, 1, &gupcr_coll_md_eq));
md.start = gupcr_gmem_base;
md.length = gupcr_gmem_size;
md.options = PTL_MD_EVENT_CT_ACK | PTL_MD_EVENT_CT_REPLY |
PTL_MD_EVENT_SUCCESS_DISABLE;
md.eq_handle = gupcr_coll_md_eq;
md.ct_handle = gupcr_coll_md_ct;
gupcr_portals_call (PtlMDBind, (gupcr_ptl_ni, &md, &gupcr_coll_md));
/* Reset the number of signals/acks. */
gupcr_coll_signal_cnt = 0;
gupcr_coll_ack_cnt = 0;
} | /**
* Initialize collectives resources.
* @ingroup INIT
*
* A thread's shared space is mapped via a Portals LE for other
* threads to write to, and an MD as a source for remote
* operations. In this way, the address filed of the shared pointer
* can be used as an offset into LE/MD.
*/ | Initialize collectives resources.
@ingroup INIT
A thread's shared space is mapped via a Portals LE for other
threads to write to, and an MD as a source for remote
operations. In this way, the address filed of the shared pointer
can be used as an offset into LE/MD. | [
"Initialize",
"collectives",
"resources",
".",
"@ingroup",
"INIT",
"A",
"thread",
"'",
"s",
"shared",
"space",
"is",
"mapped",
"via",
"a",
"Portals",
"LE",
"for",
"other",
"threads",
"to",
"write",
"to",
"and",
"an",
"MD",
"as",
"a",
"source",
"for",
"remote",
"operations",
".",
"In",
"this",
"way",
"the",
"address",
"filed",
"of",
"the",
"shared",
"pointer",
"can",
"be",
"used",
"as",
"an",
"offset",
"into",
"LE",
"/",
"MD",
"."
] | void
gupcr_coll_init (void)
{
ptl_md_t md;
ptl_pt_index_t pte;
ptl_le_t le;
gupcr_log (FC_COLL, "coll init called");
gupcr_portals_call (PtlEQAlloc, (gupcr_ptl_ni, 1, &gupcr_coll_le_eq));
gupcr_portals_call (PtlPTAlloc, (gupcr_ptl_ni, 0,
gupcr_coll_le_eq, GUPCR_PTL_PTE_COLL,
&pte));
if (pte != GUPCR_PTL_PTE_COLL)
gupcr_fatal_error ("cannot allocate PTE GUPCR_PTL_PTE_COLL.");
gupcr_debug (FC_COLL, "Collectives PTE allocated: %d", GUPCR_PTL_PTE_COLL);
gupcr_portals_call (PtlCTAlloc, (gupcr_ptl_ni, &gupcr_coll_le_ct));
le.start = gupcr_gmem_base;
le.length = gupcr_gmem_size;
le.ct_handle = gupcr_coll_le_ct;
le.uid = PTL_UID_ANY;
le.options = PTL_LE_OP_PUT | PTL_LE_OP_GET | PTL_LE_EVENT_CT_COMM |
PTL_LE_EVENT_SUCCESS_DISABLE | PTL_LE_EVENT_LINK_DISABLE;
gupcr_portals_call (PtlLEAppend, (gupcr_ptl_ni, GUPCR_PTL_PTE_COLL, &le,
PTL_PRIORITY_LIST, NULL, &gupcr_coll_le));
gupcr_debug (FC_COLL, "Collectives LE created at 0x%lx size 0x%lx",
(long unsigned) gupcr_gmem_base,
(long unsigned) gupcr_gmem_size);
gupcr_portals_call (PtlCTAlloc, (gupcr_ptl_ni, &gupcr_coll_md_ct));
gupcr_portals_call (PtlEQAlloc, (gupcr_ptl_ni, 1, &gupcr_coll_md_eq));
md.start = gupcr_gmem_base;
md.length = gupcr_gmem_size;
md.options = PTL_MD_EVENT_CT_ACK | PTL_MD_EVENT_CT_REPLY |
PTL_MD_EVENT_SUCCESS_DISABLE;
md.eq_handle = gupcr_coll_md_eq;
md.ct_handle = gupcr_coll_md_ct;
gupcr_portals_call (PtlMDBind, (gupcr_ptl_ni, &md, &gupcr_coll_md));
gupcr_coll_signal_cnt = 0;
gupcr_coll_ack_cnt = 0;
} | [
"void",
"gupcr_coll_init",
"(",
"void",
")",
"{",
"ptl_md_t",
"md",
";",
"ptl_pt_index_t",
"pte",
";",
"ptl_le_t",
"le",
";",
"gupcr_log",
"(",
"FC_COLL",
",",
"\"",
"\"",
")",
";",
"gupcr_portals_call",
"(",
"PtlEQAlloc",
",",
"(",
"gupcr_ptl_ni",
",",
"1",
",",
"&",
"gupcr_coll_le_eq",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlPTAlloc",
",",
"(",
"gupcr_ptl_ni",
",",
"0",
",",
"gupcr_coll_le_eq",
",",
"GUPCR_PTL_PTE_COLL",
",",
"&",
"pte",
")",
")",
";",
"if",
"(",
"pte",
"!=",
"GUPCR_PTL_PTE_COLL",
")",
"gupcr_fatal_error",
"(",
"\"",
"\"",
")",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"GUPCR_PTL_PTE_COLL",
")",
";",
"gupcr_portals_call",
"(",
"PtlCTAlloc",
",",
"(",
"gupcr_ptl_ni",
",",
"&",
"gupcr_coll_le_ct",
")",
")",
";",
"le",
".",
"start",
"=",
"gupcr_gmem_base",
";",
"le",
".",
"length",
"=",
"gupcr_gmem_size",
";",
"le",
".",
"ct_handle",
"=",
"gupcr_coll_le_ct",
";",
"le",
".",
"uid",
"=",
"PTL_UID_ANY",
";",
"le",
".",
"options",
"=",
"PTL_LE_OP_PUT",
"|",
"PTL_LE_OP_GET",
"|",
"PTL_LE_EVENT_CT_COMM",
"|",
"PTL_LE_EVENT_SUCCESS_DISABLE",
"|",
"PTL_LE_EVENT_LINK_DISABLE",
";",
"gupcr_portals_call",
"(",
"PtlLEAppend",
",",
"(",
"gupcr_ptl_ni",
",",
"GUPCR_PTL_PTE_COLL",
",",
"&",
"le",
",",
"PTL_PRIORITY_LIST",
",",
"NULL",
",",
"&",
"gupcr_coll_le",
")",
")",
";",
"gupcr_debug",
"(",
"FC_COLL",
",",
"\"",
"\"",
",",
"(",
"long",
"unsigned",
")",
"gupcr_gmem_base",
",",
"(",
"long",
"unsigned",
")",
"gupcr_gmem_size",
")",
";",
"gupcr_portals_call",
"(",
"PtlCTAlloc",
",",
"(",
"gupcr_ptl_ni",
",",
"&",
"gupcr_coll_md_ct",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlEQAlloc",
",",
"(",
"gupcr_ptl_ni",
",",
"1",
",",
"&",
"gupcr_coll_md_eq",
")",
")",
";",
"md",
".",
"start",
"=",
"gupcr_gmem_base",
";",
"md",
".",
"length",
"=",
"gupcr_gmem_size",
";",
"md",
".",
"options",
"=",
"PTL_MD_EVENT_CT_ACK",
"|",
"PTL_MD_EVENT_CT_REPLY",
"|",
"PTL_MD_EVENT_SUCCESS_DISABLE",
";",
"md",
".",
"eq_handle",
"=",
"gupcr_coll_md_eq",
";",
"md",
".",
"ct_handle",
"=",
"gupcr_coll_md_ct",
";",
"gupcr_portals_call",
"(",
"PtlMDBind",
",",
"(",
"gupcr_ptl_ni",
",",
"&",
"md",
",",
"&",
"gupcr_coll_md",
")",
")",
";",
"gupcr_coll_signal_cnt",
"=",
"0",
";",
"gupcr_coll_ack_cnt",
"=",
"0",
";",
"}"
] | Initialize collectives resources. | [
"Initialize",
"collectives",
"resources",
"."
] | [
"/* Allocate the Portals PTE that is used for collectives. */",
"/* Allocate the Portals LE that is used for collectives. */",
"/* Setup the Portals MD for local source/destination copying.\n We need to map only the shared memory space. */",
"/* Reset the number of signals/acks. */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
f9889ba465c1e7b31d2abf7e08ad1491464fcf5e | tactcomplabs/clang-upc | runtime/libupc/portals4/gupcr_coll_sup.c | [
"Apache-2.0"
] | C | gupcr_coll_fini | void | void
gupcr_coll_fini (void)
{
gupcr_log (FC_COLL, "coll fini called");
/* Release the collectives MD. */
gupcr_portals_call (PtlMDRelease, (gupcr_coll_md));
gupcr_portals_call (PtlCTFree, (gupcr_coll_md_ct));
gupcr_portals_call (PtlEQFree, (gupcr_coll_md_eq));
/* Release the collectives LE and PTE. */
gupcr_portals_call (PtlLEUnlink, (gupcr_coll_le));
gupcr_portals_call (PtlCTFree, (gupcr_coll_le_ct));
gupcr_portals_call (PtlEQFree, (gupcr_coll_le_eq));
gupcr_portals_call (PtlPTFree, (gupcr_ptl_ni, GUPCR_PTL_PTE_COLL));
} | /**
* Release collectives resources.
* @ingroup INIT
*/ | Release collectives resources.
@ingroup INIT | [
"Release",
"collectives",
"resources",
".",
"@ingroup",
"INIT"
] | void
gupcr_coll_fini (void)
{
gupcr_log (FC_COLL, "coll fini called");
gupcr_portals_call (PtlMDRelease, (gupcr_coll_md));
gupcr_portals_call (PtlCTFree, (gupcr_coll_md_ct));
gupcr_portals_call (PtlEQFree, (gupcr_coll_md_eq));
gupcr_portals_call (PtlLEUnlink, (gupcr_coll_le));
gupcr_portals_call (PtlCTFree, (gupcr_coll_le_ct));
gupcr_portals_call (PtlEQFree, (gupcr_coll_le_eq));
gupcr_portals_call (PtlPTFree, (gupcr_ptl_ni, GUPCR_PTL_PTE_COLL));
} | [
"void",
"gupcr_coll_fini",
"(",
"void",
")",
"{",
"gupcr_log",
"(",
"FC_COLL",
",",
"\"",
"\"",
")",
";",
"gupcr_portals_call",
"(",
"PtlMDRelease",
",",
"(",
"gupcr_coll_md",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlCTFree",
",",
"(",
"gupcr_coll_md_ct",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlEQFree",
",",
"(",
"gupcr_coll_md_eq",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlLEUnlink",
",",
"(",
"gupcr_coll_le",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlCTFree",
",",
"(",
"gupcr_coll_le_ct",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlEQFree",
",",
"(",
"gupcr_coll_le_eq",
")",
")",
";",
"gupcr_portals_call",
"(",
"PtlPTFree",
",",
"(",
"gupcr_ptl_ni",
",",
"GUPCR_PTL_PTE_COLL",
")",
")",
";",
"}"
] | Release collectives resources. | [
"Release",
"collectives",
"resources",
"."
] | [
"/* Release the collectives MD. */",
"/* Release the collectives LE and PTE. */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
20979056462340325eb51ec552ca4c747352b5fa | paulbelches/DecafParserAndLexer | compiler/symbolTableHandler.h | [
"MIT"
] | C | elementExist | int | int elementExist(string identifier){
int pos = -1;
int length = symbolTable.size();
stack<SymbolTable> tempSymbolTable;
for (int i = 0; i < length; i++){
//Check if the identifier exist
if (symbolTable.top().hasElement(identifier)) {
pos = i;
break;
}
tempSymbolTable.push(symbolTable.top());
symbolTable.pop();
}
length = tempSymbolTable.size();
for (int i = 0; i < length; i++){
symbolTable.push(tempSymbolTable.top());
tempSymbolTable.pop();
}
return pos;
} | //Para llamadas y referencias, no declaraciones | Para llamadas y referencias, no declaraciones | [
"Para",
"llamadas",
"y",
"referencias",
"no",
"declaraciones"
] | int elementExist(string identifier){
int pos = -1;
int length = symbolTable.size();
stack<SymbolTable> tempSymbolTable;
for (int i = 0; i < length; i++){
if (symbolTable.top().hasElement(identifier)) {
pos = i;
break;
}
tempSymbolTable.push(symbolTable.top());
symbolTable.pop();
}
length = tempSymbolTable.size();
for (int i = 0; i < length; i++){
symbolTable.push(tempSymbolTable.top());
tempSymbolTable.pop();
}
return pos;
} | [
"int",
"elementExist",
"(",
"string",
"identifier",
")",
"{",
"int",
"pos",
"=",
"-1",
";",
"int",
"length",
"=",
"symbolTable",
".",
"size",
"(",
")",
";",
"stack",
"<",
"SymbolTable",
">",
"tempSymbolTable",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"symbolTable",
".",
"top",
"(",
")",
".",
"hasElement",
"(",
"identifier",
")",
")",
"{",
"pos",
"=",
"i",
";",
"break",
";",
"}",
"tempSymbolTable",
".",
"push",
"(",
"symbolTable",
".",
"top",
"(",
")",
")",
";",
"symbolTable",
".",
"pop",
"(",
")",
";",
"}",
"length",
"=",
"tempSymbolTable",
".",
"size",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"symbolTable",
".",
"push",
"(",
"tempSymbolTable",
".",
"top",
"(",
")",
")",
";",
"tempSymbolTable",
".",
"pop",
"(",
")",
";",
"}",
"return",
"pos",
";",
"}"
] | Para llamadas y referencias, no declaraciones | [
"Para",
"llamadas",
"y",
"referencias",
"no",
"declaraciones"
] | [
"//Check if the identifier exist"
] | [
{
"param": "identifier",
"type": "string"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "identifier",
"type": "string",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20979056462340325eb51ec552ca4c747352b5fa | paulbelches/DecafParserAndLexer | compiler/symbolTableHandler.h | [
"MIT"
] | C | isGlobal | bool | bool isGlobal(string identifier){
//Clear the identifier
//Check if it is a struct
size_t p = 0;
p = identifier.find(".");
if (p > 0){
identifier = identifier.substr(0, p);
}
//Check if it is a array
p = 0;
p = identifier.find("[");
if (p > 0){
identifier = identifier.substr(0, p);
}
//cout << "Result "<< identifier << endl;
//
bool isglobal = true;
int length = symbolTable.size();
stack<SymbolTable> tempSymbolTable;
//cout << identifier << endl;
for (int i = 0; i < length; i++){
//cout << "I : " << i << " " << endl;
//Check if the identifier exist
if (symbolTable.top().hasElement(identifier)) {
//check if it is a param
//cout << length << " "<< (i == length - 1) << endl;
isglobal = i == length - 1;
break;
}
tempSymbolTable.push(symbolTable.top());
symbolTable.pop();
}
length = tempSymbolTable.size();
for (int i = 0; i < length; i++){
symbolTable.push(tempSymbolTable.top());
tempSymbolTable.pop();
}
return isglobal;
} | //Para llamadas y referencias, no declaraciones | Para llamadas y referencias, no declaraciones | [
"Para",
"llamadas",
"y",
"referencias",
"no",
"declaraciones"
] | bool isGlobal(string identifier){
size_t p = 0;
p = identifier.find(".");
if (p > 0){
identifier = identifier.substr(0, p);
}
p = 0;
p = identifier.find("[");
if (p > 0){
identifier = identifier.substr(0, p);
}
bool isglobal = true;
int length = symbolTable.size();
stack<SymbolTable> tempSymbolTable;
cout << identifier << endl;
for (int i = 0; i < length; i++){
cout << "I : " << i << " " << endl;
Check if the identifier exist
if (symbolTable.top().hasElement(identifier)) {
check if it is a param
cout << length << " "<< (i == length - 1) << endl;
isglobal = i == length - 1;
break;
}
tempSymbolTable.push(symbolTable.top());
symbolTable.pop();
}
length = tempSymbolTable.size();
for (int i = 0; i < length; i++){
symbolTable.push(tempSymbolTable.top());
tempSymbolTable.pop();
}
return isglobal;
} | [
"bool",
"isGlobal",
"(",
"string",
"identifier",
")",
"{",
"size_t",
"p",
"=",
"0",
";",
"p",
"=",
"identifier",
".",
"find",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"p",
">",
"0",
")",
"{",
"identifier",
"=",
"identifier",
".",
"substr",
"(",
"0",
",",
"p",
")",
";",
"}",
"p",
"=",
"0",
";",
"p",
"=",
"identifier",
".",
"find",
"(",
"\"",
"\"",
")",
";",
"if",
"(",
"p",
">",
"0",
")",
"{",
"identifier",
"=",
"identifier",
".",
"substr",
"(",
"0",
",",
"p",
")",
";",
"}",
"bool",
"isglobal",
"=",
"true",
";",
"int",
"length",
"=",
"symbolTable",
".",
"size",
"(",
")",
";",
"stack",
"<",
"SymbolTable",
">",
"tempSymbolTable",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"if",
"(",
"symbolTable",
".",
"top",
"(",
")",
".",
"hasElement",
"(",
"identifier",
")",
")",
"{",
"isglobal",
"=",
"i",
"==",
"length",
"-",
"1",
";",
"break",
";",
"}",
"tempSymbolTable",
".",
"push",
"(",
"symbolTable",
".",
"top",
"(",
")",
")",
";",
"symbolTable",
".",
"pop",
"(",
")",
";",
"}",
"length",
"=",
"tempSymbolTable",
".",
"size",
"(",
")",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"length",
";",
"i",
"++",
")",
"{",
"symbolTable",
".",
"push",
"(",
"tempSymbolTable",
".",
"top",
"(",
")",
")",
";",
"tempSymbolTable",
".",
"pop",
"(",
")",
";",
"}",
"return",
"isglobal",
";",
"}"
] | Para llamadas y referencias, no declaraciones | [
"Para",
"llamadas",
"y",
"referencias",
"no",
"declaraciones"
] | [
"//Clear the identifier",
"//Check if it is a struct",
"//Check if it is a array",
"//cout << \"Result \"<< identifier << endl;",
"//",
"//cout << identifier << endl;",
"//cout << \"I : \" << i << \" \" << endl;",
"//Check if the identifier exist",
"//check if it is a param",
"//cout << length << \" \"<< (i == length - 1) << endl;"
] | [
{
"param": "identifier",
"type": "string"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "identifier",
"type": "string",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
20979056462340325eb51ec552ca4c747352b5fa | paulbelches/DecafParserAndLexer | compiler/symbolTableHandler.h | [
"MIT"
] | C | initializeWithParamTable | void | void initializeWithParamTable(){
for (int i = 0; i < paramTable.getSize(); i++){
string identifier = paramTable.getIdentifier(i);
string dataType = paramTable.lookup(paramTable.getIdentifier(i)).dataType;
int size = paramTable.lookup(paramTable.getIdentifier(i)).size;
symbolTable.top().binding(identifier, dataType, size);
//cout << i << endl;
}
} | // initialize the symbol table With the information of the ParamTable | initialize the symbol table With the information of the ParamTable | [
"initialize",
"the",
"symbol",
"table",
"With",
"the",
"information",
"of",
"the",
"ParamTable"
] | void initializeWithParamTable(){
for (int i = 0; i < paramTable.getSize(); i++){
string identifier = paramTable.getIdentifier(i);
string dataType = paramTable.lookup(paramTable.getIdentifier(i)).dataType;
int size = paramTable.lookup(paramTable.getIdentifier(i)).size;
symbolTable.top().binding(identifier, dataType, size);
}
} | [
"void",
"initializeWithParamTable",
"(",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"paramTable",
".",
"getSize",
"(",
")",
";",
"i",
"++",
")",
"{",
"string",
"identifier",
"=",
"paramTable",
".",
"getIdentifier",
"(",
"i",
")",
";",
"string",
"dataType",
"=",
"paramTable",
".",
"lookup",
"(",
"paramTable",
".",
"getIdentifier",
"(",
"i",
")",
")",
".",
"dataType",
";",
"int",
"size",
"=",
"paramTable",
".",
"lookup",
"(",
"paramTable",
".",
"getIdentifier",
"(",
"i",
")",
")",
".",
"size",
";",
"symbolTable",
".",
"top",
"(",
")",
".",
"binding",
"(",
"identifier",
",",
"dataType",
",",
"size",
")",
";",
"}",
"}"
] | initialize the symbol table With the information of the ParamTable | [
"initialize",
"the",
"symbol",
"table",
"With",
"the",
"information",
"of",
"the",
"ParamTable"
] | [
"//cout << i << endl;"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
747da96eaf65117b058d97683f6e9f07a76703b4 | noritsuna/JPEGEncoder4Cortex-M | jpegencoder.c | [
"Apache-2.0"
] | C | encode_image | int | int encode_image(jpeg_data *data, int (*read_data_func)(uint_t pos, uint8_t *data, uint_t len), int (*write_data_func)(uint8_t *data, uint_t len)) {
int mcu_size = data->c_info.mcu_size;
int width = data->width;
int height = data->height;
int pixel_size_by_byte = data->c_info.pixel_size_by_byte;
//CAUTION!!!!!!!!!! MUST initializing jpeg_data structure!
if(data->mcu_width_max == 0) {
data->mcu_width_max = (int)ceil(width / (float)mcu_size);
data->mcu_height_max = (int)ceil(height / (float)mcu_size);
}
int mcu_width_max = data->mcu_width_max;
int mcu_height_max = data->mcu_height_max;
uint8_t *mcu = data->work.mcu;
uint8_t prePixel_y = 0;
uint8_t prePixel_Crb = 0;
int cnt = 0;
generate_header(data);
write_data_func(data->ret_data, data->data_len);
cnt += data->data_len;
//MUC by CbYCr format & Grayscale.
for(int cur_mcu_height = 0; cur_mcu_height < mcu_height_max; cur_mcu_height++) {
for(int cur_mcu_width = 0; cur_mcu_width < mcu_width_max; cur_mcu_width++) {
for(int cur_height = 0; cur_height < mcu_size; cur_height++) {
if((cur_mcu_height*mcu_size + cur_height) >= height) {
for(int i = 0; i < mcu_size*pixel_size_by_byte; i++) {
if(i%2 == 0) {
mcu[cur_height*mcu_size*pixel_size_by_byte + i] = prePixel_Crb;
} else {
mcu[cur_height*mcu_size*pixel_size_by_byte + i] = prePixel_y;
}
}
} else {
for(int cur_width = 0; cur_width < mcu_size*pixel_size_by_byte; cur_width++) {
if(cur_mcu_width*mcu_size*pixel_size_by_byte + cur_width >= width*pixel_size_by_byte) {
if(cur_width%2 == 0) {
mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width] = prePixel_Crb;
} else {
mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width] = prePixel_y;
}
} else {
read_data_func((cur_mcu_height*mcu_size + cur_height)*width*pixel_size_by_byte + (cur_mcu_width*mcu_size*pixel_size_by_byte + cur_width), &mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width],1);
if(cur_width%2 == 0) {
prePixel_Crb = mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width];
} else {
prePixel_y = mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width];
}
}
}
}
}
encode_MCU(data, mcu);
write_data_func(data->ret_data, data->data_len);
cnt += data->data_len;
}
}
generateFooter(data);
write_data_func(data->ret_data, data->data_len);
cnt += data->data_len;
return cnt;
} | /**
* Reading Image data & Writing Encoded data by each MCU.
* Supported Image format is "8bit Grayscale" and "YUV422(CbYCrY format)" 1-dimensional array.
*
* @param data JPEG Structure
* @param read_data_func Reading Image data function
* @param write_data_func Writing Ecoding data Function
* @return JPEG file size. Under 0 is error.
*/ | Reading Image data & Writing Encoded data by each MCU.
Supported Image format is "8bit Grayscale" and "YUV422(CbYCrY format)" 1-dimensional array.
@param data JPEG Structure
@param read_data_func Reading Image data function
@param write_data_func Writing Ecoding data Function
@return JPEG file size. Under 0 is error. | [
"Reading",
"Image",
"data",
"&",
"Writing",
"Encoded",
"data",
"by",
"each",
"MCU",
".",
"Supported",
"Image",
"format",
"is",
"\"",
"8bit",
"Grayscale",
"\"",
"and",
"\"",
"YUV422",
"(",
"CbYCrY",
"format",
")",
"\"",
"1",
"-",
"dimensional",
"array",
".",
"@param",
"data",
"JPEG",
"Structure",
"@param",
"read_data_func",
"Reading",
"Image",
"data",
"function",
"@param",
"write_data_func",
"Writing",
"Ecoding",
"data",
"Function",
"@return",
"JPEG",
"file",
"size",
".",
"Under",
"0",
"is",
"error",
"."
] | int encode_image(jpeg_data *data, int (*read_data_func)(uint_t pos, uint8_t *data, uint_t len), int (*write_data_func)(uint8_t *data, uint_t len)) {
int mcu_size = data->c_info.mcu_size;
int width = data->width;
int height = data->height;
int pixel_size_by_byte = data->c_info.pixel_size_by_byte;
if(data->mcu_width_max == 0) {
data->mcu_width_max = (int)ceil(width / (float)mcu_size);
data->mcu_height_max = (int)ceil(height / (float)mcu_size);
}
int mcu_width_max = data->mcu_width_max;
int mcu_height_max = data->mcu_height_max;
uint8_t *mcu = data->work.mcu;
uint8_t prePixel_y = 0;
uint8_t prePixel_Crb = 0;
int cnt = 0;
generate_header(data);
write_data_func(data->ret_data, data->data_len);
cnt += data->data_len;
for(int cur_mcu_height = 0; cur_mcu_height < mcu_height_max; cur_mcu_height++) {
for(int cur_mcu_width = 0; cur_mcu_width < mcu_width_max; cur_mcu_width++) {
for(int cur_height = 0; cur_height < mcu_size; cur_height++) {
if((cur_mcu_height*mcu_size + cur_height) >= height) {
for(int i = 0; i < mcu_size*pixel_size_by_byte; i++) {
if(i%2 == 0) {
mcu[cur_height*mcu_size*pixel_size_by_byte + i] = prePixel_Crb;
} else {
mcu[cur_height*mcu_size*pixel_size_by_byte + i] = prePixel_y;
}
}
} else {
for(int cur_width = 0; cur_width < mcu_size*pixel_size_by_byte; cur_width++) {
if(cur_mcu_width*mcu_size*pixel_size_by_byte + cur_width >= width*pixel_size_by_byte) {
if(cur_width%2 == 0) {
mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width] = prePixel_Crb;
} else {
mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width] = prePixel_y;
}
} else {
read_data_func((cur_mcu_height*mcu_size + cur_height)*width*pixel_size_by_byte + (cur_mcu_width*mcu_size*pixel_size_by_byte + cur_width), &mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width],1);
if(cur_width%2 == 0) {
prePixel_Crb = mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width];
} else {
prePixel_y = mcu[cur_height*mcu_size*pixel_size_by_byte + cur_width];
}
}
}
}
}
encode_MCU(data, mcu);
write_data_func(data->ret_data, data->data_len);
cnt += data->data_len;
}
}
generateFooter(data);
write_data_func(data->ret_data, data->data_len);
cnt += data->data_len;
return cnt;
} | [
"int",
"encode_image",
"(",
"jpeg_data",
"*",
"data",
",",
"int",
"(",
"*",
"read_data_func",
")",
"(",
"uint_t",
"pos",
",",
"uint8_t",
"*",
"data",
",",
"uint_t",
"len",
")",
",",
"int",
"(",
"*",
"write_data_func",
")",
"(",
"uint8_t",
"*",
"data",
",",
"uint_t",
"len",
")",
")",
"{",
"int",
"mcu_size",
"=",
"data",
"->",
"c_info",
".",
"mcu_size",
";",
"int",
"width",
"=",
"data",
"->",
"width",
";",
"int",
"height",
"=",
"data",
"->",
"height",
";",
"int",
"pixel_size_by_byte",
"=",
"data",
"->",
"c_info",
".",
"pixel_size_by_byte",
";",
"if",
"(",
"data",
"->",
"mcu_width_max",
"==",
"0",
")",
"{",
"data",
"->",
"mcu_width_max",
"=",
"(",
"int",
")",
"ceil",
"(",
"width",
"/",
"(",
"float",
")",
"mcu_size",
")",
";",
"data",
"->",
"mcu_height_max",
"=",
"(",
"int",
")",
"ceil",
"(",
"height",
"/",
"(",
"float",
")",
"mcu_size",
")",
";",
"}",
"int",
"mcu_width_max",
"=",
"data",
"->",
"mcu_width_max",
";",
"int",
"mcu_height_max",
"=",
"data",
"->",
"mcu_height_max",
";",
"uint8_t",
"*",
"mcu",
"=",
"data",
"->",
"work",
".",
"mcu",
";",
"uint8_t",
"prePixel_y",
"=",
"0",
";",
"uint8_t",
"prePixel_Crb",
"=",
"0",
";",
"int",
"cnt",
"=",
"0",
";",
"generate_header",
"(",
"data",
")",
";",
"write_data_func",
"(",
"data",
"->",
"ret_data",
",",
"data",
"->",
"data_len",
")",
";",
"cnt",
"+=",
"data",
"->",
"data_len",
";",
"for",
"(",
"int",
"cur_mcu_height",
"=",
"0",
";",
"cur_mcu_height",
"<",
"mcu_height_max",
";",
"cur_mcu_height",
"++",
")",
"{",
"for",
"(",
"int",
"cur_mcu_width",
"=",
"0",
";",
"cur_mcu_width",
"<",
"mcu_width_max",
";",
"cur_mcu_width",
"++",
")",
"{",
"for",
"(",
"int",
"cur_height",
"=",
"0",
";",
"cur_height",
"<",
"mcu_size",
";",
"cur_height",
"++",
")",
"{",
"if",
"(",
"(",
"cur_mcu_height",
"*",
"mcu_size",
"+",
"cur_height",
")",
">=",
"height",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"mcu_size",
"*",
"pixel_size_by_byte",
";",
"i",
"++",
")",
"{",
"if",
"(",
"i",
"%",
"2",
"==",
"0",
")",
"{",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"i",
"]",
"=",
"prePixel_Crb",
";",
"}",
"else",
"{",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"i",
"]",
"=",
"prePixel_y",
";",
"}",
"}",
"}",
"else",
"{",
"for",
"(",
"int",
"cur_width",
"=",
"0",
";",
"cur_width",
"<",
"mcu_size",
"*",
"pixel_size_by_byte",
";",
"cur_width",
"++",
")",
"{",
"if",
"(",
"cur_mcu_width",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
">=",
"width",
"*",
"pixel_size_by_byte",
")",
"{",
"if",
"(",
"cur_width",
"%",
"2",
"==",
"0",
")",
"{",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
"]",
"=",
"prePixel_Crb",
";",
"}",
"else",
"{",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
"]",
"=",
"prePixel_y",
";",
"}",
"}",
"else",
"{",
"read_data_func",
"(",
"(",
"cur_mcu_height",
"*",
"mcu_size",
"+",
"cur_height",
")",
"*",
"width",
"*",
"pixel_size_by_byte",
"+",
"(",
"cur_mcu_width",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
")",
",",
"&",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
"]",
",",
"1",
")",
";",
"if",
"(",
"cur_width",
"%",
"2",
"==",
"0",
")",
"{",
"prePixel_Crb",
"=",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
"]",
";",
"}",
"else",
"{",
"prePixel_y",
"=",
"mcu",
"[",
"cur_height",
"*",
"mcu_size",
"*",
"pixel_size_by_byte",
"+",
"cur_width",
"]",
";",
"}",
"}",
"}",
"}",
"}",
"encode_MCU",
"(",
"data",
",",
"mcu",
")",
";",
"write_data_func",
"(",
"data",
"->",
"ret_data",
",",
"data",
"->",
"data_len",
")",
";",
"cnt",
"+=",
"data",
"->",
"data_len",
";",
"}",
"}",
"generateFooter",
"(",
"data",
")",
";",
"write_data_func",
"(",
"data",
"->",
"ret_data",
",",
"data",
"->",
"data_len",
")",
";",
"cnt",
"+=",
"data",
"->",
"data_len",
";",
"return",
"cnt",
";",
"}"
] | Reading Image data & Writing Encoded data by each MCU. | [
"Reading",
"Image",
"data",
"&",
"Writing",
"Encoded",
"data",
"by",
"each",
"MCU",
"."
] | [
"//CAUTION!!!!!!!!!! MUST initializing jpeg_data structure!",
"//MUC by CbYCr format & Grayscale."
] | [
{
"param": "data",
"type": "uint8_t"
},
{
"param": "read_data_func",
"type": "int"
},
{
"param": "pos",
"type": "uint_t"
},
{
"param": "len",
"type": "uint_t"
},
{
"param": "write_data_func",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "uint8_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "read_data_func",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "pos",
"type": "uint_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "len",
"type": "uint_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "write_data_func",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
747da96eaf65117b058d97683f6e9f07a76703b4 | noritsuna/JPEGEncoder4Cortex-M | jpegencoder.c | [
"Apache-2.0"
] | C | put_byte | void | static void put_byte(jpeg_data *data, const uint8_t val){
uint_t pos = data->data_len;
data->ret_data[pos++] = val;
data->data_len = pos;
} | /**
* Put Filled uffman code's bits to Encoding data.
*
* @param data JPEG Structure
* @param val Filled Encoding data
*/ | Put Filled uffman code's bits to Encoding data.
@param data JPEG Structure
@param val Filled Encoding data | [
"Put",
"Filled",
"uffman",
"code",
"'",
"s",
"bits",
"to",
"Encoding",
"data",
".",
"@param",
"data",
"JPEG",
"Structure",
"@param",
"val",
"Filled",
"Encoding",
"data"
] | static void put_byte(jpeg_data *data, const uint8_t val){
uint_t pos = data->data_len;
data->ret_data[pos++] = val;
data->data_len = pos;
} | [
"static",
"void",
"put_byte",
"(",
"jpeg_data",
"*",
"data",
",",
"const",
"uint8_t",
"val",
")",
"{",
"uint_t",
"pos",
"=",
"data",
"->",
"data_len",
";",
"data",
"->",
"ret_data",
"[",
"pos",
"++",
"]",
"=",
"val",
";",
"data",
"->",
"data_len",
"=",
"pos",
";",
"}"
] | Put Filled uffman code's bits to Encoding data. | [
"Put",
"Filled",
"uffman",
"code",
"'",
"s",
"bits",
"to",
"Encoding",
"data",
"."
] | [] | [
{
"param": "data",
"type": "jpeg_data"
},
{
"param": "val",
"type": "uint8_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "jpeg_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "val",
"type": "uint8_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
747da96eaf65117b058d97683f6e9f07a76703b4 | noritsuna/JPEGEncoder4Cortex-M | jpegencoder.c | [
"Apache-2.0"
] | C | put_bits | void | static void put_bits(jpeg_data *data, const uint_t nbits, const uint16_t val) {
uint_t codebits = nbits;
uint16_t bits = val << (16 - codebits);
uint8_t byte = data->stream.byte;
uint_t rest = data->stream.rest;
if(rest == 0) {
rest = 8;
}
while(codebits != 0) {
uint_t n = codebits;
if(n > rest){
n = rest;
}
codebits -= n;
rest -= n;
byte = (byte << n) | (uint8_t)((bits >> (16 - n)) & 0xff);
bits <<= n;
if(rest == 0) {
put_byte(data, byte);
if(byte == 0xff) {
put_byte(data, 0x00U);
}
rest = 8;
}
}
data->stream.byte = byte;
data->stream.rest = rest;
} | /**
* Fill Huffman code's bits to byte.
*
* @param data JPEG Structure
* @param nbits number of Huffman code's bits
* @param val Filled Encoding data
*/ | Fill Huffman code's bits to byte.
@param data JPEG Structure
@param nbits number of Huffman code's bits
@param val Filled Encoding data | [
"Fill",
"Huffman",
"code",
"'",
"s",
"bits",
"to",
"byte",
".",
"@param",
"data",
"JPEG",
"Structure",
"@param",
"nbits",
"number",
"of",
"Huffman",
"code",
"'",
"s",
"bits",
"@param",
"val",
"Filled",
"Encoding",
"data"
] | static void put_bits(jpeg_data *data, const uint_t nbits, const uint16_t val) {
uint_t codebits = nbits;
uint16_t bits = val << (16 - codebits);
uint8_t byte = data->stream.byte;
uint_t rest = data->stream.rest;
if(rest == 0) {
rest = 8;
}
while(codebits != 0) {
uint_t n = codebits;
if(n > rest){
n = rest;
}
codebits -= n;
rest -= n;
byte = (byte << n) | (uint8_t)((bits >> (16 - n)) & 0xff);
bits <<= n;
if(rest == 0) {
put_byte(data, byte);
if(byte == 0xff) {
put_byte(data, 0x00U);
}
rest = 8;
}
}
data->stream.byte = byte;
data->stream.rest = rest;
} | [
"static",
"void",
"put_bits",
"(",
"jpeg_data",
"*",
"data",
",",
"const",
"uint_t",
"nbits",
",",
"const",
"uint16_t",
"val",
")",
"{",
"uint_t",
"codebits",
"=",
"nbits",
";",
"uint16_t",
"bits",
"=",
"val",
"<<",
"(",
"16",
"-",
"codebits",
")",
";",
"uint8_t",
"byte",
"=",
"data",
"->",
"stream",
".",
"byte",
";",
"uint_t",
"rest",
"=",
"data",
"->",
"stream",
".",
"rest",
";",
"if",
"(",
"rest",
"==",
"0",
")",
"{",
"rest",
"=",
"8",
";",
"}",
"while",
"(",
"codebits",
"!=",
"0",
")",
"{",
"uint_t",
"n",
"=",
"codebits",
";",
"if",
"(",
"n",
">",
"rest",
")",
"{",
"n",
"=",
"rest",
";",
"}",
"codebits",
"-=",
"n",
";",
"rest",
"-=",
"n",
";",
"byte",
"=",
"(",
"byte",
"<<",
"n",
")",
"|",
"(",
"uint8_t",
")",
"(",
"(",
"bits",
">>",
"(",
"16",
"-",
"n",
")",
")",
"&",
"0xff",
")",
";",
"bits",
"<<=",
"n",
";",
"if",
"(",
"rest",
"==",
"0",
")",
"{",
"put_byte",
"(",
"data",
",",
"byte",
")",
";",
"if",
"(",
"byte",
"==",
"0xff",
")",
"{",
"put_byte",
"(",
"data",
",",
"0x00U",
")",
";",
"}",
"rest",
"=",
"8",
";",
"}",
"}",
"data",
"->",
"stream",
".",
"byte",
"=",
"byte",
";",
"data",
"->",
"stream",
".",
"rest",
"=",
"rest",
";",
"}"
] | Fill Huffman code's bits to byte. | [
"Fill",
"Huffman",
"code",
"'",
"s",
"bits",
"to",
"byte",
"."
] | [] | [
{
"param": "data",
"type": "jpeg_data"
},
{
"param": "nbits",
"type": "uint_t"
},
{
"param": "val",
"type": "uint16_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "jpeg_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "nbits",
"type": "uint_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "val",
"type": "uint16_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
747da96eaf65117b058d97683f6e9f07a76703b4 | noritsuna/JPEGEncoder4Cortex-M | jpegencoder.c | [
"Apache-2.0"
] | C | flush_bits | void | static void flush_bits(jpeg_data *data) {
uint_t rest = data->stream.rest;
if((rest & 7) != 0) {
uint8_t byte = data->stream.byte;
byte = byte << rest;
put_byte(data, byte);
data->stream.byte = 0x00;
data->stream.rest = 0;
}
} | /**
* Flush Huffman code's bits to byte.
*
* @param data JPEG Structure
*/ | Flush Huffman code's bits to byte.
@param data JPEG Structure | [
"Flush",
"Huffman",
"code",
"'",
"s",
"bits",
"to",
"byte",
".",
"@param",
"data",
"JPEG",
"Structure"
] | static void flush_bits(jpeg_data *data) {
uint_t rest = data->stream.rest;
if((rest & 7) != 0) {
uint8_t byte = data->stream.byte;
byte = byte << rest;
put_byte(data, byte);
data->stream.byte = 0x00;
data->stream.rest = 0;
}
} | [
"static",
"void",
"flush_bits",
"(",
"jpeg_data",
"*",
"data",
")",
"{",
"uint_t",
"rest",
"=",
"data",
"->",
"stream",
".",
"rest",
";",
"if",
"(",
"(",
"rest",
"&",
"7",
")",
"!=",
"0",
")",
"{",
"uint8_t",
"byte",
"=",
"data",
"->",
"stream",
".",
"byte",
";",
"byte",
"=",
"byte",
"<<",
"rest",
";",
"put_byte",
"(",
"data",
",",
"byte",
")",
";",
"data",
"->",
"stream",
".",
"byte",
"=",
"0x00",
";",
"data",
"->",
"stream",
".",
"rest",
"=",
"0",
";",
"}",
"}"
] | Flush Huffman code's bits to byte. | [
"Flush",
"Huffman",
"code",
"'",
"s",
"bits",
"to",
"byte",
"."
] | [] | [
{
"param": "data",
"type": "jpeg_data"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "data",
"type": "jpeg_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | nordic_nrf5_uart_event_handler_rxstarted | void | static void nordic_nrf5_uart_event_handler_rxstarted(int instance)
{
uint8_t next_bank = nordic_nrf5_uart_state[instance].active_bank ^ 0x01;
nrf_uarte_rx_buffer_set(nordic_nrf5_uart_register[instance], nordic_nrf5_uart_state[instance].buffer[next_bank], DMA_BUFFER_SIZE);
if (nordic_nrf5_uart_state[instance].rts != NRF_UART_PSEL_DISCONNECTED) {
if (nordic_nrf5_uart_state[instance].fifo_free_count > FIFO_MIN) {
/* Clear rts since we are ready to receive the next byte */
nrfx_gpiote_clr_task_trigger(nordic_nrf5_uart_state[instance].rts);
} else {
/* Suspend reception since there isn't enough buffer space.
* The function serial_getc will restart reception. */
nordic_nrf5_uart_state[instance].rx_suspended = true;
}
}
} | /**
* @brief Event handler for when DMA has been armed with Rx buffer.
*
* Arm Rx buffer with second buffer for optimal reception.
*
* @param[in] instance The instance
*/ | @brief Event handler for when DMA has been armed with Rx buffer.
Arm Rx buffer with second buffer for optimal reception.
@param[in] instance The instance | [
"@brief",
"Event",
"handler",
"for",
"when",
"DMA",
"has",
"been",
"armed",
"with",
"Rx",
"buffer",
".",
"Arm",
"Rx",
"buffer",
"with",
"second",
"buffer",
"for",
"optimal",
"reception",
".",
"@param",
"[",
"in",
"]",
"instance",
"The",
"instance"
] | static void nordic_nrf5_uart_event_handler_rxstarted(int instance)
{
uint8_t next_bank = nordic_nrf5_uart_state[instance].active_bank ^ 0x01;
nrf_uarte_rx_buffer_set(nordic_nrf5_uart_register[instance], nordic_nrf5_uart_state[instance].buffer[next_bank], DMA_BUFFER_SIZE);
if (nordic_nrf5_uart_state[instance].rts != NRF_UART_PSEL_DISCONNECTED) {
if (nordic_nrf5_uart_state[instance].fifo_free_count > FIFO_MIN) {
nrfx_gpiote_clr_task_trigger(nordic_nrf5_uart_state[instance].rts);
} else {
nordic_nrf5_uart_state[instance].rx_suspended = true;
}
}
} | [
"static",
"void",
"nordic_nrf5_uart_event_handler_rxstarted",
"(",
"int",
"instance",
")",
"{",
"uint8_t",
"next_bank",
"=",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"active_bank",
"^",
"0x01",
";",
"nrf_uarte_rx_buffer_set",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"buffer",
"[",
"next_bank",
"]",
",",
"DMA_BUFFER_SIZE",
")",
";",
"if",
"(",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"rts",
"!=",
"NRF_UART_PSEL_DISCONNECTED",
")",
"{",
"if",
"(",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"fifo_free_count",
">",
"FIFO_MIN",
")",
"{",
"nrfx_gpiote_clr_task_trigger",
"(",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"rts",
")",
";",
"}",
"else",
"{",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"rx_suspended",
"=",
"true",
";",
"}",
"}",
"}"
] | @brief Event handler for when DMA has been armed with Rx buffer. | [
"@brief",
"Event",
"handler",
"for",
"when",
"DMA",
"has",
"been",
"armed",
"with",
"Rx",
"buffer",
"."
] | [
"/* Clear rts since we are ready to receive the next byte */",
"/* Suspend reception since there isn't enough buffer space.\n * The function serial_getc will restart reception. */"
] | [
{
"param": "instance",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "instance",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | nordic_nrf5_uart_configure_object | void | static void nordic_nrf5_uart_configure_object(serial_t *obj)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
/* Configure Tx and Rx pins. */
if (uart_object->tx != NRF_UART_PSEL_DISCONNECTED) {
nrf_gpio_pin_set(uart_object->tx);
nrf_gpio_cfg_output(uart_object->tx);
}
if (uart_object->rx != NRF_UART_PSEL_DISCONNECTED) {
nrf_gpio_cfg_input(uart_object->rx, NRF_GPIO_PIN_NOPULL);
}
nrf_uarte_txrx_pins_set(nordic_nrf5_uart_register[uart_object->instance],
uart_object->tx,
uart_object->rx);
/* Set hardware flow control pins. */
if (uart_object->hwfc == NRF_UART_HWFC_ENABLED) {
/* Check if pin is set before configuring it. */
if (uart_object->cts != NRF_UART_PSEL_DISCONNECTED) {
nrf_gpio_cfg_input(uart_object->cts, NRF_GPIO_PIN_NOPULL);
}
/* Only let UARTE module handle CTS, RTS is handled manually due to buggy UARTE logic. */
nrf_uarte_hwfc_pins_set(nordic_nrf5_uart_register[uart_object->instance],
NRF_UART_PSEL_DISCONNECTED,
uart_object->cts);
}
/* Check if the rts pin changed */
if (uart_object->rts != nordic_nrf5_uart_state[uart_object->instance].rts) {
uint32_t ret;
/* Disable the PPI interconnect */
ret = nrfx_ppi_channel_disable(nordic_nrf5_uart_state[uart_object->instance].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
/* Free flow control gpiote pin if it was previously set */
if (nordic_nrf5_uart_state[uart_object->instance].rts != NRF_UART_PSEL_DISCONNECTED) {
nrfx_gpiote_out_uninit((nrfx_gpiote_pin_t)uart_object->rts);
}
/* Allocate and enable flow control gpiote pin if it is being used */
if (uart_object->rts != NRF_UART_PSEL_DISCONNECTED) {
static const nrfx_gpiote_out_config_t config = {
.init_state = NRF_GPIOTE_INITIAL_VALUE_HIGH,
.task_pin = true,
.action = NRF_GPIOTE_POLARITY_LOTOHI
};
/* Allocate gpiote channel */
ret = nrfx_gpiote_out_init((nrfx_gpiote_pin_t)uart_object->rts, &config);
if (ret == NRF_ERROR_INVALID_STATE) {
/* Pin was previously set to GPIO so uninitialize it */
nrfx_gpiote_out_uninit((nrfx_gpiote_pin_t)uart_object->rts);
ret = nrfx_gpiote_out_init((nrfx_gpiote_pin_t)uart_object->rts, &config);
}
MBED_ASSERT(ret == NRF_SUCCESS);
/* Set RTS high on the ENDRX event */
ret = nrfx_ppi_channel_assign(nordic_nrf5_uart_state[uart_object->instance].ppi_rts,
nrf_uarte_event_address_get(nordic_nrf5_uart_register[uart_object->instance], NRF_UARTE_EVENT_ENDRX),
nrfx_gpiote_out_task_addr_get(uart_object->rts));
MBED_ASSERT(ret == NRF_SUCCESS);
ret = nrfx_ppi_channel_enable(nordic_nrf5_uart_state[uart_object->instance].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
/* Enable gpiote task - rts pin can no longer be used as GPIO at this point */
nrfx_gpiote_out_task_enable((nrfx_gpiote_pin_t)uart_object->rts);
}
nordic_nrf5_uart_state[uart_object->instance].rts = uart_object->rts;
}
/* Enable flow control and parity. */
nrf_uarte_configure(nordic_nrf5_uart_register[uart_object->instance],
(nrf_uarte_parity_t) uart_object->parity,
(nrf_uarte_hwfc_t) uart_object->hwfc);
/* Set baudrate. */
nrf_uarte_baudrate_set(nordic_nrf5_uart_register[uart_object->instance],
(nrf_uarte_baudrate_t) uart_object->baudrate);
} | /**
* @brief Configure UARTE based on serial object settings.
*
* Common for both Rx and Tx.
*
* @param obj The object
*/ | @brief Configure UARTE based on serial object settings.
Common for both Rx and Tx.
@param obj The object | [
"@brief",
"Configure",
"UARTE",
"based",
"on",
"serial",
"object",
"settings",
".",
"Common",
"for",
"both",
"Rx",
"and",
"Tx",
".",
"@param",
"obj",
"The",
"object"
] | static void nordic_nrf5_uart_configure_object(serial_t *obj)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
if (uart_object->tx != NRF_UART_PSEL_DISCONNECTED) {
nrf_gpio_pin_set(uart_object->tx);
nrf_gpio_cfg_output(uart_object->tx);
}
if (uart_object->rx != NRF_UART_PSEL_DISCONNECTED) {
nrf_gpio_cfg_input(uart_object->rx, NRF_GPIO_PIN_NOPULL);
}
nrf_uarte_txrx_pins_set(nordic_nrf5_uart_register[uart_object->instance],
uart_object->tx,
uart_object->rx);
if (uart_object->hwfc == NRF_UART_HWFC_ENABLED) {
if (uart_object->cts != NRF_UART_PSEL_DISCONNECTED) {
nrf_gpio_cfg_input(uart_object->cts, NRF_GPIO_PIN_NOPULL);
}
nrf_uarte_hwfc_pins_set(nordic_nrf5_uart_register[uart_object->instance],
NRF_UART_PSEL_DISCONNECTED,
uart_object->cts);
}
if (uart_object->rts != nordic_nrf5_uart_state[uart_object->instance].rts) {
uint32_t ret;
ret = nrfx_ppi_channel_disable(nordic_nrf5_uart_state[uart_object->instance].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
if (nordic_nrf5_uart_state[uart_object->instance].rts != NRF_UART_PSEL_DISCONNECTED) {
nrfx_gpiote_out_uninit((nrfx_gpiote_pin_t)uart_object->rts);
}
if (uart_object->rts != NRF_UART_PSEL_DISCONNECTED) {
static const nrfx_gpiote_out_config_t config = {
.init_state = NRF_GPIOTE_INITIAL_VALUE_HIGH,
.task_pin = true,
.action = NRF_GPIOTE_POLARITY_LOTOHI
};
ret = nrfx_gpiote_out_init((nrfx_gpiote_pin_t)uart_object->rts, &config);
if (ret == NRF_ERROR_INVALID_STATE) {
nrfx_gpiote_out_uninit((nrfx_gpiote_pin_t)uart_object->rts);
ret = nrfx_gpiote_out_init((nrfx_gpiote_pin_t)uart_object->rts, &config);
}
MBED_ASSERT(ret == NRF_SUCCESS);
ret = nrfx_ppi_channel_assign(nordic_nrf5_uart_state[uart_object->instance].ppi_rts,
nrf_uarte_event_address_get(nordic_nrf5_uart_register[uart_object->instance], NRF_UARTE_EVENT_ENDRX),
nrfx_gpiote_out_task_addr_get(uart_object->rts));
MBED_ASSERT(ret == NRF_SUCCESS);
ret = nrfx_ppi_channel_enable(nordic_nrf5_uart_state[uart_object->instance].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
nrfx_gpiote_out_task_enable((nrfx_gpiote_pin_t)uart_object->rts);
}
nordic_nrf5_uart_state[uart_object->instance].rts = uart_object->rts;
}
nrf_uarte_configure(nordic_nrf5_uart_register[uart_object->instance],
(nrf_uarte_parity_t) uart_object->parity,
(nrf_uarte_hwfc_t) uart_object->hwfc);
nrf_uarte_baudrate_set(nordic_nrf5_uart_register[uart_object->instance],
(nrf_uarte_baudrate_t) uart_object->baudrate);
} | [
"static",
"void",
"nordic_nrf5_uart_configure_object",
"(",
"serial_t",
"*",
"obj",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"if",
"(",
"uart_object",
"->",
"tx",
"!=",
"NRF_UART_PSEL_DISCONNECTED",
")",
"{",
"nrf_gpio_pin_set",
"(",
"uart_object",
"->",
"tx",
")",
";",
"nrf_gpio_cfg_output",
"(",
"uart_object",
"->",
"tx",
")",
";",
"}",
"if",
"(",
"uart_object",
"->",
"rx",
"!=",
"NRF_UART_PSEL_DISCONNECTED",
")",
"{",
"nrf_gpio_cfg_input",
"(",
"uart_object",
"->",
"rx",
",",
"NRF_GPIO_PIN_NOPULL",
")",
";",
"}",
"nrf_uarte_txrx_pins_set",
"(",
"nordic_nrf5_uart_register",
"[",
"uart_object",
"->",
"instance",
"]",
",",
"uart_object",
"->",
"tx",
",",
"uart_object",
"->",
"rx",
")",
";",
"if",
"(",
"uart_object",
"->",
"hwfc",
"==",
"NRF_UART_HWFC_ENABLED",
")",
"{",
"if",
"(",
"uart_object",
"->",
"cts",
"!=",
"NRF_UART_PSEL_DISCONNECTED",
")",
"{",
"nrf_gpio_cfg_input",
"(",
"uart_object",
"->",
"cts",
",",
"NRF_GPIO_PIN_NOPULL",
")",
";",
"}",
"nrf_uarte_hwfc_pins_set",
"(",
"nordic_nrf5_uart_register",
"[",
"uart_object",
"->",
"instance",
"]",
",",
"NRF_UART_PSEL_DISCONNECTED",
",",
"uart_object",
"->",
"cts",
")",
";",
"}",
"if",
"(",
"uart_object",
"->",
"rts",
"!=",
"nordic_nrf5_uart_state",
"[",
"uart_object",
"->",
"instance",
"]",
".",
"rts",
")",
"{",
"uint32_t",
"ret",
";",
"ret",
"=",
"nrfx_ppi_channel_disable",
"(",
"nordic_nrf5_uart_state",
"[",
"uart_object",
"->",
"instance",
"]",
".",
"ppi_rts",
")",
";",
"MBED_ASSERT",
"(",
"ret",
"==",
"NRF_SUCCESS",
")",
";",
"if",
"(",
"nordic_nrf5_uart_state",
"[",
"uart_object",
"->",
"instance",
"]",
".",
"rts",
"!=",
"NRF_UART_PSEL_DISCONNECTED",
")",
"{",
"nrfx_gpiote_out_uninit",
"(",
"(",
"nrfx_gpiote_pin_t",
")",
"uart_object",
"->",
"rts",
")",
";",
"}",
"if",
"(",
"uart_object",
"->",
"rts",
"!=",
"NRF_UART_PSEL_DISCONNECTED",
")",
"{",
"static",
"const",
"nrfx_gpiote_out_config_t",
"config",
"=",
"{",
".",
"init_state",
"=",
"NRF_GPIOTE_INITIAL_VALUE_HIGH",
",",
".",
"task_pin",
"=",
"true",
",",
".",
"action",
"=",
"NRF_GPIOTE_POLARITY_LOTOHI",
"}",
";",
"ret",
"=",
"nrfx_gpiote_out_init",
"(",
"(",
"nrfx_gpiote_pin_t",
")",
"uart_object",
"->",
"rts",
",",
"&",
"config",
")",
";",
"if",
"(",
"ret",
"==",
"NRF_ERROR_INVALID_STATE",
")",
"{",
"nrfx_gpiote_out_uninit",
"(",
"(",
"nrfx_gpiote_pin_t",
")",
"uart_object",
"->",
"rts",
")",
";",
"ret",
"=",
"nrfx_gpiote_out_init",
"(",
"(",
"nrfx_gpiote_pin_t",
")",
"uart_object",
"->",
"rts",
",",
"&",
"config",
")",
";",
"}",
"MBED_ASSERT",
"(",
"ret",
"==",
"NRF_SUCCESS",
")",
";",
"ret",
"=",
"nrfx_ppi_channel_assign",
"(",
"nordic_nrf5_uart_state",
"[",
"uart_object",
"->",
"instance",
"]",
".",
"ppi_rts",
",",
"nrf_uarte_event_address_get",
"(",
"nordic_nrf5_uart_register",
"[",
"uart_object",
"->",
"instance",
"]",
",",
"NRF_UARTE_EVENT_ENDRX",
")",
",",
"nrfx_gpiote_out_task_addr_get",
"(",
"uart_object",
"->",
"rts",
")",
")",
";",
"MBED_ASSERT",
"(",
"ret",
"==",
"NRF_SUCCESS",
")",
";",
"ret",
"=",
"nrfx_ppi_channel_enable",
"(",
"nordic_nrf5_uart_state",
"[",
"uart_object",
"->",
"instance",
"]",
".",
"ppi_rts",
")",
";",
"MBED_ASSERT",
"(",
"ret",
"==",
"NRF_SUCCESS",
")",
";",
"nrfx_gpiote_out_task_enable",
"(",
"(",
"nrfx_gpiote_pin_t",
")",
"uart_object",
"->",
"rts",
")",
";",
"}",
"nordic_nrf5_uart_state",
"[",
"uart_object",
"->",
"instance",
"]",
".",
"rts",
"=",
"uart_object",
"->",
"rts",
";",
"}",
"nrf_uarte_configure",
"(",
"nordic_nrf5_uart_register",
"[",
"uart_object",
"->",
"instance",
"]",
",",
"(",
"nrf_uarte_parity_t",
")",
"uart_object",
"->",
"parity",
",",
"(",
"nrf_uarte_hwfc_t",
")",
"uart_object",
"->",
"hwfc",
")",
";",
"nrf_uarte_baudrate_set",
"(",
"nordic_nrf5_uart_register",
"[",
"uart_object",
"->",
"instance",
"]",
",",
"(",
"nrf_uarte_baudrate_t",
")",
"uart_object",
"->",
"baudrate",
")",
";",
"}"
] | @brief Configure UARTE based on serial object settings. | [
"@brief",
"Configure",
"UARTE",
"based",
"on",
"serial",
"object",
"settings",
"."
] | [
"/* Configure Tx and Rx pins. */",
"/* Set hardware flow control pins. */",
"/* Check if pin is set before configuring it. */",
"/* Only let UARTE module handle CTS, RTS is handled manually due to buggy UARTE logic. */",
"/* Check if the rts pin changed */",
"/* Disable the PPI interconnect */",
"/* Free flow control gpiote pin if it was previously set */",
"/* Allocate and enable flow control gpiote pin if it is being used */",
"/* Allocate gpiote channel */",
"/* Pin was previously set to GPIO so uninitialize it */",
"/* Set RTS high on the ENDRX event */",
"/* Enable gpiote task - rts pin can no longer be used as GPIO at this point */",
"/* Enable flow control and parity. */",
"/* Set baudrate. */"
] | [
{
"param": "obj",
"type": "serial_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | nordic_nrf5_uart_configure_rx_asynch | void | static void nordic_nrf5_uart_configure_rx_asynch(int instance)
{
/* Disable Rx related interrupts. */
nrf_uarte_int_disable(nordic_nrf5_uart_register[instance], NRF_UARTE_INT_RXSTARTED_MASK |
NRF_UARTE_INT_ENDRX_MASK);
/* Clear Rx related events. */
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_RXSTARTED);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDRX);
/* Disable shortcut. Next Rx buffer must be manually started. */
nrf_uarte_shorts_disable(nordic_nrf5_uart_register[instance], NRF_UARTE_SHORT_ENDRX_STARTRX);
/* Set asynchronous mode. */
nordic_nrf5_uart_state[instance].rx_asynch = true;
/* Clear suspend condition */
nordic_nrf5_uart_state[instance].rx_suspended = false;
/* Enable Rx interrupt. */
nrf_uarte_int_enable(nordic_nrf5_uart_register[instance], NRF_UARTE_INT_ENDRX_MASK);
} | /**
* @brief Setup asynchronous reception.
*
* @param[in] instance The instance
*/ | @brief Setup asynchronous reception.
@param[in] instance The instance | [
"@brief",
"Setup",
"asynchronous",
"reception",
".",
"@param",
"[",
"in",
"]",
"instance",
"The",
"instance"
] | static void nordic_nrf5_uart_configure_rx_asynch(int instance)
{
nrf_uarte_int_disable(nordic_nrf5_uart_register[instance], NRF_UARTE_INT_RXSTARTED_MASK |
NRF_UARTE_INT_ENDRX_MASK);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_RXSTARTED);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDRX);
nrf_uarte_shorts_disable(nordic_nrf5_uart_register[instance], NRF_UARTE_SHORT_ENDRX_STARTRX);
nordic_nrf5_uart_state[instance].rx_asynch = true;
nordic_nrf5_uart_state[instance].rx_suspended = false;
nrf_uarte_int_enable(nordic_nrf5_uart_register[instance], NRF_UARTE_INT_ENDRX_MASK);
} | [
"static",
"void",
"nordic_nrf5_uart_configure_rx_asynch",
"(",
"int",
"instance",
")",
"{",
"nrf_uarte_int_disable",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_INT_RXSTARTED_MASK",
"|",
"NRF_UARTE_INT_ENDRX_MASK",
")",
";",
"nrf_uarte_event_clear",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_RXSTARTED",
")",
";",
"nrf_uarte_event_clear",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_ENDRX",
")",
";",
"nrf_uarte_shorts_disable",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_SHORT_ENDRX_STARTRX",
")",
";",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"rx_asynch",
"=",
"true",
";",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"rx_suspended",
"=",
"false",
";",
"nrf_uarte_int_enable",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_INT_ENDRX_MASK",
")",
";",
"}"
] | @brief Setup asynchronous reception. | [
"@brief",
"Setup",
"asynchronous",
"reception",
"."
] | [
"/* Disable Rx related interrupts. */",
"/* Clear Rx related events. */",
"/* Disable shortcut. Next Rx buffer must be manually started. */",
"/* Set asynchronous mode. */",
"/* Clear suspend condition */",
"/* Enable Rx interrupt. */"
] | [
{
"param": "instance",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "instance",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_init | void | void serial_init(serial_t *obj, PinName tx, PinName rx)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
/* Only initialize on first call. */
static bool first_init = true;
if (first_init) {
uint32_t ret;
first_init = false;
/* Initialize components that serial relies on. */
if (!nrfx_gpiote_is_init()) {
nrfx_gpiote_init();
}
/* Enable interrupts for SWI. */
NVIC_SetVector(SWI0_EGU0_IRQn, (uint32_t) nordic_nrf5_uart_swi0);
NRFX_IRQ_PRIORITY_SET(SWI0_EGU0_IRQn, APP_IRQ_PRIORITY_LOWEST);
NRFX_IRQ_ENABLE(SWI0_EGU0_IRQn);
/* Initialize FIFO buffer for UARTE0. */
NRF_ATFIFO_INIT(nordic_nrf5_uart_fifo_0);
nordic_nrf5_uart_state[0].fifo = nordic_nrf5_uart_fifo_0;
/* Initialize owner to NULL. */
nordic_nrf5_uart_state[0].owner = NULL;
/* Allocate a PPI channel for flow control */
ret = nrfx_ppi_channel_alloc(&nordic_nrf5_uart_state[0].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
/* Clear RTS */
nordic_nrf5_uart_state[0].rts = NRF_UART_PSEL_DISCONNECTED;
/* Clear any old events and enable interrupts for UARTE0. */
nrf_uarte_int_disable(nordic_nrf5_uart_register[0], 0xFFFFFFFF);
NVIC_SetVector(UARTE0_UART0_IRQn, (uint32_t) nordic_nrf5_uart0_handler);
NRFX_IRQ_PRIORITY_SET(UARTE0_UART0_IRQn, APP_IRQ_PRIORITY_HIGHEST);
NRFX_IRQ_ENABLE(UARTE0_UART0_IRQn);
#if UART1_ENABLED
/* Initialize FIFO buffer for UARTE1. */
NRF_ATFIFO_INIT(nordic_nrf5_uart_fifo_1);
nordic_nrf5_uart_state[1].fifo = nordic_nrf5_uart_fifo_1;
/* Initialize owner to NULL. */
nordic_nrf5_uart_state[1].owner = NULL;
/* Allocate a PPI channel for flow control */
ret = nrfx_ppi_channel_alloc(&nordic_nrf5_uart_state[1].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
/* Clear RTS */
nordic_nrf5_uart_state[1].rts = NRF_UART_PSEL_DISCONNECTED;
/* Clear any old events and enable interrupts for UARTE1. */
nrf_uarte_int_disable(nordic_nrf5_uart_register[1], 0xFFFFFFFF);
NVIC_SetVector(UARTE1_IRQn, (uint32_t) nordic_nrf5_uart1_handler);
NRFX_IRQ_PRIORITY_SET(UARTE1_IRQn, APP_IRQ_PRIORITY_HIGHEST);
NRFX_IRQ_ENABLE(UARTE1_IRQn);
#endif
}
/* Get instance ID based on provided pins. */
int instance = pin_instance_uart(tx, rx);
uart_object->instance = instance;
/* Increment usage counter for this instance. */
nordic_nrf5_uart_state[instance].usage_counter++;
/* Enable instance on first usage. */
if (nordic_nrf5_uart_state[instance].usage_counter == 1) {
nrf_uarte_enable(nordic_nrf5_uart_register[instance]);
/* In order to support printing with interrupts disabled serial_putc
* must busy wait on NRF_UARTE_EVENT_TXDRDY. This event cannot be set
* manually but must be set by the UARTE module after a character has
* been sent.
*
* The following code sends a dummy character into the void so that
* NRF_UARTE_EVENT_TXDRDY is correctly set.
*/
/* Ensure pins are disconnected. */
nrf_uarte_txrx_pins_set(nordic_nrf5_uart_register[instance],
NRF_UART_PSEL_DISCONNECTED,
NRF_UART_PSEL_DISCONNECTED);
/* Set maximum baud rate to minimize waiting. */
nrf_uarte_baudrate_set(nordic_nrf5_uart_register[instance],
NRF_UARTE_BAUDRATE_1000000);
/* Send character. */
nrf_uarte_tx_buffer_set(nordic_nrf5_uart_register[instance],
&nordic_nrf5_uart_state[instance].tx_data,
1);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDTX);
nrf_uarte_task_trigger(nordic_nrf5_uart_register[instance], NRF_UARTE_TASK_STARTTX);
/* Wait until NRF_UARTE_EVENT_TXDRDY is set before proceeding. */
bool done = false;
do {
done = nrf_uarte_event_check(nordic_nrf5_uart_register[instance],
(nrf_uarte_event_t) NRF_UARTE_EVENT_TXDRDY);
} while(done == false);
}
/* Store pins in serial object. */
if (tx == NC) {
uart_object->tx = NRF_UART_PSEL_DISCONNECTED;
} else {
uart_object->tx = tx;
}
if (rx == NC) {
uart_object->rx = NRF_UART_PSEL_DISCONNECTED;
} else {
uart_object->rx = rx;
}
/* Set default parity, baud rate, and callback handler. */
uart_object->parity = NRF_UART_PARITY_EXCLUDED;
uart_object->baudrate = NRF_UART_BAUDRATE_9600;
uart_object->cts = NRF_UART_PSEL_DISCONNECTED;
uart_object->rts = NRF_UART_PSEL_DISCONNECTED;
uart_object->hwfc = NRF_UART_HWFC_DISABLED;
uart_object->handler = 0;
/* The STDIO object is stored in this file. Set the flag once initialized. */
if (obj == &stdio_uart) {
stdio_uart_inited = 1;
}
/* Take ownership and configure UART. */
uart_object->update = true;
nordic_nrf5_serial_configure(obj);
} | /** Initialize the serial peripheral. It sets the default parameters for serial
* peripheral, and configures its specifieds pins.
*
* Param obj The serial object
* Param tx The TX pin name
* Param rx The RX pin name
*/ | Initialize the serial peripheral. It sets the default parameters for serial
peripheral, and configures its specifieds pins.
Param obj The serial object
Param tx The TX pin name
Param rx The RX pin name | [
"Initialize",
"the",
"serial",
"peripheral",
".",
"It",
"sets",
"the",
"default",
"parameters",
"for",
"serial",
"peripheral",
"and",
"configures",
"its",
"specifieds",
"pins",
".",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"tx",
"The",
"TX",
"pin",
"name",
"Param",
"rx",
"The",
"RX",
"pin",
"name"
] | void serial_init(serial_t *obj, PinName tx, PinName rx)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
static bool first_init = true;
if (first_init) {
uint32_t ret;
first_init = false;
if (!nrfx_gpiote_is_init()) {
nrfx_gpiote_init();
}
NVIC_SetVector(SWI0_EGU0_IRQn, (uint32_t) nordic_nrf5_uart_swi0);
NRFX_IRQ_PRIORITY_SET(SWI0_EGU0_IRQn, APP_IRQ_PRIORITY_LOWEST);
NRFX_IRQ_ENABLE(SWI0_EGU0_IRQn);
NRF_ATFIFO_INIT(nordic_nrf5_uart_fifo_0);
nordic_nrf5_uart_state[0].fifo = nordic_nrf5_uart_fifo_0;
nordic_nrf5_uart_state[0].owner = NULL;
ret = nrfx_ppi_channel_alloc(&nordic_nrf5_uart_state[0].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
nordic_nrf5_uart_state[0].rts = NRF_UART_PSEL_DISCONNECTED;
nrf_uarte_int_disable(nordic_nrf5_uart_register[0], 0xFFFFFFFF);
NVIC_SetVector(UARTE0_UART0_IRQn, (uint32_t) nordic_nrf5_uart0_handler);
NRFX_IRQ_PRIORITY_SET(UARTE0_UART0_IRQn, APP_IRQ_PRIORITY_HIGHEST);
NRFX_IRQ_ENABLE(UARTE0_UART0_IRQn);
#if UART1_ENABLED
NRF_ATFIFO_INIT(nordic_nrf5_uart_fifo_1);
nordic_nrf5_uart_state[1].fifo = nordic_nrf5_uart_fifo_1;
nordic_nrf5_uart_state[1].owner = NULL;
ret = nrfx_ppi_channel_alloc(&nordic_nrf5_uart_state[1].ppi_rts);
MBED_ASSERT(ret == NRF_SUCCESS);
nordic_nrf5_uart_state[1].rts = NRF_UART_PSEL_DISCONNECTED;
nrf_uarte_int_disable(nordic_nrf5_uart_register[1], 0xFFFFFFFF);
NVIC_SetVector(UARTE1_IRQn, (uint32_t) nordic_nrf5_uart1_handler);
NRFX_IRQ_PRIORITY_SET(UARTE1_IRQn, APP_IRQ_PRIORITY_HIGHEST);
NRFX_IRQ_ENABLE(UARTE1_IRQn);
#endif
}
int instance = pin_instance_uart(tx, rx);
uart_object->instance = instance;
nordic_nrf5_uart_state[instance].usage_counter++;
if (nordic_nrf5_uart_state[instance].usage_counter == 1) {
nrf_uarte_enable(nordic_nrf5_uart_register[instance]);
nrf_uarte_txrx_pins_set(nordic_nrf5_uart_register[instance],
NRF_UART_PSEL_DISCONNECTED,
NRF_UART_PSEL_DISCONNECTED);
nrf_uarte_baudrate_set(nordic_nrf5_uart_register[instance],
NRF_UARTE_BAUDRATE_1000000);
nrf_uarte_tx_buffer_set(nordic_nrf5_uart_register[instance],
&nordic_nrf5_uart_state[instance].tx_data,
1);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDTX);
nrf_uarte_task_trigger(nordic_nrf5_uart_register[instance], NRF_UARTE_TASK_STARTTX);
bool done = false;
do {
done = nrf_uarte_event_check(nordic_nrf5_uart_register[instance],
(nrf_uarte_event_t) NRF_UARTE_EVENT_TXDRDY);
} while(done == false);
}
if (tx == NC) {
uart_object->tx = NRF_UART_PSEL_DISCONNECTED;
} else {
uart_object->tx = tx;
}
if (rx == NC) {
uart_object->rx = NRF_UART_PSEL_DISCONNECTED;
} else {
uart_object->rx = rx;
}
uart_object->parity = NRF_UART_PARITY_EXCLUDED;
uart_object->baudrate = NRF_UART_BAUDRATE_9600;
uart_object->cts = NRF_UART_PSEL_DISCONNECTED;
uart_object->rts = NRF_UART_PSEL_DISCONNECTED;
uart_object->hwfc = NRF_UART_HWFC_DISABLED;
uart_object->handler = 0;
if (obj == &stdio_uart) {
stdio_uart_inited = 1;
}
uart_object->update = true;
nordic_nrf5_serial_configure(obj);
} | [
"void",
"serial_init",
"(",
"serial_t",
"*",
"obj",
",",
"PinName",
"tx",
",",
"PinName",
"rx",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"static",
"bool",
"first_init",
"=",
"true",
";",
"if",
"(",
"first_init",
")",
"{",
"uint32_t",
"ret",
";",
"first_init",
"=",
"false",
";",
"if",
"(",
"!",
"nrfx_gpiote_is_init",
"(",
")",
")",
"{",
"nrfx_gpiote_init",
"(",
")",
";",
"}",
"NVIC_SetVector",
"(",
"SWI0_EGU0_IRQn",
",",
"(",
"uint32_t",
")",
"nordic_nrf5_uart_swi0",
")",
";",
"NRFX_IRQ_PRIORITY_SET",
"(",
"SWI0_EGU0_IRQn",
",",
"APP_IRQ_PRIORITY_LOWEST",
")",
";",
"NRFX_IRQ_ENABLE",
"(",
"SWI0_EGU0_IRQn",
")",
";",
"NRF_ATFIFO_INIT",
"(",
"nordic_nrf5_uart_fifo_0",
")",
";",
"nordic_nrf5_uart_state",
"[",
"0",
"]",
".",
"fifo",
"=",
"nordic_nrf5_uart_fifo_0",
";",
"nordic_nrf5_uart_state",
"[",
"0",
"]",
".",
"owner",
"=",
"NULL",
";",
"ret",
"=",
"nrfx_ppi_channel_alloc",
"(",
"&",
"nordic_nrf5_uart_state",
"[",
"0",
"]",
".",
"ppi_rts",
")",
";",
"MBED_ASSERT",
"(",
"ret",
"==",
"NRF_SUCCESS",
")",
";",
"nordic_nrf5_uart_state",
"[",
"0",
"]",
".",
"rts",
"=",
"NRF_UART_PSEL_DISCONNECTED",
";",
"nrf_uarte_int_disable",
"(",
"nordic_nrf5_uart_register",
"[",
"0",
"]",
",",
"0xFFFFFFFF",
")",
";",
"NVIC_SetVector",
"(",
"UARTE0_UART0_IRQn",
",",
"(",
"uint32_t",
")",
"nordic_nrf5_uart0_handler",
")",
";",
"NRFX_IRQ_PRIORITY_SET",
"(",
"UARTE0_UART0_IRQn",
",",
"APP_IRQ_PRIORITY_HIGHEST",
")",
";",
"NRFX_IRQ_ENABLE",
"(",
"UARTE0_UART0_IRQn",
")",
";",
"#if",
"UART1_ENABLED",
"\n",
"NRF_ATFIFO_INIT",
"(",
"nordic_nrf5_uart_fifo_1",
")",
";",
"nordic_nrf5_uart_state",
"[",
"1",
"]",
".",
"fifo",
"=",
"nordic_nrf5_uart_fifo_1",
";",
"nordic_nrf5_uart_state",
"[",
"1",
"]",
".",
"owner",
"=",
"NULL",
";",
"ret",
"=",
"nrfx_ppi_channel_alloc",
"(",
"&",
"nordic_nrf5_uart_state",
"[",
"1",
"]",
".",
"ppi_rts",
")",
";",
"MBED_ASSERT",
"(",
"ret",
"==",
"NRF_SUCCESS",
")",
";",
"nordic_nrf5_uart_state",
"[",
"1",
"]",
".",
"rts",
"=",
"NRF_UART_PSEL_DISCONNECTED",
";",
"nrf_uarte_int_disable",
"(",
"nordic_nrf5_uart_register",
"[",
"1",
"]",
",",
"0xFFFFFFFF",
")",
";",
"NVIC_SetVector",
"(",
"UARTE1_IRQn",
",",
"(",
"uint32_t",
")",
"nordic_nrf5_uart1_handler",
")",
";",
"NRFX_IRQ_PRIORITY_SET",
"(",
"UARTE1_IRQn",
",",
"APP_IRQ_PRIORITY_HIGHEST",
")",
";",
"NRFX_IRQ_ENABLE",
"(",
"UARTE1_IRQn",
")",
";",
"#endif",
"}",
"int",
"instance",
"=",
"pin_instance_uart",
"(",
"tx",
",",
"rx",
")",
";",
"uart_object",
"->",
"instance",
"=",
"instance",
";",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"usage_counter",
"++",
";",
"if",
"(",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"usage_counter",
"==",
"1",
")",
"{",
"nrf_uarte_enable",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
")",
";",
"nrf_uarte_txrx_pins_set",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UART_PSEL_DISCONNECTED",
",",
"NRF_UART_PSEL_DISCONNECTED",
")",
";",
"nrf_uarte_baudrate_set",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_BAUDRATE_1000000",
")",
";",
"nrf_uarte_tx_buffer_set",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"&",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"tx_data",
",",
"1",
")",
";",
"nrf_uarte_event_clear",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_ENDTX",
")",
";",
"nrf_uarte_task_trigger",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_TASK_STARTTX",
")",
";",
"bool",
"done",
"=",
"false",
";",
"do",
"{",
"done",
"=",
"nrf_uarte_event_check",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"(",
"nrf_uarte_event_t",
")",
"NRF_UARTE_EVENT_TXDRDY",
")",
";",
"}",
"while",
"(",
"done",
"==",
"false",
")",
";",
"}",
"if",
"(",
"tx",
"==",
"NC",
")",
"{",
"uart_object",
"->",
"tx",
"=",
"NRF_UART_PSEL_DISCONNECTED",
";",
"}",
"else",
"{",
"uart_object",
"->",
"tx",
"=",
"tx",
";",
"}",
"if",
"(",
"rx",
"==",
"NC",
")",
"{",
"uart_object",
"->",
"rx",
"=",
"NRF_UART_PSEL_DISCONNECTED",
";",
"}",
"else",
"{",
"uart_object",
"->",
"rx",
"=",
"rx",
";",
"}",
"uart_object",
"->",
"parity",
"=",
"NRF_UART_PARITY_EXCLUDED",
";",
"uart_object",
"->",
"baudrate",
"=",
"NRF_UART_BAUDRATE_9600",
";",
"uart_object",
"->",
"cts",
"=",
"NRF_UART_PSEL_DISCONNECTED",
";",
"uart_object",
"->",
"rts",
"=",
"NRF_UART_PSEL_DISCONNECTED",
";",
"uart_object",
"->",
"hwfc",
"=",
"NRF_UART_HWFC_DISABLED",
";",
"uart_object",
"->",
"handler",
"=",
"0",
";",
"if",
"(",
"obj",
"==",
"&",
"stdio_uart",
")",
"{",
"stdio_uart_inited",
"=",
"1",
";",
"}",
"uart_object",
"->",
"update",
"=",
"true",
";",
"nordic_nrf5_serial_configure",
"(",
"obj",
")",
";",
"}"
] | Initialize the serial peripheral. | [
"Initialize",
"the",
"serial",
"peripheral",
"."
] | [
"/* Only initialize on first call. */",
"/* Initialize components that serial relies on. */",
"/* Enable interrupts for SWI. */",
"/* Initialize FIFO buffer for UARTE0. */",
"/* Initialize owner to NULL. */",
"/* Allocate a PPI channel for flow control */",
"/* Clear RTS */",
"/* Clear any old events and enable interrupts for UARTE0. */",
"/* Initialize FIFO buffer for UARTE1. */",
"/* Initialize owner to NULL. */",
"/* Allocate a PPI channel for flow control */",
"/* Clear RTS */",
"/* Clear any old events and enable interrupts for UARTE1. */",
"/* Get instance ID based on provided pins. */",
"/* Increment usage counter for this instance. */",
"/* Enable instance on first usage. */",
"/* In order to support printing with interrupts disabled serial_putc\n * must busy wait on NRF_UARTE_EVENT_TXDRDY. This event cannot be set\n * manually but must be set by the UARTE module after a character has\n * been sent.\n *\n * The following code sends a dummy character into the void so that\n * NRF_UARTE_EVENT_TXDRDY is correctly set.\n */",
"/* Ensure pins are disconnected. */",
"/* Set maximum baud rate to minimize waiting. */",
"/* Send character. */",
"/* Wait until NRF_UARTE_EVENT_TXDRDY is set before proceeding. */",
"/* Store pins in serial object. */",
"/* Set default parity, baud rate, and callback handler. */",
"/* The STDIO object is stored in this file. Set the flag once initialized. */",
"/* Take ownership and configure UART. */"
] | [
{
"param": "obj",
"type": "serial_t"
},
{
"param": "tx",
"type": "PinName"
},
{
"param": "rx",
"type": "PinName"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "tx",
"type": "PinName",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rx",
"type": "PinName",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_baud | void | void serial_baud(serial_t *obj, int baudrate)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
nrf_uarte_baudrate_t new_rate = NRF_UART_BAUDRATE_9600;
/* Round down to nearest supported baud rate. */
if (baudrate < 2400) {
new_rate = NRF_UARTE_BAUDRATE_1200;
} else if (baudrate < 4800) {
new_rate = NRF_UARTE_BAUDRATE_2400;
} else if (baudrate < 9600) {
new_rate = NRF_UARTE_BAUDRATE_4800;
} else if (baudrate < 14400) {
new_rate = NRF_UARTE_BAUDRATE_9600;
} else if (baudrate < 19200) {
new_rate = NRF_UARTE_BAUDRATE_14400;
} else if (baudrate < 28800) {
new_rate = NRF_UARTE_BAUDRATE_19200;
} else if (baudrate < 38400) {
new_rate = NRF_UARTE_BAUDRATE_28800;
} else if (baudrate < 57600) {
new_rate = NRF_UARTE_BAUDRATE_38400;
} else if (baudrate < 76800) {
new_rate = NRF_UARTE_BAUDRATE_57600;
} else if (baudrate < 115200) {
new_rate = NRF_UARTE_BAUDRATE_76800;
} else if (baudrate < 230400) {
new_rate = NRF_UARTE_BAUDRATE_115200;
} else if (baudrate < 250000) {
new_rate = NRF_UARTE_BAUDRATE_230400;
} else if (baudrate < 460800) {
new_rate = NRF_UARTE_BAUDRATE_250000;
} else if (baudrate < 921600) {
new_rate = NRF_UARTE_BAUDRATE_460800;
} else if (baudrate < 1000000) {
new_rate = NRF_UARTE_BAUDRATE_921600;
} else {
new_rate = NRF_UARTE_BAUDRATE_1000000;
}
/* Force reconfiguration next time serial object is owner if baud rate has changed. */
if (uart_object->baudrate != new_rate) {
uart_object->baudrate = new_rate;
uart_object->update = true;
}
} | /** Configure the baud rate
*
* Param obj The serial object
* Param baudrate The baud rate to be configured
*/ | Configure the baud rate
Param obj The serial object
Param baudrate The baud rate to be configured | [
"Configure",
"the",
"baud",
"rate",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"baudrate",
"The",
"baud",
"rate",
"to",
"be",
"configured"
] | void serial_baud(serial_t *obj, int baudrate)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
nrf_uarte_baudrate_t new_rate = NRF_UART_BAUDRATE_9600;
if (baudrate < 2400) {
new_rate = NRF_UARTE_BAUDRATE_1200;
} else if (baudrate < 4800) {
new_rate = NRF_UARTE_BAUDRATE_2400;
} else if (baudrate < 9600) {
new_rate = NRF_UARTE_BAUDRATE_4800;
} else if (baudrate < 14400) {
new_rate = NRF_UARTE_BAUDRATE_9600;
} else if (baudrate < 19200) {
new_rate = NRF_UARTE_BAUDRATE_14400;
} else if (baudrate < 28800) {
new_rate = NRF_UARTE_BAUDRATE_19200;
} else if (baudrate < 38400) {
new_rate = NRF_UARTE_BAUDRATE_28800;
} else if (baudrate < 57600) {
new_rate = NRF_UARTE_BAUDRATE_38400;
} else if (baudrate < 76800) {
new_rate = NRF_UARTE_BAUDRATE_57600;
} else if (baudrate < 115200) {
new_rate = NRF_UARTE_BAUDRATE_76800;
} else if (baudrate < 230400) {
new_rate = NRF_UARTE_BAUDRATE_115200;
} else if (baudrate < 250000) {
new_rate = NRF_UARTE_BAUDRATE_230400;
} else if (baudrate < 460800) {
new_rate = NRF_UARTE_BAUDRATE_250000;
} else if (baudrate < 921600) {
new_rate = NRF_UARTE_BAUDRATE_460800;
} else if (baudrate < 1000000) {
new_rate = NRF_UARTE_BAUDRATE_921600;
} else {
new_rate = NRF_UARTE_BAUDRATE_1000000;
}
if (uart_object->baudrate != new_rate) {
uart_object->baudrate = new_rate;
uart_object->update = true;
}
} | [
"void",
"serial_baud",
"(",
"serial_t",
"*",
"obj",
",",
"int",
"baudrate",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"nrf_uarte_baudrate_t",
"new_rate",
"=",
"NRF_UART_BAUDRATE_9600",
";",
"if",
"(",
"baudrate",
"<",
"2400",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_1200",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"4800",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_2400",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"9600",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_4800",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"14400",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_9600",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"19200",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_14400",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"28800",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_19200",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"38400",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_28800",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"57600",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_38400",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"76800",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_57600",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"115200",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_76800",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"230400",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_115200",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"250000",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_230400",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"460800",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_250000",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"921600",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_460800",
";",
"}",
"else",
"if",
"(",
"baudrate",
"<",
"1000000",
")",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_921600",
";",
"}",
"else",
"{",
"new_rate",
"=",
"NRF_UARTE_BAUDRATE_1000000",
";",
"}",
"if",
"(",
"uart_object",
"->",
"baudrate",
"!=",
"new_rate",
")",
"{",
"uart_object",
"->",
"baudrate",
"=",
"new_rate",
";",
"uart_object",
"->",
"update",
"=",
"true",
";",
"}",
"}"
] | Configure the baud rate
Param obj The serial object
Param baudrate The baud rate to be configured | [
"Configure",
"the",
"baud",
"rate",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"baudrate",
"The",
"baud",
"rate",
"to",
"be",
"configured"
] | [
"/* Round down to nearest supported baud rate. */",
"/* Force reconfiguration next time serial object is owner if baud rate has changed. */"
] | [
{
"param": "obj",
"type": "serial_t"
},
{
"param": "baudrate",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "baudrate",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_format | void | void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
{
MBED_ASSERT(obj);
/**
* Only 8-bit mode, None/Even parity, and 1 stop bit supported by hardware.
*/
MBED_ASSERT(data_bits == 8);
MBED_ASSERT((parity == ParityNone) || (parity == ParityEven));
MBED_ASSERT(stop_bits == 1);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
/**
* Only force change if parity has changed.
*/
if ((uart_object->parity != NRF_UART_PARITY_EXCLUDED) && (parity == ParityNone)) {
uart_object->parity = NRF_UART_PARITY_EXCLUDED;
uart_object->update = true;
} else if ((uart_object->parity != NRF_UART_PARITY_INCLUDED) && (parity == ParityEven)) {
uart_object->parity = NRF_UART_PARITY_INCLUDED;
uart_object->update = true;
}
} | /** Configure the format. Set the number of bits, parity and the number of stop bits
*
* Param obj The serial object
* Param data_bits The number of data bits
* Param parity The parity
* Param stop_bits The number of stop bits
*/ | Configure the format. Set the number of bits, parity and the number of stop bits
Param obj The serial object
Param data_bits The number of data bits
Param parity The parity
Param stop_bits The number of stop bits | [
"Configure",
"the",
"format",
".",
"Set",
"the",
"number",
"of",
"bits",
"parity",
"and",
"the",
"number",
"of",
"stop",
"bits",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"data_bits",
"The",
"number",
"of",
"data",
"bits",
"Param",
"parity",
"The",
"parity",
"Param",
"stop_bits",
"The",
"number",
"of",
"stop",
"bits"
] | void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits)
{
MBED_ASSERT(obj);
MBED_ASSERT(data_bits == 8);
MBED_ASSERT((parity == ParityNone) || (parity == ParityEven));
MBED_ASSERT(stop_bits == 1);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
if ((uart_object->parity != NRF_UART_PARITY_EXCLUDED) && (parity == ParityNone)) {
uart_object->parity = NRF_UART_PARITY_EXCLUDED;
uart_object->update = true;
} else if ((uart_object->parity != NRF_UART_PARITY_INCLUDED) && (parity == ParityEven)) {
uart_object->parity = NRF_UART_PARITY_INCLUDED;
uart_object->update = true;
}
} | [
"void",
"serial_format",
"(",
"serial_t",
"*",
"obj",
",",
"int",
"data_bits",
",",
"SerialParity",
"parity",
",",
"int",
"stop_bits",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"MBED_ASSERT",
"(",
"data_bits",
"==",
"8",
")",
";",
"MBED_ASSERT",
"(",
"(",
"parity",
"==",
"ParityNone",
")",
"||",
"(",
"parity",
"==",
"ParityEven",
")",
")",
";",
"MBED_ASSERT",
"(",
"stop_bits",
"==",
"1",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"if",
"(",
"(",
"uart_object",
"->",
"parity",
"!=",
"NRF_UART_PARITY_EXCLUDED",
")",
"&&",
"(",
"parity",
"==",
"ParityNone",
")",
")",
"{",
"uart_object",
"->",
"parity",
"=",
"NRF_UART_PARITY_EXCLUDED",
";",
"uart_object",
"->",
"update",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"(",
"uart_object",
"->",
"parity",
"!=",
"NRF_UART_PARITY_INCLUDED",
")",
"&&",
"(",
"parity",
"==",
"ParityEven",
")",
")",
"{",
"uart_object",
"->",
"parity",
"=",
"NRF_UART_PARITY_INCLUDED",
";",
"uart_object",
"->",
"update",
"=",
"true",
";",
"}",
"}"
] | Configure the format. | [
"Configure",
"the",
"format",
"."
] | [
"/**\n * Only 8-bit mode, None/Even parity, and 1 stop bit supported by hardware.\n */",
"/**\n * Only force change if parity has changed.\n */"
] | [
{
"param": "obj",
"type": "serial_t"
},
{
"param": "data_bits",
"type": "int"
},
{
"param": "parity",
"type": "SerialParity"
},
{
"param": "stop_bits",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "data_bits",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "parity",
"type": "SerialParity",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "stop_bits",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_set_flow_control | void | void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
/**
* Convert Mbed pin names to Nordic pin names.
*/
uart_object->cts = ((txflow == NC) || (type == FlowControlRTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t) txflow;
uart_object->rts = ((rxflow == NC) || (type == FlowControlCTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t) rxflow;
uart_object->hwfc = (type == FlowControlNone) ? NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
/* Force reconfiguration next time object is owner. */
uart_object->update = true;
nordic_nrf5_serial_configure(obj);
} | /** Configure the serial for the flow control. It sets flow control in the hardware
* if a serial peripheral supports it, otherwise software emulation is used.
*
* Param obj The serial object
* Param type The type of the flow control. Look at the available FlowControl types.
* Param rxflow The TX pin name
* Param txflow The RX pin name
*/ | Configure the serial for the flow control. It sets flow control in the hardware
if a serial peripheral supports it, otherwise software emulation is used.
Param obj The serial object
Param type The type of the flow control. Look at the available FlowControl types.
Param rxflow The TX pin name
Param txflow The RX pin name | [
"Configure",
"the",
"serial",
"for",
"the",
"flow",
"control",
".",
"It",
"sets",
"flow",
"control",
"in",
"the",
"hardware",
"if",
"a",
"serial",
"peripheral",
"supports",
"it",
"otherwise",
"software",
"emulation",
"is",
"used",
".",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"type",
"The",
"type",
"of",
"the",
"flow",
"control",
".",
"Look",
"at",
"the",
"available",
"FlowControl",
"types",
".",
"Param",
"rxflow",
"The",
"TX",
"pin",
"name",
"Param",
"txflow",
"The",
"RX",
"pin",
"name"
] | void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
uart_object->cts = ((txflow == NC) || (type == FlowControlRTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t) txflow;
uart_object->rts = ((rxflow == NC) || (type == FlowControlCTS)) ? NRF_UART_PSEL_DISCONNECTED : (uint32_t) rxflow;
uart_object->hwfc = (type == FlowControlNone) ? NRF_UART_HWFC_DISABLED : NRF_UART_HWFC_ENABLED;
uart_object->update = true;
nordic_nrf5_serial_configure(obj);
} | [
"void",
"serial_set_flow_control",
"(",
"serial_t",
"*",
"obj",
",",
"FlowControl",
"type",
",",
"PinName",
"rxflow",
",",
"PinName",
"txflow",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"uart_object",
"->",
"cts",
"=",
"(",
"(",
"txflow",
"==",
"NC",
")",
"||",
"(",
"type",
"==",
"FlowControlRTS",
")",
")",
"?",
"NRF_UART_PSEL_DISCONNECTED",
":",
"(",
"uint32_t",
")",
"txflow",
";",
"uart_object",
"->",
"rts",
"=",
"(",
"(",
"rxflow",
"==",
"NC",
")",
"||",
"(",
"type",
"==",
"FlowControlCTS",
")",
")",
"?",
"NRF_UART_PSEL_DISCONNECTED",
":",
"(",
"uint32_t",
")",
"rxflow",
";",
"uart_object",
"->",
"hwfc",
"=",
"(",
"type",
"==",
"FlowControlNone",
")",
"?",
"NRF_UART_HWFC_DISABLED",
":",
"NRF_UART_HWFC_ENABLED",
";",
"uart_object",
"->",
"update",
"=",
"true",
";",
"nordic_nrf5_serial_configure",
"(",
"obj",
")",
";",
"}"
] | Configure the serial for the flow control. | [
"Configure",
"the",
"serial",
"for",
"the",
"flow",
"control",
"."
] | [
"/**\n * Convert Mbed pin names to Nordic pin names.\n */",
"/* Force reconfiguration next time object is owner. */"
] | [
{
"param": "obj",
"type": "serial_t"
},
{
"param": "type",
"type": "FlowControl"
},
{
"param": "rxflow",
"type": "PinName"
},
{
"param": "txflow",
"type": "PinName"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "type",
"type": "FlowControl",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rxflow",
"type": "PinName",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "txflow",
"type": "PinName",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_irq_set | void | void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
/* Convert Mbed type to Nordic IRQ mask. */
uint32_t type = (irq == TxIrq) ? NORDIC_TX_IRQ : NORDIC_RX_IRQ;
/* Enable/disable interrupt bit mask. */
if (enable) {
uart_object->mask |= type;
nordic_nrf5_serial_configure(obj);
} else {
uart_object->mask &= ~type;
}
} | /** Configure serial interrupt. This function is used for word-approach
*
* Param obj The serial object
* Param irq The serial IRQ type (RX or TX)
* Param enable Set to non-zero to enable events, or zero to disable them
*/ | Configure serial interrupt. This function is used for word-approach
Param obj The serial object
Param irq The serial IRQ type (RX or TX)
Param enable Set to non-zero to enable events, or zero to disable them | [
"Configure",
"serial",
"interrupt",
".",
"This",
"function",
"is",
"used",
"for",
"word",
"-",
"approach",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"irq",
"The",
"serial",
"IRQ",
"type",
"(",
"RX",
"or",
"TX",
")",
"Param",
"enable",
"Set",
"to",
"non",
"-",
"zero",
"to",
"enable",
"events",
"or",
"zero",
"to",
"disable",
"them"
] | void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
uint32_t type = (irq == TxIrq) ? NORDIC_TX_IRQ : NORDIC_RX_IRQ;
if (enable) {
uart_object->mask |= type;
nordic_nrf5_serial_configure(obj);
} else {
uart_object->mask &= ~type;
}
} | [
"void",
"serial_irq_set",
"(",
"serial_t",
"*",
"obj",
",",
"SerialIrq",
"irq",
",",
"uint32_t",
"enable",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"uint32_t",
"type",
"=",
"(",
"irq",
"==",
"TxIrq",
")",
"?",
"NORDIC_TX_IRQ",
":",
"NORDIC_RX_IRQ",
";",
"if",
"(",
"enable",
")",
"{",
"uart_object",
"->",
"mask",
"|=",
"type",
";",
"nordic_nrf5_serial_configure",
"(",
"obj",
")",
";",
"}",
"else",
"{",
"uart_object",
"->",
"mask",
"&=",
"~",
"type",
";",
"}",
"}"
] | Configure serial interrupt. | [
"Configure",
"serial",
"interrupt",
"."
] | [
"/* Convert Mbed type to Nordic IRQ mask. */",
"/* Enable/disable interrupt bit mask. */"
] | [
{
"param": "obj",
"type": "serial_t"
},
{
"param": "irq",
"type": "SerialIrq"
},
{
"param": "enable",
"type": "uint32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "irq",
"type": "SerialIrq",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "enable",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_putc | void | void serial_putc(serial_t *obj, int character)
{
bool done = false;
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
int instance = uart_object->instance;
nordic_nrf5_serial_configure(obj);
/* Wait until UART is ready to send next character. */
do {
done = nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY);
} while(done == false);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY);
/* Arm Tx DMA buffer. */
nordic_nrf5_uart_state[instance].tx_data = character;
nrf_uarte_tx_buffer_set(nordic_nrf5_uart_register[instance],
&nordic_nrf5_uart_state[instance].tx_data,
1);
/* Clear Tx event and enable Tx interrupts. */
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDTX);
nrf_uarte_int_enable(nordic_nrf5_uart_register[instance], NRF_UARTE_INT_ENDTX_MASK);
/* Start transfer. */
nrf_uarte_task_trigger(nordic_nrf5_uart_register[instance], NRF_UARTE_TASK_STARTTX);
} | /** Send a character. This is a blocking call, waiting for a peripheral to be available
* for writing
*
* Param obj The serial object
* Param c The character to be sent
*/ | Send a character. This is a blocking call, waiting for a peripheral to be available
for writing
Param obj The serial object
Param c The character to be sent | [
"Send",
"a",
"character",
".",
"This",
"is",
"a",
"blocking",
"call",
"waiting",
"for",
"a",
"peripheral",
"to",
"be",
"available",
"for",
"writing",
"Param",
"obj",
"The",
"serial",
"object",
"Param",
"c",
"The",
"character",
"to",
"be",
"sent"
] | void serial_putc(serial_t *obj, int character)
{
bool done = false;
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
int instance = uart_object->instance;
nordic_nrf5_serial_configure(obj);
do {
done = nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY);
} while(done == false);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY);
nordic_nrf5_uart_state[instance].tx_data = character;
nrf_uarte_tx_buffer_set(nordic_nrf5_uart_register[instance],
&nordic_nrf5_uart_state[instance].tx_data,
1);
nrf_uarte_event_clear(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_ENDTX);
nrf_uarte_int_enable(nordic_nrf5_uart_register[instance], NRF_UARTE_INT_ENDTX_MASK);
nrf_uarte_task_trigger(nordic_nrf5_uart_register[instance], NRF_UARTE_TASK_STARTTX);
} | [
"void",
"serial_putc",
"(",
"serial_t",
"*",
"obj",
",",
"int",
"character",
")",
"{",
"bool",
"done",
"=",
"false",
";",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"int",
"instance",
"=",
"uart_object",
"->",
"instance",
";",
"nordic_nrf5_serial_configure",
"(",
"obj",
")",
";",
"do",
"{",
"done",
"=",
"nrf_uarte_event_check",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_TXDRDY",
")",
";",
"}",
"while",
"(",
"done",
"==",
"false",
")",
";",
"nrf_uarte_event_clear",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_TXDRDY",
")",
";",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"tx_data",
"=",
"character",
";",
"nrf_uarte_tx_buffer_set",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"&",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"tx_data",
",",
"1",
")",
";",
"nrf_uarte_event_clear",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_ENDTX",
")",
";",
"nrf_uarte_int_enable",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_INT_ENDTX_MASK",
")",
";",
"nrf_uarte_task_trigger",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_TASK_STARTTX",
")",
";",
"}"
] | Send a character. | [
"Send",
"a",
"character",
"."
] | [
"/* Wait until UART is ready to send next character. */",
"/* Arm Tx DMA buffer. */",
"/* Clear Tx event and enable Tx interrupts. */",
"/* Start transfer. */"
] | [
{
"param": "obj",
"type": "serial_t"
},
{
"param": "character",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "character",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ef142e6ba77e657a39eea7f04f3fdd77a6ba1f60 | shuopeng-deng/mbed-os | targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/serial_api.c | [
"Apache-2.0"
] | C | serial_writable | int | int serial_writable(serial_t *obj)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
int instance = uart_object->instance;
return (!core_util_atomic_load_bool(&nordic_nrf5_uart_state[instance].tx_in_progress) &&
(nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY)));
} | /** Check if the serial peripheral is writable
*
* Param obj The serial object
* Return Non-zero value if a character can be written, 0 otherwise.
*/ | Check if the serial peripheral is writable
Param obj The serial object
Return Non-zero value if a character can be written, 0 otherwise. | [
"Check",
"if",
"the",
"serial",
"peripheral",
"is",
"writable",
"Param",
"obj",
"The",
"serial",
"object",
"Return",
"Non",
"-",
"zero",
"value",
"if",
"a",
"character",
"can",
"be",
"written",
"0",
"otherwise",
"."
] | int serial_writable(serial_t *obj)
{
MBED_ASSERT(obj);
#if DEVICE_SERIAL_ASYNCH
struct serial_s *uart_object = &obj->serial;
#else
struct serial_s *uart_object = obj;
#endif
int instance = uart_object->instance;
return (!core_util_atomic_load_bool(&nordic_nrf5_uart_state[instance].tx_in_progress) &&
(nrf_uarte_event_check(nordic_nrf5_uart_register[instance], NRF_UARTE_EVENT_TXDRDY)));
} | [
"int",
"serial_writable",
"(",
"serial_t",
"*",
"obj",
")",
"{",
"MBED_ASSERT",
"(",
"obj",
")",
";",
"#if",
"DEVICE_SERIAL_ASYNCH",
"\n",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"&",
"obj",
"->",
"serial",
";",
"#else",
"struct",
"serial_s",
"*",
"uart_object",
"=",
"obj",
";",
"#endif",
"int",
"instance",
"=",
"uart_object",
"->",
"instance",
";",
"return",
"(",
"!",
"core_util_atomic_load_bool",
"(",
"&",
"nordic_nrf5_uart_state",
"[",
"instance",
"]",
".",
"tx_in_progress",
")",
"&&",
"(",
"nrf_uarte_event_check",
"(",
"nordic_nrf5_uart_register",
"[",
"instance",
"]",
",",
"NRF_UARTE_EVENT_TXDRDY",
")",
")",
")",
";",
"}"
] | Check if the serial peripheral is writable
Param obj The serial object
Return Non-zero value if a character can be written, 0 otherwise. | [
"Check",
"if",
"the",
"serial",
"peripheral",
"is",
"writable",
"Param",
"obj",
"The",
"serial",
"object",
"Return",
"Non",
"-",
"zero",
"value",
"if",
"a",
"character",
"can",
"be",
"written",
"0",
"otherwise",
"."
] | [] | [
{
"param": "obj",
"type": "serial_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "obj",
"type": "serial_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | overlap_handler_generate | void | void overlap_handler_generate(overlap_handler_t *olh, bam1_t *rec)
{
/* ptrs to current cigar ops */
uint32_t *read_cigar, *mate_cigar, *read_cigar_end, *mate_cigar_end;
int32_t read_rpos, mate_rpos;
/* if both read and mate have non-zero # of cigar ops */
if (rec->core.n_cigar > 0 && olh->n_mc_cigar) {
/* read and mate pos */
read_rpos = rec->core.pos;
mate_rpos = rec->core.mpos;
/* set read and mate start and end */
read_cigar = bam_get_cigar(rec);
read_cigar_end = read_cigar + rec->core.n_cigar;
mate_cigar = olh->mc_buffer;
mate_cigar_end = olh->mc_buffer + olh->n_mc_cigar;
/* advance to first coverage cigar */
_advance_to_coverage_cigar(&read_cigar, &read_cigar_end, &read_rpos);
_advance_to_coverage_cigar(&mate_cigar, &mate_cigar_end, &mate_rpos);
int32_t read_endrpos, mate_endrpos, overlap_start, overlap_end;
while (read_cigar != read_cigar_end &&
mate_cigar != mate_cigar_end)
{
read_endrpos = read_rpos + bam_cigar_oplen(*read_cigar);
mate_endrpos = mate_rpos + bam_cigar_oplen(*mate_cigar);
/* find overlap, add to overlap buffer, and advance cigars */
if (read_rpos < mate_rpos) {
/* record overlap */
if (mate_rpos < read_endrpos) {
overlap_start = mate_rpos;
overlap_end = (read_endrpos < mate_endrpos)? read_endrpos: mate_endrpos;
overlap_handler_add(olh, overlap_start, overlap_end);
}
/* advance read_cigar */
if (bam_cigar_type(*read_cigar) & 0x02) {
read_rpos += bam_cigar_oplen(*read_cigar);
}
++read_cigar;
_advance_to_coverage_cigar(&read_cigar, &read_cigar_end, &read_rpos);
} else {
/* record overlap */
if (read_rpos < mate_endrpos) {
overlap_start = read_rpos;
overlap_end = (mate_endrpos < read_endrpos)? mate_endrpos: read_endrpos;
overlap_handler_add(olh, overlap_start, overlap_end);
}
/* advance mate_cigar */
if (bam_cigar_type(*mate_cigar) & 0x02) {
mate_rpos += bam_cigar_oplen(*mate_cigar);
}
++mate_cigar;
_advance_to_coverage_cigar(&mate_cigar, &mate_cigar_end, &mate_rpos);
}
}
}
} | /* Generate overlap intervals for a read after loading mc_buffer with mc_buffer_load() */ | Generate overlap intervals for a read after loading mc_buffer with mc_buffer_load() | [
"Generate",
"overlap",
"intervals",
"for",
"a",
"read",
"after",
"loading",
"mc_buffer",
"with",
"mc_buffer_load",
"()"
] | void overlap_handler_generate(overlap_handler_t *olh, bam1_t *rec)
{
uint32_t *read_cigar, *mate_cigar, *read_cigar_end, *mate_cigar_end;
int32_t read_rpos, mate_rpos;
if (rec->core.n_cigar > 0 && olh->n_mc_cigar) {
read_rpos = rec->core.pos;
mate_rpos = rec->core.mpos;
read_cigar = bam_get_cigar(rec);
read_cigar_end = read_cigar + rec->core.n_cigar;
mate_cigar = olh->mc_buffer;
mate_cigar_end = olh->mc_buffer + olh->n_mc_cigar;
_advance_to_coverage_cigar(&read_cigar, &read_cigar_end, &read_rpos);
_advance_to_coverage_cigar(&mate_cigar, &mate_cigar_end, &mate_rpos);
int32_t read_endrpos, mate_endrpos, overlap_start, overlap_end;
while (read_cigar != read_cigar_end &&
mate_cigar != mate_cigar_end)
{
read_endrpos = read_rpos + bam_cigar_oplen(*read_cigar);
mate_endrpos = mate_rpos + bam_cigar_oplen(*mate_cigar);
if (read_rpos < mate_rpos) {
if (mate_rpos < read_endrpos) {
overlap_start = mate_rpos;
overlap_end = (read_endrpos < mate_endrpos)? read_endrpos: mate_endrpos;
overlap_handler_add(olh, overlap_start, overlap_end);
}
if (bam_cigar_type(*read_cigar) & 0x02) {
read_rpos += bam_cigar_oplen(*read_cigar);
}
++read_cigar;
_advance_to_coverage_cigar(&read_cigar, &read_cigar_end, &read_rpos);
} else {
if (read_rpos < mate_endrpos) {
overlap_start = read_rpos;
overlap_end = (mate_endrpos < read_endrpos)? mate_endrpos: read_endrpos;
overlap_handler_add(olh, overlap_start, overlap_end);
}
if (bam_cigar_type(*mate_cigar) & 0x02) {
mate_rpos += bam_cigar_oplen(*mate_cigar);
}
++mate_cigar;
_advance_to_coverage_cigar(&mate_cigar, &mate_cigar_end, &mate_rpos);
}
}
}
} | [
"void",
"overlap_handler_generate",
"(",
"overlap_handler_t",
"*",
"olh",
",",
"bam1_t",
"*",
"rec",
")",
"{",
"uint32_t",
"*",
"read_cigar",
",",
"*",
"mate_cigar",
",",
"*",
"read_cigar_end",
",",
"*",
"mate_cigar_end",
";",
"int32_t",
"read_rpos",
",",
"mate_rpos",
";",
"if",
"(",
"rec",
"->",
"core",
".",
"n_cigar",
">",
"0",
"&&",
"olh",
"->",
"n_mc_cigar",
")",
"{",
"read_rpos",
"=",
"rec",
"->",
"core",
".",
"pos",
";",
"mate_rpos",
"=",
"rec",
"->",
"core",
".",
"mpos",
";",
"read_cigar",
"=",
"bam_get_cigar",
"(",
"rec",
")",
";",
"read_cigar_end",
"=",
"read_cigar",
"+",
"rec",
"->",
"core",
".",
"n_cigar",
";",
"mate_cigar",
"=",
"olh",
"->",
"mc_buffer",
";",
"mate_cigar_end",
"=",
"olh",
"->",
"mc_buffer",
"+",
"olh",
"->",
"n_mc_cigar",
";",
"_advance_to_coverage_cigar",
"(",
"&",
"read_cigar",
",",
"&",
"read_cigar_end",
",",
"&",
"read_rpos",
")",
";",
"_advance_to_coverage_cigar",
"(",
"&",
"mate_cigar",
",",
"&",
"mate_cigar_end",
",",
"&",
"mate_rpos",
")",
";",
"int32_t",
"read_endrpos",
",",
"mate_endrpos",
",",
"overlap_start",
",",
"overlap_end",
";",
"while",
"(",
"read_cigar",
"!=",
"read_cigar_end",
"&&",
"mate_cigar",
"!=",
"mate_cigar_end",
")",
"{",
"read_endrpos",
"=",
"read_rpos",
"+",
"bam_cigar_oplen",
"(",
"*",
"read_cigar",
")",
";",
"mate_endrpos",
"=",
"mate_rpos",
"+",
"bam_cigar_oplen",
"(",
"*",
"mate_cigar",
")",
";",
"if",
"(",
"read_rpos",
"<",
"mate_rpos",
")",
"{",
"if",
"(",
"mate_rpos",
"<",
"read_endrpos",
")",
"{",
"overlap_start",
"=",
"mate_rpos",
";",
"overlap_end",
"=",
"(",
"read_endrpos",
"<",
"mate_endrpos",
")",
"?",
"read_endrpos",
":",
"mate_endrpos",
";",
"overlap_handler_add",
"(",
"olh",
",",
"overlap_start",
",",
"overlap_end",
")",
";",
"}",
"if",
"(",
"bam_cigar_type",
"(",
"*",
"read_cigar",
")",
"&",
"0x02",
")",
"{",
"read_rpos",
"+=",
"bam_cigar_oplen",
"(",
"*",
"read_cigar",
")",
";",
"}",
"++",
"read_cigar",
";",
"_advance_to_coverage_cigar",
"(",
"&",
"read_cigar",
",",
"&",
"read_cigar_end",
",",
"&",
"read_rpos",
")",
";",
"}",
"else",
"{",
"if",
"(",
"read_rpos",
"<",
"mate_endrpos",
")",
"{",
"overlap_start",
"=",
"read_rpos",
";",
"overlap_end",
"=",
"(",
"mate_endrpos",
"<",
"read_endrpos",
")",
"?",
"mate_endrpos",
":",
"read_endrpos",
";",
"overlap_handler_add",
"(",
"olh",
",",
"overlap_start",
",",
"overlap_end",
")",
";",
"}",
"if",
"(",
"bam_cigar_type",
"(",
"*",
"mate_cigar",
")",
"&",
"0x02",
")",
"{",
"mate_rpos",
"+=",
"bam_cigar_oplen",
"(",
"*",
"mate_cigar",
")",
";",
"}",
"++",
"mate_cigar",
";",
"_advance_to_coverage_cigar",
"(",
"&",
"mate_cigar",
",",
"&",
"mate_cigar_end",
",",
"&",
"mate_rpos",
")",
";",
"}",
"}",
"}",
"}"
] | Generate overlap intervals for a read after loading mc_buffer with mc_buffer_load() | [
"Generate",
"overlap",
"intervals",
"for",
"a",
"read",
"after",
"loading",
"mc_buffer",
"with",
"mc_buffer_load",
"()"
] | [
"/* ptrs to current cigar ops */",
"/* if both read and mate have non-zero # of cigar ops */",
"/* read and mate pos */",
"/* set read and mate start and end */",
"/* advance to first coverage cigar */",
"/* find overlap, add to overlap buffer, and advance cigars */",
"/* record overlap */",
"/* advance read_cigar */",
"/* record overlap */",
"/* advance mate_cigar */"
] | [
{
"param": "olh",
"type": "overlap_handler_t"
},
{
"param": "rec",
"type": "bam1_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "olh",
"type": "overlap_handler_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | capture_metrics_finalize | void | void capture_metrics_finalize(capture_metrics_t *cm, coverage_info_t *ci, bed_t *ti)
{
uint64_t k = 0, median_sum = 0, sum = 0;
uint64_t mid = (ti == NULL ? cm->b_total : cm->b_targeted) / 2;
bool median_set = false;
/* Set median coverage */
for (size_t i = 0; i < ci->cov_histo_len; ++i) {
if (ci->cov_histo[i] > 0) {
k += ci->cov_histo[i];
median_sum += ci->cov_histo[i];
if (!median_set && median_sum >= mid) {
cm->c_median = i;
median_set = true;
}
sum += i * ci->cov_histo[i];
}
}
cm->c_std_dev = k > 1
? sqrt(((double)cm->c_sum_sq - (double)sum * ((double)sum / (double)k)) /
(double)(k - 1))
: 0.0;
/* Masked bases */
cm->b_total -= cm->b_masked;
} | /**
* Finalize capture metrics once all records are processed.
* Calculates median coverage.
*/ | Finalize capture metrics once all records are processed.
Calculates median coverage. | [
"Finalize",
"capture",
"metrics",
"once",
"all",
"records",
"are",
"processed",
".",
"Calculates",
"median",
"coverage",
"."
] | void capture_metrics_finalize(capture_metrics_t *cm, coverage_info_t *ci, bed_t *ti)
{
uint64_t k = 0, median_sum = 0, sum = 0;
uint64_t mid = (ti == NULL ? cm->b_total : cm->b_targeted) / 2;
bool median_set = false;
for (size_t i = 0; i < ci->cov_histo_len; ++i) {
if (ci->cov_histo[i] > 0) {
k += ci->cov_histo[i];
median_sum += ci->cov_histo[i];
if (!median_set && median_sum >= mid) {
cm->c_median = i;
median_set = true;
}
sum += i * ci->cov_histo[i];
}
}
cm->c_std_dev = k > 1
? sqrt(((double)cm->c_sum_sq - (double)sum * ((double)sum / (double)k)) /
(double)(k - 1))
: 0.0;
cm->b_total -= cm->b_masked;
} | [
"void",
"capture_metrics_finalize",
"(",
"capture_metrics_t",
"*",
"cm",
",",
"coverage_info_t",
"*",
"ci",
",",
"bed_t",
"*",
"ti",
")",
"{",
"uint64_t",
"k",
"=",
"0",
",",
"median_sum",
"=",
"0",
",",
"sum",
"=",
"0",
";",
"uint64_t",
"mid",
"=",
"(",
"ti",
"==",
"NULL",
"?",
"cm",
"->",
"b_total",
":",
"cm",
"->",
"b_targeted",
")",
"/",
"2",
";",
"bool",
"median_set",
"=",
"false",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"i",
"<",
"ci",
"->",
"cov_histo_len",
";",
"++",
"i",
")",
"{",
"if",
"(",
"ci",
"->",
"cov_histo",
"[",
"i",
"]",
">",
"0",
")",
"{",
"k",
"+=",
"ci",
"->",
"cov_histo",
"[",
"i",
"]",
";",
"median_sum",
"+=",
"ci",
"->",
"cov_histo",
"[",
"i",
"]",
";",
"if",
"(",
"!",
"median_set",
"&&",
"median_sum",
">=",
"mid",
")",
"{",
"cm",
"->",
"c_median",
"=",
"i",
";",
"median_set",
"=",
"true",
";",
"}",
"sum",
"+=",
"i",
"*",
"ci",
"->",
"cov_histo",
"[",
"i",
"]",
";",
"}",
"}",
"cm",
"->",
"c_std_dev",
"=",
"k",
">",
"1",
"?",
"sqrt",
"(",
"(",
"(",
"double",
")",
"cm",
"->",
"c_sum_sq",
"-",
"(",
"double",
")",
"sum",
"*",
"(",
"(",
"double",
")",
"sum",
"/",
"(",
"double",
")",
"k",
")",
")",
"/",
"(",
"double",
")",
"(",
"k",
"-",
"1",
")",
")",
":",
"0.0",
";",
"cm",
"->",
"b_total",
"-=",
"cm",
"->",
"b_masked",
";",
"}"
] | Finalize capture metrics once all records are processed. | [
"Finalize",
"capture",
"metrics",
"once",
"all",
"records",
"are",
"processed",
"."
] | [
"/* Set median coverage */",
"/* Masked bases */"
] | [
{
"param": "cm",
"type": "capture_metrics_t"
},
{
"param": "ci",
"type": "coverage_info_t"
},
{
"param": "ti",
"type": "bed_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "cm",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ci",
"type": "coverage_info_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ti",
"type": "bed_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | handle_wgs_coverage | void | void handle_wgs_coverage(const uint32_t *coverage, capture_metrics_t *cm,
coverage_info_t *ci, int32_t chrom_len)
{
uint32_t cov;
/* for each base position in chromosome */
for (int32_t i = 0; i < chrom_len; ++i) {
cov = get_coverage(coverage[i]);
/* Bases with coverage of at least 1, 10, 20, etc. */
if (cov < 30) {
if (cov == 0) {
goto cov0;
} else {
if (cov < 15) {
if (cov < 10) {
goto cov1;
} else {
goto cov10;
}
} else {
if (cov < 20) {
goto cov15;
} else {
goto cov20;
}
}
}
} else {
if (cov < 70) {
if (cov < 50) {
if (cov < 40) {
goto cov30;
} else {
goto cov40;
}
} else {
if (cov < 60) {
goto cov50;
} else {
goto cov60;
}
}
} else {
if (cov < 500) {
if (cov < 100) {
goto cov70;
} else {
goto cov100;
}
} else {
if (cov < 1000) {
goto cov500;
} else {
goto cov1000;
}
}
}
}
cov1000:++cm->b_1000_plus_hits;
cov500: ++cm->b_500_plus_hits;
cov100: ++cm->b_100_plus_hits;
cov70: ++cm->b_70_plus_hits;
cov60: ++cm->b_60_plus_hits;
cov50: ++cm->b_50_plus_hits;
cov40: ++cm->b_40_plus_hits;
cov30: ++cm->b_30_plus_hits;
cov20: ++cm->b_20_plus_hits;
cov15: ++cm->b_15_plus_hits;
cov10: ++cm->b_10_plus_hits;
cov1: ++cm->b_1_plus_hits;
cm->c_total += (uint64_t)cov;
cm->c_sum_sq += (uint64_t)cov * (uint64_t)cov;
cov0: incr_cov_histo(ci, cov);
}
} | /**
* Record whole genome coverage metrics for chromosome cname.
*/ | Record whole genome coverage metrics for chromosome cname. | [
"Record",
"whole",
"genome",
"coverage",
"metrics",
"for",
"chromosome",
"cname",
"."
] | void handle_wgs_coverage(const uint32_t *coverage, capture_metrics_t *cm,
coverage_info_t *ci, int32_t chrom_len)
{
uint32_t cov;
for (int32_t i = 0; i < chrom_len; ++i) {
cov = get_coverage(coverage[i]);
if (cov < 30) {
if (cov == 0) {
goto cov0;
} else {
if (cov < 15) {
if (cov < 10) {
goto cov1;
} else {
goto cov10;
}
} else {
if (cov < 20) {
goto cov15;
} else {
goto cov20;
}
}
}
} else {
if (cov < 70) {
if (cov < 50) {
if (cov < 40) {
goto cov30;
} else {
goto cov40;
}
} else {
if (cov < 60) {
goto cov50;
} else {
goto cov60;
}
}
} else {
if (cov < 500) {
if (cov < 100) {
goto cov70;
} else {
goto cov100;
}
} else {
if (cov < 1000) {
goto cov500;
} else {
goto cov1000;
}
}
}
}
cov1000:++cm->b_1000_plus_hits;
cov500: ++cm->b_500_plus_hits;
cov100: ++cm->b_100_plus_hits;
cov70: ++cm->b_70_plus_hits;
cov60: ++cm->b_60_plus_hits;
cov50: ++cm->b_50_plus_hits;
cov40: ++cm->b_40_plus_hits;
cov30: ++cm->b_30_plus_hits;
cov20: ++cm->b_20_plus_hits;
cov15: ++cm->b_15_plus_hits;
cov10: ++cm->b_10_plus_hits;
cov1: ++cm->b_1_plus_hits;
cm->c_total += (uint64_t)cov;
cm->c_sum_sq += (uint64_t)cov * (uint64_t)cov;
cov0: incr_cov_histo(ci, cov);
}
} | [
"void",
"handle_wgs_coverage",
"(",
"const",
"uint32_t",
"*",
"coverage",
",",
"capture_metrics_t",
"*",
"cm",
",",
"coverage_info_t",
"*",
"ci",
",",
"int32_t",
"chrom_len",
")",
"{",
"uint32_t",
"cov",
";",
"for",
"(",
"int32_t",
"i",
"=",
"0",
";",
"i",
"<",
"chrom_len",
";",
"++",
"i",
")",
"{",
"cov",
"=",
"get_coverage",
"(",
"coverage",
"[",
"i",
"]",
")",
";",
"if",
"(",
"cov",
"<",
"30",
")",
"{",
"if",
"(",
"cov",
"==",
"0",
")",
"{",
"goto",
"cov0",
";",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"15",
")",
"{",
"if",
"(",
"cov",
"<",
"10",
")",
"{",
"goto",
"cov1",
";",
"}",
"else",
"{",
"goto",
"cov10",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"20",
")",
"{",
"goto",
"cov15",
";",
"}",
"else",
"{",
"goto",
"cov20",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"70",
")",
"{",
"if",
"(",
"cov",
"<",
"50",
")",
"{",
"if",
"(",
"cov",
"<",
"40",
")",
"{",
"goto",
"cov30",
";",
"}",
"else",
"{",
"goto",
"cov40",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"60",
")",
"{",
"goto",
"cov50",
";",
"}",
"else",
"{",
"goto",
"cov60",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"500",
")",
"{",
"if",
"(",
"cov",
"<",
"100",
")",
"{",
"goto",
"cov70",
";",
"}",
"else",
"{",
"goto",
"cov100",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"1000",
")",
"{",
"goto",
"cov500",
";",
"}",
"else",
"{",
"goto",
"cov1000",
";",
"}",
"}",
"}",
"}",
"cov1000",
":",
"++",
"cm",
"->",
"b_1000_plus_hits",
";",
"cov500",
":",
"++",
"cm",
"->",
"b_500_plus_hits",
";",
"cov100",
":",
"++",
"cm",
"->",
"b_100_plus_hits",
";",
"cov70",
":",
"++",
"cm",
"->",
"b_70_plus_hits",
";",
"cov60",
":",
"++",
"cm",
"->",
"b_60_plus_hits",
";",
"cov50",
":",
"++",
"cm",
"->",
"b_50_plus_hits",
";",
"cov40",
":",
"++",
"cm",
"->",
"b_40_plus_hits",
";",
"cov30",
":",
"++",
"cm",
"->",
"b_30_plus_hits",
";",
"cov20",
":",
"++",
"cm",
"->",
"b_20_plus_hits",
";",
"cov15",
":",
"++",
"cm",
"->",
"b_15_plus_hits",
";",
"cov10",
":",
"++",
"cm",
"->",
"b_10_plus_hits",
";",
"cov1",
":",
"++",
"cm",
"->",
"b_1_plus_hits",
";",
"cm",
"->",
"c_total",
"+=",
"(",
"uint64_t",
")",
"cov",
";",
"cm",
"->",
"c_sum_sq",
"+=",
"(",
"uint64_t",
")",
"cov",
"*",
"(",
"uint64_t",
")",
"cov",
";",
"cov0",
":",
"incr_cov_histo",
"(",
"ci",
",",
"cov",
")",
";",
"}",
"}"
] | Record whole genome coverage metrics for chromosome cname. | [
"Record",
"whole",
"genome",
"coverage",
"metrics",
"for",
"chromosome",
"cname",
"."
] | [
"/* for each base position in chromosome */",
"/* Bases with coverage of at least 1, 10, 20, etc. */"
] | [
{
"param": "coverage",
"type": "uint32_t"
},
{
"param": "cm",
"type": "capture_metrics_t"
},
{
"param": "ci",
"type": "coverage_info_t"
},
{
"param": "chrom_len",
"type": "int32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "coverage",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cm",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ci",
"type": "coverage_info_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_len",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | handle_target_coverage | void | void handle_target_coverage(const uint32_t *coverage, capture_metrics_t *cm,
coverage_info_t *ci, bed_t *ti, int32_t chrom_idx,
const char *chrom, int32_t chrom_len)
{
/* Target coverage statistics */
bool target_hit, buffer_hit;
int32_t start, end, j, buffer_end;
uint32_t cov;
bed_chrom_t *tic = ti->chroms[chrom_idx];
/* for each target */
for (size_t i = 0; i < tic->num_targets; ++i) {
start = tic->start_pos[i];
end = tic->end_pos[i];
target_hit = false;
/* for each base position */
for (int32_t j = start; j <= end; ++j) {
cov = get_coverage(coverage[j]);
/* Bases with coverage of at least 1, 10, 20, etc. */
if (cov < 30) {
if (cov == 0) {
goto tgtcov0;
} else {
if (cov < 15) {
if (cov < 10) {
goto tgtcov1;
} else {
goto tgtcov10;
}
} else {
if (cov < 20) {
goto tgtcov15;
} else {
goto tgtcov20;
}
}
}
} else {
if (cov < 70) {
if (cov < 50) {
if (cov < 40) {
goto tgtcov30;
} else {
goto tgtcov40;
}
} else {
if (cov < 60) {
goto tgtcov50;
} else {
goto tgtcov60;
}
}
} else {
if (cov < 500) {
if (cov < 100) {
goto tgtcov70;
} else {
goto tgtcov100;
}
} else {
if (cov < 1000) {
goto tgtcov500;
} else {
goto tgtcov1000;
}
}
}
}
tgtcov1000: ++cm->b_1000_plus_hits;
tgtcov500: ++cm->b_500_plus_hits;
tgtcov100: ++cm->b_100_plus_hits;
tgtcov70: ++cm->b_70_plus_hits;
tgtcov60: ++cm->b_60_plus_hits;
tgtcov50: ++cm->b_50_plus_hits;
tgtcov40: ++cm->b_40_plus_hits;
tgtcov30: ++cm->b_30_plus_hits;
tgtcov20: ++cm->b_20_plus_hits;
tgtcov15: ++cm->b_15_plus_hits;
tgtcov10: ++cm->b_10_plus_hits;
tgtcov1: ++cm->b_1_plus_hits;
cm->c_total += (uint64_t)cov;
cm->c_sum_sq += (uint64_t)cov * (uint64_t)cov;
target_hit = true;
tgtcov0: incr_cov_histo(ci, cov);
}
if (target_hit) {
++cm->t_hit;
} else {
/* Check if buffers were hit */
buffer_hit = false;
/* Left buffer */
j = (start > BUFFER) ? start - BUFFER : 0;
buffer_end = (start < chrom_len) ? start : chrom_len - 1;
while (j < buffer_end) {
cov = get_coverage(coverage[j]);
if (cov > 0) {
buffer_hit = true;
++cm->t_buffers_hit;
break;
}
++j;
}
if (!buffer_hit) {
/* Right buffer */
++end;
j = (end > 0) ? end : 0;
buffer_end = (end + BUFFER < chrom_len) ? end + BUFFER : chrom_len - 1;
while (j < buffer_end) {
cov = get_coverage(coverage[j]);
if (cov > 0) {
++cm->t_buffers_hit;
break;
}
++j;
}
}
}
}
} | /**
* Record capture coverage metrics for chromosome cname.
*/ | Record capture coverage metrics for chromosome cname. | [
"Record",
"capture",
"coverage",
"metrics",
"for",
"chromosome",
"cname",
"."
] | void handle_target_coverage(const uint32_t *coverage, capture_metrics_t *cm,
coverage_info_t *ci, bed_t *ti, int32_t chrom_idx,
const char *chrom, int32_t chrom_len)
{
bool target_hit, buffer_hit;
int32_t start, end, j, buffer_end;
uint32_t cov;
bed_chrom_t *tic = ti->chroms[chrom_idx];
for (size_t i = 0; i < tic->num_targets; ++i) {
start = tic->start_pos[i];
end = tic->end_pos[i];
target_hit = false;
for (int32_t j = start; j <= end; ++j) {
cov = get_coverage(coverage[j]);
if (cov < 30) {
if (cov == 0) {
goto tgtcov0;
} else {
if (cov < 15) {
if (cov < 10) {
goto tgtcov1;
} else {
goto tgtcov10;
}
} else {
if (cov < 20) {
goto tgtcov15;
} else {
goto tgtcov20;
}
}
}
} else {
if (cov < 70) {
if (cov < 50) {
if (cov < 40) {
goto tgtcov30;
} else {
goto tgtcov40;
}
} else {
if (cov < 60) {
goto tgtcov50;
} else {
goto tgtcov60;
}
}
} else {
if (cov < 500) {
if (cov < 100) {
goto tgtcov70;
} else {
goto tgtcov100;
}
} else {
if (cov < 1000) {
goto tgtcov500;
} else {
goto tgtcov1000;
}
}
}
}
tgtcov1000: ++cm->b_1000_plus_hits;
tgtcov500: ++cm->b_500_plus_hits;
tgtcov100: ++cm->b_100_plus_hits;
tgtcov70: ++cm->b_70_plus_hits;
tgtcov60: ++cm->b_60_plus_hits;
tgtcov50: ++cm->b_50_plus_hits;
tgtcov40: ++cm->b_40_plus_hits;
tgtcov30: ++cm->b_30_plus_hits;
tgtcov20: ++cm->b_20_plus_hits;
tgtcov15: ++cm->b_15_plus_hits;
tgtcov10: ++cm->b_10_plus_hits;
tgtcov1: ++cm->b_1_plus_hits;
cm->c_total += (uint64_t)cov;
cm->c_sum_sq += (uint64_t)cov * (uint64_t)cov;
target_hit = true;
tgtcov0: incr_cov_histo(ci, cov);
}
if (target_hit) {
++cm->t_hit;
} else {
buffer_hit = false;
j = (start > BUFFER) ? start - BUFFER : 0;
buffer_end = (start < chrom_len) ? start : chrom_len - 1;
while (j < buffer_end) {
cov = get_coverage(coverage[j]);
if (cov > 0) {
buffer_hit = true;
++cm->t_buffers_hit;
break;
}
++j;
}
if (!buffer_hit) {
++end;
j = (end > 0) ? end : 0;
buffer_end = (end + BUFFER < chrom_len) ? end + BUFFER : chrom_len - 1;
while (j < buffer_end) {
cov = get_coverage(coverage[j]);
if (cov > 0) {
++cm->t_buffers_hit;
break;
}
++j;
}
}
}
}
} | [
"void",
"handle_target_coverage",
"(",
"const",
"uint32_t",
"*",
"coverage",
",",
"capture_metrics_t",
"*",
"cm",
",",
"coverage_info_t",
"*",
"ci",
",",
"bed_t",
"*",
"ti",
",",
"int32_t",
"chrom_idx",
",",
"const",
"char",
"*",
"chrom",
",",
"int32_t",
"chrom_len",
")",
"{",
"bool",
"target_hit",
",",
"buffer_hit",
";",
"int32_t",
"start",
",",
"end",
",",
"j",
",",
"buffer_end",
";",
"uint32_t",
"cov",
";",
"bed_chrom_t",
"*",
"tic",
"=",
"ti",
"->",
"chroms",
"[",
"chrom_idx",
"]",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"i",
"<",
"tic",
"->",
"num_targets",
";",
"++",
"i",
")",
"{",
"start",
"=",
"tic",
"->",
"start_pos",
"[",
"i",
"]",
";",
"end",
"=",
"tic",
"->",
"end_pos",
"[",
"i",
"]",
";",
"target_hit",
"=",
"false",
";",
"for",
"(",
"int32_t",
"j",
"=",
"start",
";",
"j",
"<=",
"end",
";",
"++",
"j",
")",
"{",
"cov",
"=",
"get_coverage",
"(",
"coverage",
"[",
"j",
"]",
")",
";",
"if",
"(",
"cov",
"<",
"30",
")",
"{",
"if",
"(",
"cov",
"==",
"0",
")",
"{",
"goto",
"tgtcov0",
";",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"15",
")",
"{",
"if",
"(",
"cov",
"<",
"10",
")",
"{",
"goto",
"tgtcov1",
";",
"}",
"else",
"{",
"goto",
"tgtcov10",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"20",
")",
"{",
"goto",
"tgtcov15",
";",
"}",
"else",
"{",
"goto",
"tgtcov20",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"70",
")",
"{",
"if",
"(",
"cov",
"<",
"50",
")",
"{",
"if",
"(",
"cov",
"<",
"40",
")",
"{",
"goto",
"tgtcov30",
";",
"}",
"else",
"{",
"goto",
"tgtcov40",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"60",
")",
"{",
"goto",
"tgtcov50",
";",
"}",
"else",
"{",
"goto",
"tgtcov60",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"500",
")",
"{",
"if",
"(",
"cov",
"<",
"100",
")",
"{",
"goto",
"tgtcov70",
";",
"}",
"else",
"{",
"goto",
"tgtcov100",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"cov",
"<",
"1000",
")",
"{",
"goto",
"tgtcov500",
";",
"}",
"else",
"{",
"goto",
"tgtcov1000",
";",
"}",
"}",
"}",
"}",
"tgtcov1000",
":",
"++",
"cm",
"->",
"b_1000_plus_hits",
";",
"tgtcov500",
":",
"++",
"cm",
"->",
"b_500_plus_hits",
";",
"tgtcov100",
":",
"++",
"cm",
"->",
"b_100_plus_hits",
";",
"tgtcov70",
":",
"++",
"cm",
"->",
"b_70_plus_hits",
";",
"tgtcov60",
":",
"++",
"cm",
"->",
"b_60_plus_hits",
";",
"tgtcov50",
":",
"++",
"cm",
"->",
"b_50_plus_hits",
";",
"tgtcov40",
":",
"++",
"cm",
"->",
"b_40_plus_hits",
";",
"tgtcov30",
":",
"++",
"cm",
"->",
"b_30_plus_hits",
";",
"tgtcov20",
":",
"++",
"cm",
"->",
"b_20_plus_hits",
";",
"tgtcov15",
":",
"++",
"cm",
"->",
"b_15_plus_hits",
";",
"tgtcov10",
":",
"++",
"cm",
"->",
"b_10_plus_hits",
";",
"tgtcov1",
":",
"++",
"cm",
"->",
"b_1_plus_hits",
";",
"cm",
"->",
"c_total",
"+=",
"(",
"uint64_t",
")",
"cov",
";",
"cm",
"->",
"c_sum_sq",
"+=",
"(",
"uint64_t",
")",
"cov",
"*",
"(",
"uint64_t",
")",
"cov",
";",
"target_hit",
"=",
"true",
";",
"tgtcov0",
":",
"incr_cov_histo",
"(",
"ci",
",",
"cov",
")",
";",
"}",
"if",
"(",
"target_hit",
")",
"{",
"++",
"cm",
"->",
"t_hit",
";",
"}",
"else",
"{",
"buffer_hit",
"=",
"false",
";",
"j",
"=",
"(",
"start",
">",
"BUFFER",
")",
"?",
"start",
"-",
"BUFFER",
":",
"0",
";",
"buffer_end",
"=",
"(",
"start",
"<",
"chrom_len",
")",
"?",
"start",
":",
"chrom_len",
"-",
"1",
";",
"while",
"(",
"j",
"<",
"buffer_end",
")",
"{",
"cov",
"=",
"get_coverage",
"(",
"coverage",
"[",
"j",
"]",
")",
";",
"if",
"(",
"cov",
">",
"0",
")",
"{",
"buffer_hit",
"=",
"true",
";",
"++",
"cm",
"->",
"t_buffers_hit",
";",
"break",
";",
"}",
"++",
"j",
";",
"}",
"if",
"(",
"!",
"buffer_hit",
")",
"{",
"++",
"end",
";",
"j",
"=",
"(",
"end",
">",
"0",
")",
"?",
"end",
":",
"0",
";",
"buffer_end",
"=",
"(",
"end",
"+",
"BUFFER",
"<",
"chrom_len",
")",
"?",
"end",
"+",
"BUFFER",
":",
"chrom_len",
"-",
"1",
";",
"while",
"(",
"j",
"<",
"buffer_end",
")",
"{",
"cov",
"=",
"get_coverage",
"(",
"coverage",
"[",
"j",
"]",
")",
";",
"if",
"(",
"cov",
">",
"0",
")",
"{",
"++",
"cm",
"->",
"t_buffers_hit",
";",
"break",
";",
"}",
"++",
"j",
";",
"}",
"}",
"}",
"}",
"}"
] | Record capture coverage metrics for chromosome cname. | [
"Record",
"capture",
"coverage",
"metrics",
"for",
"chromosome",
"cname",
"."
] | [
"/* Target coverage statistics */",
"/* for each target */",
"/* for each base position */",
"/* Bases with coverage of at least 1, 10, 20, etc. */",
"/* Check if buffers were hit */",
"/* Left buffer */",
"/* Right buffer */"
] | [
{
"param": "coverage",
"type": "uint32_t"
},
{
"param": "cm",
"type": "capture_metrics_t"
},
{
"param": "ci",
"type": "coverage_info_t"
},
{
"param": "ti",
"type": "bed_t"
},
{
"param": "chrom_idx",
"type": "int32_t"
},
{
"param": "chrom",
"type": "char"
},
{
"param": "chrom_len",
"type": "int32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "coverage",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cm",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ci",
"type": "coverage_info_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ti",
"type": "bed_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_idx",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_len",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | clear_coverage | void | void clear_coverage(uint32_t *coverage, int32_t start, int32_t end, int32_t chrom_len)
{
if (start < 0) {
start = 0;
}
if (end >= chrom_len) {
end = chrom_len - 1;
}
/* Clear target and buffer bases */
memset(coverage + start, 0, (end - start + 1) * sizeof(uint32_t));
} | /**
* Set values from start to end in coverage to 0.
*/ | Set values from start to end in coverage to 0. | [
"Set",
"values",
"from",
"start",
"to",
"end",
"in",
"coverage",
"to",
"0",
"."
] | void clear_coverage(uint32_t *coverage, int32_t start, int32_t end, int32_t chrom_len)
{
if (start < 0) {
start = 0;
}
if (end >= chrom_len) {
end = chrom_len - 1;
}
memset(coverage + start, 0, (end - start + 1) * sizeof(uint32_t));
} | [
"void",
"clear_coverage",
"(",
"uint32_t",
"*",
"coverage",
",",
"int32_t",
"start",
",",
"int32_t",
"end",
",",
"int32_t",
"chrom_len",
")",
"{",
"if",
"(",
"start",
"<",
"0",
")",
"{",
"start",
"=",
"0",
";",
"}",
"if",
"(",
"end",
">=",
"chrom_len",
")",
"{",
"end",
"=",
"chrom_len",
"-",
"1",
";",
"}",
"memset",
"(",
"coverage",
"+",
"start",
",",
"0",
",",
"(",
"end",
"-",
"start",
"+",
"1",
")",
"*",
"sizeof",
"(",
"uint32_t",
")",
")",
";",
"}"
] | Set values from start to end in coverage to 0. | [
"Set",
"values",
"from",
"start",
"to",
"end",
"in",
"coverage",
"to",
"0",
"."
] | [
"/* Clear target and buffer bases */"
] | [
{
"param": "coverage",
"type": "uint32_t"
},
{
"param": "start",
"type": "int32_t"
},
{
"param": "end",
"type": "int32_t"
},
{
"param": "chrom_len",
"type": "int32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "coverage",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "start",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "end",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_len",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | handle_miss_reads | void | void handle_miss_reads(uint32_t *coverage, capture_metrics_t *cm, bed_t *ti,
int32_t chrom_idx, int32_t chrom_len)
{
if (ti->num_targets > 0) {
bed_chrom_t *tic = ti->chroms[chrom_idx];
int32_t start = 0, end;
for (size_t i = 0; i < tic->num_targets; ++i) {
end = tic->start_pos[i] - 1 - MISS_BUFFER;
if (end >= start) {
if (start < 0) {
start = 0;
}
if (end >= chrom_len) {
end = chrom_len - 1;
}
for (int32_t j = start; j <= end; ++j) {
if (coverage[j] >= 20) {
++cm->t_non_target_good_hits;
while (j <= end && coverage[j] > 0) {
++j;
}
}
}
}
start = tic->end_pos[i] + 1 + MISS_BUFFER;
}
end = chrom_len;
for (int32_t j = start; j <= end; ++j) {
if (coverage[j] >= 20) {
++cm->t_non_target_good_hits;
while (j <= end && coverage[j] > 0) {
++j;
}
}
}
}
} | /**
* Record contiguous regions of >= 20X coverage outside of target and buffer
* regions.
*/ | Record contiguous regions of >= 20X coverage outside of target and buffer
regions. | [
"Record",
"contiguous",
"regions",
"of",
">",
"=",
"20X",
"coverage",
"outside",
"of",
"target",
"and",
"buffer",
"regions",
"."
] | void handle_miss_reads(uint32_t *coverage, capture_metrics_t *cm, bed_t *ti,
int32_t chrom_idx, int32_t chrom_len)
{
if (ti->num_targets > 0) {
bed_chrom_t *tic = ti->chroms[chrom_idx];
int32_t start = 0, end;
for (size_t i = 0; i < tic->num_targets; ++i) {
end = tic->start_pos[i] - 1 - MISS_BUFFER;
if (end >= start) {
if (start < 0) {
start = 0;
}
if (end >= chrom_len) {
end = chrom_len - 1;
}
for (int32_t j = start; j <= end; ++j) {
if (coverage[j] >= 20) {
++cm->t_non_target_good_hits;
while (j <= end && coverage[j] > 0) {
++j;
}
}
}
}
start = tic->end_pos[i] + 1 + MISS_BUFFER;
}
end = chrom_len;
for (int32_t j = start; j <= end; ++j) {
if (coverage[j] >= 20) {
++cm->t_non_target_good_hits;
while (j <= end && coverage[j] > 0) {
++j;
}
}
}
}
} | [
"void",
"handle_miss_reads",
"(",
"uint32_t",
"*",
"coverage",
",",
"capture_metrics_t",
"*",
"cm",
",",
"bed_t",
"*",
"ti",
",",
"int32_t",
"chrom_idx",
",",
"int32_t",
"chrom_len",
")",
"{",
"if",
"(",
"ti",
"->",
"num_targets",
">",
"0",
")",
"{",
"bed_chrom_t",
"*",
"tic",
"=",
"ti",
"->",
"chroms",
"[",
"chrom_idx",
"]",
";",
"int32_t",
"start",
"=",
"0",
",",
"end",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"i",
"<",
"tic",
"->",
"num_targets",
";",
"++",
"i",
")",
"{",
"end",
"=",
"tic",
"->",
"start_pos",
"[",
"i",
"]",
"-",
"1",
"-",
"MISS_BUFFER",
";",
"if",
"(",
"end",
">=",
"start",
")",
"{",
"if",
"(",
"start",
"<",
"0",
")",
"{",
"start",
"=",
"0",
";",
"}",
"if",
"(",
"end",
">=",
"chrom_len",
")",
"{",
"end",
"=",
"chrom_len",
"-",
"1",
";",
"}",
"for",
"(",
"int32_t",
"j",
"=",
"start",
";",
"j",
"<=",
"end",
";",
"++",
"j",
")",
"{",
"if",
"(",
"coverage",
"[",
"j",
"]",
">=",
"20",
")",
"{",
"++",
"cm",
"->",
"t_non_target_good_hits",
";",
"while",
"(",
"j",
"<=",
"end",
"&&",
"coverage",
"[",
"j",
"]",
">",
"0",
")",
"{",
"++",
"j",
";",
"}",
"}",
"}",
"}",
"start",
"=",
"tic",
"->",
"end_pos",
"[",
"i",
"]",
"+",
"1",
"+",
"MISS_BUFFER",
";",
"}",
"end",
"=",
"chrom_len",
";",
"for",
"(",
"int32_t",
"j",
"=",
"start",
";",
"j",
"<=",
"end",
";",
"++",
"j",
")",
"{",
"if",
"(",
"coverage",
"[",
"j",
"]",
">=",
"20",
")",
"{",
"++",
"cm",
"->",
"t_non_target_good_hits",
";",
"while",
"(",
"j",
"<=",
"end",
"&&",
"coverage",
"[",
"j",
"]",
">",
"0",
")",
"{",
"++",
"j",
";",
"}",
"}",
"}",
"}",
"}"
] | Record contiguous regions of >= 20X coverage outside of target and buffer
regions. | [
"Record",
"contiguous",
"regions",
"of",
">",
"=",
"20X",
"coverage",
"outside",
"of",
"target",
"and",
"buffer",
"regions",
"."
] | [] | [
{
"param": "coverage",
"type": "uint32_t"
},
{
"param": "cm",
"type": "capture_metrics_t"
},
{
"param": "ti",
"type": "bed_t"
},
{
"param": "chrom_idx",
"type": "int32_t"
},
{
"param": "chrom_len",
"type": "int32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "coverage",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cm",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "ti",
"type": "bed_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_idx",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_len",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | handle_coverage_mask | void | void handle_coverage_mask(uint32_t *coverage, bed_t *cov_mask_ti,
int32_t chrom_idx, int32_t chrom_len)
{
if (cov_mask_ti->num_targets > 0) {
bed_chrom_t *tic = cov_mask_ti->chroms[chrom_idx];
/* for each target set coverage[start:end] values to 0 */
for (size_t i = 0; i < tic->num_targets; ++i) {
clear_coverage(coverage, tic->start_pos[i], tic->end_pos[i], chrom_len);
}
}
} | /**
* Set coverage values for regions of known N bases in reference to 0.
* Regions are defined as targets in cov_mask_ti.
*/ | Set coverage values for regions of known N bases in reference to 0.
Regions are defined as targets in cov_mask_ti. | [
"Set",
"coverage",
"values",
"for",
"regions",
"of",
"known",
"N",
"bases",
"in",
"reference",
"to",
"0",
".",
"Regions",
"are",
"defined",
"as",
"targets",
"in",
"cov_mask_ti",
"."
] | void handle_coverage_mask(uint32_t *coverage, bed_t *cov_mask_ti,
int32_t chrom_idx, int32_t chrom_len)
{
if (cov_mask_ti->num_targets > 0) {
bed_chrom_t *tic = cov_mask_ti->chroms[chrom_idx];
for (size_t i = 0; i < tic->num_targets; ++i) {
clear_coverage(coverage, tic->start_pos[i], tic->end_pos[i], chrom_len);
}
}
} | [
"void",
"handle_coverage_mask",
"(",
"uint32_t",
"*",
"coverage",
",",
"bed_t",
"*",
"cov_mask_ti",
",",
"int32_t",
"chrom_idx",
",",
"int32_t",
"chrom_len",
")",
"{",
"if",
"(",
"cov_mask_ti",
"->",
"num_targets",
">",
"0",
")",
"{",
"bed_chrom_t",
"*",
"tic",
"=",
"cov_mask_ti",
"->",
"chroms",
"[",
"chrom_idx",
"]",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"i",
"<",
"tic",
"->",
"num_targets",
";",
"++",
"i",
")",
"{",
"clear_coverage",
"(",
"coverage",
",",
"tic",
"->",
"start_pos",
"[",
"i",
"]",
",",
"tic",
"->",
"end_pos",
"[",
"i",
"]",
",",
"chrom_len",
")",
";",
"}",
"}",
"}"
] | Set coverage values for regions of known N bases in reference to 0. | [
"Set",
"coverage",
"values",
"for",
"regions",
"of",
"known",
"N",
"bases",
"in",
"reference",
"to",
"0",
"."
] | [
"/* for each target set coverage[start:end] values to 0 */"
] | [
{
"param": "coverage",
"type": "uint32_t"
},
{
"param": "cov_mask_ti",
"type": "bed_t"
},
{
"param": "chrom_idx",
"type": "int32_t"
},
{
"param": "chrom_len",
"type": "int32_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "coverage",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cov_mask_ti",
"type": "bed_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_idx",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_len",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | _capture_process_record2 | void | void _capture_process_record2(bam1_t *rec, capture_metrics_t *cm,
target_state_t target_status)
{
cm->b_aligned += rec->core.l_qseq;
/* Record read as out of target, in target buffer, or in target */
switch (target_status) {
case TARGET_IN:
++cm->r_in_target;
break;
case TARGET_BUFFER:
++cm->r_in_buffer;
break;
default:
++cm->r_out_target;
break;
}
} | /**
* Process coverage metrics specific to whole genome or capture.
*/ | Process coverage metrics specific to whole genome or capture. | [
"Process",
"coverage",
"metrics",
"specific",
"to",
"whole",
"genome",
"or",
"capture",
"."
] | void _capture_process_record2(bam1_t *rec, capture_metrics_t *cm,
target_state_t target_status)
{
cm->b_aligned += rec->core.l_qseq;
switch (target_status) {
case TARGET_IN:
++cm->r_in_target;
break;
case TARGET_BUFFER:
++cm->r_in_buffer;
break;
default:
++cm->r_out_target;
break;
}
} | [
"void",
"_capture_process_record2",
"(",
"bam1_t",
"*",
"rec",
",",
"capture_metrics_t",
"*",
"cm",
",",
"target_state_t",
"target_status",
")",
"{",
"cm",
"->",
"b_aligned",
"+=",
"rec",
"->",
"core",
".",
"l_qseq",
";",
"switch",
"(",
"target_status",
")",
"{",
"case",
"TARGET_IN",
":",
"++",
"cm",
"->",
"r_in_target",
";",
"break",
";",
"case",
"TARGET_BUFFER",
":",
"++",
"cm",
"->",
"r_in_buffer",
";",
"break",
";",
"default",
":",
"++",
"cm",
"->",
"r_out_target",
";",
"break",
";",
"}",
"}"
] | Process coverage metrics specific to whole genome or capture. | [
"Process",
"coverage",
"metrics",
"specific",
"to",
"whole",
"genome",
"or",
"capture",
"."
] | [
"/* Record read as out of target, in target buffer, or in target */"
] | [
{
"param": "rec",
"type": "bam1_t"
},
{
"param": "cm",
"type": "capture_metrics_t"
},
{
"param": "target_status",
"type": "target_state_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cm",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "target_status",
"type": "target_state_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
919bfccb9a27c6e748d304e578df4569da3226f4 | jfarek/alignstats | coverage.c | [
"BSD-3-Clause"
] | C | capture_process_record | void | void capture_process_record(bam1_t *rec, uint32_t *coverage,
capture_metrics_t *cm_wgs, capture_metrics_t *cm_cap,
overlap_handler_t *olh, int32_t chrom_len,
bool remove_dups, bool remove_overlaps, bool remove_overlaps_mc,
uint8_t min_base_qual)
{
bool in_target, in_buffer, check_overlap;
uint8_t *qual, *bqual;
int32_t pos, start, start_pos, end_pos, ref_pos;
uint32_t target, oplen, *cigar;
uint64_t b_filt_overlap, b_filt_basequal;
uint64_t b_filt_target_overlap, b_filt_target_basequal;
const uint16_t FILTER = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL;
const uint32_t COV_MAX = (UINT32_MAX - 1) >> 2;
if (cm_wgs != NULL) {
++cm_wgs->r_total;
}
if (cm_cap != NULL) {
++cm_cap->r_total;
}
/* Filter out reads with filtered flags */
if (rec->core.flag & FILTER) {
return;
}
if (cm_wgs != NULL) {
_capture_process_record1(rec, cm_wgs);
}
if (cm_cap != NULL) {
_capture_process_record1(rec, cm_cap);
}
/* remove duplicate reads */
if (remove_dups && (rec->core.flag & BAM_FDUP)) {
return;
}
/* process record for possible overlap with mate pair */
process_record_overlap(olh, rec, remove_overlaps, remove_overlaps_mc);
/*
* Record coverage and whether aligned bases hit target or buffer
* Confirmed this now matches up with the correct ref pos and # CIGAR Ms
*/
in_target = false;
in_buffer = false;
ref_pos = 0;
start = rec->core.pos;
cigar = bam_get_cigar(rec);
bqual = bam_get_qual(rec);
b_filt_overlap = 0;
b_filt_basequal = 0;
b_filt_target_overlap = 0;
b_filt_target_basequal = 0;
overlap_pair_t *curr_overlap_pair, *overlap_pair_end;
check_overlap = (olh->n_overlap_pairs > 0);
if (check_overlap) {
curr_overlap_pair = olh->overlap_buffer;
overlap_pair_end = curr_overlap_pair + olh->n_overlap_pairs;
} else {
curr_overlap_pair = NULL;
overlap_pair_end = NULL;
}
/* for each CIGAR op */
for (uint32_t i = 0; i < rec->core.n_cigar; ++i) {
oplen = bam_cigar_oplen(cigar[i]);
switch (bam_cigar_op(cigar[i])) {
case BAM_CHARD_CLIP:
break;
/*
* M, =, X: record coverage for CIGAR M bases (matches + mismatches)
* or = (matches) and X (mismatches)
*/
case BAM_CMATCH:
case BAM_CEQUAL:
case BAM_CDIFF:
/* Record coverage */
if (coverage != NULL) {
start_pos = pos = start + ref_pos;
end_pos = start_pos + oplen - 1;
if (start_pos < 0) {
start_pos = 0;
pos = 0;
}
if (end_pos >= chrom_len) {
end_pos = chrom_len - 1;
}
qual = bqual + ref_pos;
while (pos <= end_pos) {
if (get_coverage(coverage[pos]) < COV_MAX) {
if (check_overlap &&
pos >= curr_overlap_pair->start &&
pos < curr_overlap_pair->end)
{
++b_filt_overlap;
if (get_target(coverage[pos]) == TARGET_IN) {
++b_filt_target_overlap;
}
} else if (*qual < min_base_qual) {
++b_filt_basequal;
if (get_target(coverage[pos]) == TARGET_IN) {
++b_filt_target_overlap;
}
} else {
++coverage[pos];
}
} else {
/* Y'know just in case */
log_warning("Coverage of greater than %u detected. "
"Coverage statistics may not be accurate.", COV_MAX);
}
++pos;
++qual;
/* if pos is past current overlap pair, advance to next */
if (check_overlap && pos >= curr_overlap_pair->end) {
++curr_overlap_pair;
/* no more overlap pairs */
if (curr_overlap_pair == overlap_pair_end) {
curr_overlap_pair = NULL;
overlap_pair_end = NULL;
check_overlap = false;
}
}
}
/* pos == end_pos */
while (--pos >= start_pos) {
target = get_target(coverage[pos]);
if (target == TARGET_BUFFER) {
in_buffer = true;
} else if (target == TARGET_IN) {
in_target = true;
break;
}
}
}
ref_pos += oplen;
break;
/* D: advance ref_pos past deletion */
case BAM_CDEL:
ref_pos += oplen;
break;
default:
break;
}
}
if (cm_wgs != NULL) {
cm_wgs->b_filt_overlap += b_filt_overlap;
cm_wgs->b_filt_basequal += b_filt_basequal;
_capture_process_record2(rec, cm_wgs, TARGET_OUT);
}
if (cm_cap != NULL) {
cm_cap->b_filt_overlap += b_filt_target_overlap;
cm_cap->b_filt_basequal += b_filt_target_basequal;
_capture_process_record2(rec, cm_cap, in_target ? TARGET_IN : in_buffer ? TARGET_BUFFER : TARGET_OUT);
}
} | /**
* Process record for target and coverage info.
* cm_wgs: Capture metrics for whole genome statistics
* cm_cap: Capture metrics for capture statistics
*/ | Process record for target and coverage info.
cm_wgs: Capture metrics for whole genome statistics
cm_cap: Capture metrics for capture statistics | [
"Process",
"record",
"for",
"target",
"and",
"coverage",
"info",
".",
"cm_wgs",
":",
"Capture",
"metrics",
"for",
"whole",
"genome",
"statistics",
"cm_cap",
":",
"Capture",
"metrics",
"for",
"capture",
"statistics"
] | void capture_process_record(bam1_t *rec, uint32_t *coverage,
capture_metrics_t *cm_wgs, capture_metrics_t *cm_cap,
overlap_handler_t *olh, int32_t chrom_len,
bool remove_dups, bool remove_overlaps, bool remove_overlaps_mc,
uint8_t min_base_qual)
{
bool in_target, in_buffer, check_overlap;
uint8_t *qual, *bqual;
int32_t pos, start, start_pos, end_pos, ref_pos;
uint32_t target, oplen, *cigar;
uint64_t b_filt_overlap, b_filt_basequal;
uint64_t b_filt_target_overlap, b_filt_target_basequal;
const uint16_t FILTER = BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL;
const uint32_t COV_MAX = (UINT32_MAX - 1) >> 2;
if (cm_wgs != NULL) {
++cm_wgs->r_total;
}
if (cm_cap != NULL) {
++cm_cap->r_total;
}
if (rec->core.flag & FILTER) {
return;
}
if (cm_wgs != NULL) {
_capture_process_record1(rec, cm_wgs);
}
if (cm_cap != NULL) {
_capture_process_record1(rec, cm_cap);
}
if (remove_dups && (rec->core.flag & BAM_FDUP)) {
return;
}
process_record_overlap(olh, rec, remove_overlaps, remove_overlaps_mc);
in_target = false;
in_buffer = false;
ref_pos = 0;
start = rec->core.pos;
cigar = bam_get_cigar(rec);
bqual = bam_get_qual(rec);
b_filt_overlap = 0;
b_filt_basequal = 0;
b_filt_target_overlap = 0;
b_filt_target_basequal = 0;
overlap_pair_t *curr_overlap_pair, *overlap_pair_end;
check_overlap = (olh->n_overlap_pairs > 0);
if (check_overlap) {
curr_overlap_pair = olh->overlap_buffer;
overlap_pair_end = curr_overlap_pair + olh->n_overlap_pairs;
} else {
curr_overlap_pair = NULL;
overlap_pair_end = NULL;
}
for (uint32_t i = 0; i < rec->core.n_cigar; ++i) {
oplen = bam_cigar_oplen(cigar[i]);
switch (bam_cigar_op(cigar[i])) {
case BAM_CHARD_CLIP:
break;
case BAM_CMATCH:
case BAM_CEQUAL:
case BAM_CDIFF:
if (coverage != NULL) {
start_pos = pos = start + ref_pos;
end_pos = start_pos + oplen - 1;
if (start_pos < 0) {
start_pos = 0;
pos = 0;
}
if (end_pos >= chrom_len) {
end_pos = chrom_len - 1;
}
qual = bqual + ref_pos;
while (pos <= end_pos) {
if (get_coverage(coverage[pos]) < COV_MAX) {
if (check_overlap &&
pos >= curr_overlap_pair->start &&
pos < curr_overlap_pair->end)
{
++b_filt_overlap;
if (get_target(coverage[pos]) == TARGET_IN) {
++b_filt_target_overlap;
}
} else if (*qual < min_base_qual) {
++b_filt_basequal;
if (get_target(coverage[pos]) == TARGET_IN) {
++b_filt_target_overlap;
}
} else {
++coverage[pos];
}
} else {
log_warning("Coverage of greater than %u detected. "
"Coverage statistics may not be accurate.", COV_MAX);
}
++pos;
++qual;
if (check_overlap && pos >= curr_overlap_pair->end) {
++curr_overlap_pair;
if (curr_overlap_pair == overlap_pair_end) {
curr_overlap_pair = NULL;
overlap_pair_end = NULL;
check_overlap = false;
}
}
}
while (--pos >= start_pos) {
target = get_target(coverage[pos]);
if (target == TARGET_BUFFER) {
in_buffer = true;
} else if (target == TARGET_IN) {
in_target = true;
break;
}
}
}
ref_pos += oplen;
break;
case BAM_CDEL:
ref_pos += oplen;
break;
default:
break;
}
}
if (cm_wgs != NULL) {
cm_wgs->b_filt_overlap += b_filt_overlap;
cm_wgs->b_filt_basequal += b_filt_basequal;
_capture_process_record2(rec, cm_wgs, TARGET_OUT);
}
if (cm_cap != NULL) {
cm_cap->b_filt_overlap += b_filt_target_overlap;
cm_cap->b_filt_basequal += b_filt_target_basequal;
_capture_process_record2(rec, cm_cap, in_target ? TARGET_IN : in_buffer ? TARGET_BUFFER : TARGET_OUT);
}
} | [
"void",
"capture_process_record",
"(",
"bam1_t",
"*",
"rec",
",",
"uint32_t",
"*",
"coverage",
",",
"capture_metrics_t",
"*",
"cm_wgs",
",",
"capture_metrics_t",
"*",
"cm_cap",
",",
"overlap_handler_t",
"*",
"olh",
",",
"int32_t",
"chrom_len",
",",
"bool",
"remove_dups",
",",
"bool",
"remove_overlaps",
",",
"bool",
"remove_overlaps_mc",
",",
"uint8_t",
"min_base_qual",
")",
"{",
"bool",
"in_target",
",",
"in_buffer",
",",
"check_overlap",
";",
"uint8_t",
"*",
"qual",
",",
"*",
"bqual",
";",
"int32_t",
"pos",
",",
"start",
",",
"start_pos",
",",
"end_pos",
",",
"ref_pos",
";",
"uint32_t",
"target",
",",
"oplen",
",",
"*",
"cigar",
";",
"uint64_t",
"b_filt_overlap",
",",
"b_filt_basequal",
";",
"uint64_t",
"b_filt_target_overlap",
",",
"b_filt_target_basequal",
";",
"const",
"uint16_t",
"FILTER",
"=",
"BAM_FUNMAP",
"|",
"BAM_FSECONDARY",
"|",
"BAM_FQCFAIL",
";",
"const",
"uint32_t",
"COV_MAX",
"=",
"(",
"UINT32_MAX",
"-",
"1",
")",
">>",
"2",
";",
"if",
"(",
"cm_wgs",
"!=",
"NULL",
")",
"{",
"++",
"cm_wgs",
"->",
"r_total",
";",
"}",
"if",
"(",
"cm_cap",
"!=",
"NULL",
")",
"{",
"++",
"cm_cap",
"->",
"r_total",
";",
"}",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"FILTER",
")",
"{",
"return",
";",
"}",
"if",
"(",
"cm_wgs",
"!=",
"NULL",
")",
"{",
"_capture_process_record1",
"(",
"rec",
",",
"cm_wgs",
")",
";",
"}",
"if",
"(",
"cm_cap",
"!=",
"NULL",
")",
"{",
"_capture_process_record1",
"(",
"rec",
",",
"cm_cap",
")",
";",
"}",
"if",
"(",
"remove_dups",
"&&",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FDUP",
")",
")",
"{",
"return",
";",
"}",
"process_record_overlap",
"(",
"olh",
",",
"rec",
",",
"remove_overlaps",
",",
"remove_overlaps_mc",
")",
";",
"in_target",
"=",
"false",
";",
"in_buffer",
"=",
"false",
";",
"ref_pos",
"=",
"0",
";",
"start",
"=",
"rec",
"->",
"core",
".",
"pos",
";",
"cigar",
"=",
"bam_get_cigar",
"(",
"rec",
")",
";",
"bqual",
"=",
"bam_get_qual",
"(",
"rec",
")",
";",
"b_filt_overlap",
"=",
"0",
";",
"b_filt_basequal",
"=",
"0",
";",
"b_filt_target_overlap",
"=",
"0",
";",
"b_filt_target_basequal",
"=",
"0",
";",
"overlap_pair_t",
"*",
"curr_overlap_pair",
",",
"*",
"overlap_pair_end",
";",
"check_overlap",
"=",
"(",
"olh",
"->",
"n_overlap_pairs",
">",
"0",
")",
";",
"if",
"(",
"check_overlap",
")",
"{",
"curr_overlap_pair",
"=",
"olh",
"->",
"overlap_buffer",
";",
"overlap_pair_end",
"=",
"curr_overlap_pair",
"+",
"olh",
"->",
"n_overlap_pairs",
";",
"}",
"else",
"{",
"curr_overlap_pair",
"=",
"NULL",
";",
"overlap_pair_end",
"=",
"NULL",
";",
"}",
"for",
"(",
"uint32_t",
"i",
"=",
"0",
";",
"i",
"<",
"rec",
"->",
"core",
".",
"n_cigar",
";",
"++",
"i",
")",
"{",
"oplen",
"=",
"bam_cigar_oplen",
"(",
"cigar",
"[",
"i",
"]",
")",
";",
"switch",
"(",
"bam_cigar_op",
"(",
"cigar",
"[",
"i",
"]",
")",
")",
"{",
"case",
"BAM_CHARD_CLIP",
":",
"break",
";",
"case",
"BAM_CMATCH",
":",
"case",
"BAM_CEQUAL",
":",
"case",
"BAM_CDIFF",
":",
"if",
"(",
"coverage",
"!=",
"NULL",
")",
"{",
"start_pos",
"=",
"pos",
"=",
"start",
"+",
"ref_pos",
";",
"end_pos",
"=",
"start_pos",
"+",
"oplen",
"-",
"1",
";",
"if",
"(",
"start_pos",
"<",
"0",
")",
"{",
"start_pos",
"=",
"0",
";",
"pos",
"=",
"0",
";",
"}",
"if",
"(",
"end_pos",
">=",
"chrom_len",
")",
"{",
"end_pos",
"=",
"chrom_len",
"-",
"1",
";",
"}",
"qual",
"=",
"bqual",
"+",
"ref_pos",
";",
"while",
"(",
"pos",
"<=",
"end_pos",
")",
"{",
"if",
"(",
"get_coverage",
"(",
"coverage",
"[",
"pos",
"]",
")",
"<",
"COV_MAX",
")",
"{",
"if",
"(",
"check_overlap",
"&&",
"pos",
">=",
"curr_overlap_pair",
"->",
"start",
"&&",
"pos",
"<",
"curr_overlap_pair",
"->",
"end",
")",
"{",
"++",
"b_filt_overlap",
";",
"if",
"(",
"get_target",
"(",
"coverage",
"[",
"pos",
"]",
")",
"==",
"TARGET_IN",
")",
"{",
"++",
"b_filt_target_overlap",
";",
"}",
"}",
"else",
"if",
"(",
"*",
"qual",
"<",
"min_base_qual",
")",
"{",
"++",
"b_filt_basequal",
";",
"if",
"(",
"get_target",
"(",
"coverage",
"[",
"pos",
"]",
")",
"==",
"TARGET_IN",
")",
"{",
"++",
"b_filt_target_overlap",
";",
"}",
"}",
"else",
"{",
"++",
"coverage",
"[",
"pos",
"]",
";",
"}",
"}",
"else",
"{",
"log_warning",
"(",
"\"",
"\"",
"\"",
"\"",
",",
"COV_MAX",
")",
";",
"}",
"++",
"pos",
";",
"++",
"qual",
";",
"if",
"(",
"check_overlap",
"&&",
"pos",
">=",
"curr_overlap_pair",
"->",
"end",
")",
"{",
"++",
"curr_overlap_pair",
";",
"if",
"(",
"curr_overlap_pair",
"==",
"overlap_pair_end",
")",
"{",
"curr_overlap_pair",
"=",
"NULL",
";",
"overlap_pair_end",
"=",
"NULL",
";",
"check_overlap",
"=",
"false",
";",
"}",
"}",
"}",
"while",
"(",
"--",
"pos",
">=",
"start_pos",
")",
"{",
"target",
"=",
"get_target",
"(",
"coverage",
"[",
"pos",
"]",
")",
";",
"if",
"(",
"target",
"==",
"TARGET_BUFFER",
")",
"{",
"in_buffer",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"target",
"==",
"TARGET_IN",
")",
"{",
"in_target",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"ref_pos",
"+=",
"oplen",
";",
"break",
";",
"case",
"BAM_CDEL",
":",
"ref_pos",
"+=",
"oplen",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"if",
"(",
"cm_wgs",
"!=",
"NULL",
")",
"{",
"cm_wgs",
"->",
"b_filt_overlap",
"+=",
"b_filt_overlap",
";",
"cm_wgs",
"->",
"b_filt_basequal",
"+=",
"b_filt_basequal",
";",
"_capture_process_record2",
"(",
"rec",
",",
"cm_wgs",
",",
"TARGET_OUT",
")",
";",
"}",
"if",
"(",
"cm_cap",
"!=",
"NULL",
")",
"{",
"cm_cap",
"->",
"b_filt_overlap",
"+=",
"b_filt_target_overlap",
";",
"cm_cap",
"->",
"b_filt_basequal",
"+=",
"b_filt_target_basequal",
";",
"_capture_process_record2",
"(",
"rec",
",",
"cm_cap",
",",
"in_target",
"?",
"TARGET_IN",
":",
"in_buffer",
"?",
"TARGET_BUFFER",
":",
"TARGET_OUT",
")",
";",
"}",
"}"
] | Process record for target and coverage info. | [
"Process",
"record",
"for",
"target",
"and",
"coverage",
"info",
"."
] | [
"/* Filter out reads with filtered flags */",
"/* remove duplicate reads */",
"/* process record for possible overlap with mate pair */",
"/*\n * Record coverage and whether aligned bases hit target or buffer\n * Confirmed this now matches up with the correct ref pos and # CIGAR Ms\n */",
"/* for each CIGAR op */",
"/*\n * M, =, X: record coverage for CIGAR M bases (matches + mismatches)\n * or = (matches) and X (mismatches)\n */",
"/* Record coverage */",
"/* Y'know just in case */",
"/* if pos is past current overlap pair, advance to next */",
"/* no more overlap pairs */",
"/* pos == end_pos */",
"/* D: advance ref_pos past deletion */"
] | [
{
"param": "rec",
"type": "bam1_t"
},
{
"param": "coverage",
"type": "uint32_t"
},
{
"param": "cm_wgs",
"type": "capture_metrics_t"
},
{
"param": "cm_cap",
"type": "capture_metrics_t"
},
{
"param": "olh",
"type": "overlap_handler_t"
},
{
"param": "chrom_len",
"type": "int32_t"
},
{
"param": "remove_dups",
"type": "bool"
},
{
"param": "remove_overlaps",
"type": "bool"
},
{
"param": "remove_overlaps_mc",
"type": "bool"
},
{
"param": "min_base_qual",
"type": "uint8_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "coverage",
"type": "uint32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cm_wgs",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "cm_cap",
"type": "capture_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "olh",
"type": "overlap_handler_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "chrom_len",
"type": "int32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "remove_dups",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "remove_overlaps",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "remove_overlaps_mc",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "min_base_qual",
"type": "uint8_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d6359fc2208bfd8b943bec0c6045397504d6a0c9 | jfarek/alignstats | alignlen.c | [
"BSD-3-Clause"
] | C | align_len_process_record | void | void align_len_process_record(bam1_t *rec, align_len_metrics_t *alm)
{
int32_t aligned_len, num_s;
uint32_t *cigar;
tree_node_t *node;
if (!(rec->core.flag & BAM_FUNMAP)) {
num_s = 0;
cigar = bam_get_cigar(rec);
/* Count number of CIGAR S bases in record */
for (uint32_t i = 0; i < rec->core.n_cigar; ++i) {
if (bam_cigar_op(cigar[i]) == BAM_CSOFT_CLIP) {
num_s += bam_cigar_oplen(cigar[i]);
}
}
/* Increment alignment length count */
aligned_len = rec->core.l_qseq - num_s;
node = tree_map_get(alm->length_map, aligned_len);
tree_map_set(alm->length_map, aligned_len, (node == NULL) ? 1 : node->value + 1);
alm->sum_sq += (uint64_t)aligned_len * (uint64_t)aligned_len;
}
} | /**
* Process a bam1_t record for alignment length metrics.
*/ | Process a bam1_t record for alignment length metrics. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"alignment",
"length",
"metrics",
"."
] | void align_len_process_record(bam1_t *rec, align_len_metrics_t *alm)
{
int32_t aligned_len, num_s;
uint32_t *cigar;
tree_node_t *node;
if (!(rec->core.flag & BAM_FUNMAP)) {
num_s = 0;
cigar = bam_get_cigar(rec);
for (uint32_t i = 0; i < rec->core.n_cigar; ++i) {
if (bam_cigar_op(cigar[i]) == BAM_CSOFT_CLIP) {
num_s += bam_cigar_oplen(cigar[i]);
}
}
aligned_len = rec->core.l_qseq - num_s;
node = tree_map_get(alm->length_map, aligned_len);
tree_map_set(alm->length_map, aligned_len, (node == NULL) ? 1 : node->value + 1);
alm->sum_sq += (uint64_t)aligned_len * (uint64_t)aligned_len;
}
} | [
"void",
"align_len_process_record",
"(",
"bam1_t",
"*",
"rec",
",",
"align_len_metrics_t",
"*",
"alm",
")",
"{",
"int32_t",
"aligned_len",
",",
"num_s",
";",
"uint32_t",
"*",
"cigar",
";",
"tree_node_t",
"*",
"node",
";",
"if",
"(",
"!",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FUNMAP",
")",
")",
"{",
"num_s",
"=",
"0",
";",
"cigar",
"=",
"bam_get_cigar",
"(",
"rec",
")",
";",
"for",
"(",
"uint32_t",
"i",
"=",
"0",
";",
"i",
"<",
"rec",
"->",
"core",
".",
"n_cigar",
";",
"++",
"i",
")",
"{",
"if",
"(",
"bam_cigar_op",
"(",
"cigar",
"[",
"i",
"]",
")",
"==",
"BAM_CSOFT_CLIP",
")",
"{",
"num_s",
"+=",
"bam_cigar_oplen",
"(",
"cigar",
"[",
"i",
"]",
")",
";",
"}",
"}",
"aligned_len",
"=",
"rec",
"->",
"core",
".",
"l_qseq",
"-",
"num_s",
";",
"node",
"=",
"tree_map_get",
"(",
"alm",
"->",
"length_map",
",",
"aligned_len",
")",
";",
"tree_map_set",
"(",
"alm",
"->",
"length_map",
",",
"aligned_len",
",",
"(",
"node",
"==",
"NULL",
")",
"?",
"1",
":",
"node",
"->",
"value",
"+",
"1",
")",
";",
"alm",
"->",
"sum_sq",
"+=",
"(",
"uint64_t",
")",
"aligned_len",
"*",
"(",
"uint64_t",
")",
"aligned_len",
";",
"}",
"}"
] | Process a bam1_t record for alignment length metrics. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"alignment",
"length",
"metrics",
"."
] | [
"/* Count number of CIGAR S bases in record */",
"/* Increment alignment length count */"
] | [
{
"param": "rec",
"type": "bam1_t"
},
{
"param": "alm",
"type": "align_len_metrics_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "alm",
"type": "align_len_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d6359fc2208bfd8b943bec0c6045397504d6a0c9 | jfarek/alignstats | alignlen.c | [
"BSD-3-Clause"
] | C | align_len_finalize | void | void align_len_finalize(align_len_metrics_t *alm)
{
tree_node_key_t *keyset;
tree_node_t *node;
uint64_t k, sum, mode_length, curr_length, median_idx;
bool median_set = false;
if (tree_map_set_keyset(&keyset, alm->length_map)) {
k = sum = mode_length = 0;
/* Mean and mode alignment lengths */
for (size_t i = 0; i < alm->length_map->num_nodes; ++i) {
if (!tree_map_set_node(&node, alm->length_map, keyset[i])) {
goto fail;
}
if ((curr_length = (uint64_t)node->value) > mode_length) {
mode_length = curr_length;
alm->mode = (uint64_t)keyset[i];
}
k += curr_length;
sum += (uint64_t)keyset[i] * curr_length;
}
if (k != 0) {
alm->mean = (double)sum / (double)k;
/* Median alignment length */
median_idx = k / 2;
k = 0;
for (size_t i = 0; i < alm->length_map->num_nodes; ++i) {
if (!tree_map_set_node(&node, alm->length_map, keyset[i])) {
goto fail;
}
k += (uint64_t)node->value;
if (!median_set && k >= median_idx) {
alm->median = (uint64_t)keyset[i];
median_set = true;
}
}
alm->std_dev = k > 1
? sqrt(((double)alm->sum_sq - (double)sum * ((double)sum / (double)k)) /
(double)(k - 1))
: 0.0;
} else {
alm->mean = 0.0;
alm->median = 0;
alm->std_dev = 0.0;
}
fail:
free(keyset);
}
} | /**
* Finalize alignment length metrics once all records are processed.
* Calculates mean, median, and mode alignment lengths.
*/ | Finalize alignment length metrics once all records are processed.
Calculates mean, median, and mode alignment lengths. | [
"Finalize",
"alignment",
"length",
"metrics",
"once",
"all",
"records",
"are",
"processed",
".",
"Calculates",
"mean",
"median",
"and",
"mode",
"alignment",
"lengths",
"."
] | void align_len_finalize(align_len_metrics_t *alm)
{
tree_node_key_t *keyset;
tree_node_t *node;
uint64_t k, sum, mode_length, curr_length, median_idx;
bool median_set = false;
if (tree_map_set_keyset(&keyset, alm->length_map)) {
k = sum = mode_length = 0;
for (size_t i = 0; i < alm->length_map->num_nodes; ++i) {
if (!tree_map_set_node(&node, alm->length_map, keyset[i])) {
goto fail;
}
if ((curr_length = (uint64_t)node->value) > mode_length) {
mode_length = curr_length;
alm->mode = (uint64_t)keyset[i];
}
k += curr_length;
sum += (uint64_t)keyset[i] * curr_length;
}
if (k != 0) {
alm->mean = (double)sum / (double)k;
median_idx = k / 2;
k = 0;
for (size_t i = 0; i < alm->length_map->num_nodes; ++i) {
if (!tree_map_set_node(&node, alm->length_map, keyset[i])) {
goto fail;
}
k += (uint64_t)node->value;
if (!median_set && k >= median_idx) {
alm->median = (uint64_t)keyset[i];
median_set = true;
}
}
alm->std_dev = k > 1
? sqrt(((double)alm->sum_sq - (double)sum * ((double)sum / (double)k)) /
(double)(k - 1))
: 0.0;
} else {
alm->mean = 0.0;
alm->median = 0;
alm->std_dev = 0.0;
}
fail:
free(keyset);
}
} | [
"void",
"align_len_finalize",
"(",
"align_len_metrics_t",
"*",
"alm",
")",
"{",
"tree_node_key_t",
"*",
"keyset",
";",
"tree_node_t",
"*",
"node",
";",
"uint64_t",
"k",
",",
"sum",
",",
"mode_length",
",",
"curr_length",
",",
"median_idx",
";",
"bool",
"median_set",
"=",
"false",
";",
"if",
"(",
"tree_map_set_keyset",
"(",
"&",
"keyset",
",",
"alm",
"->",
"length_map",
")",
")",
"{",
"k",
"=",
"sum",
"=",
"mode_length",
"=",
"0",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"i",
"<",
"alm",
"->",
"length_map",
"->",
"num_nodes",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"tree_map_set_node",
"(",
"&",
"node",
",",
"alm",
"->",
"length_map",
",",
"keyset",
"[",
"i",
"]",
")",
")",
"{",
"goto",
"fail",
";",
"}",
"if",
"(",
"(",
"curr_length",
"=",
"(",
"uint64_t",
")",
"node",
"->",
"value",
")",
">",
"mode_length",
")",
"{",
"mode_length",
"=",
"curr_length",
";",
"alm",
"->",
"mode",
"=",
"(",
"uint64_t",
")",
"keyset",
"[",
"i",
"]",
";",
"}",
"k",
"+=",
"curr_length",
";",
"sum",
"+=",
"(",
"uint64_t",
")",
"keyset",
"[",
"i",
"]",
"*",
"curr_length",
";",
"}",
"if",
"(",
"k",
"!=",
"0",
")",
"{",
"alm",
"->",
"mean",
"=",
"(",
"double",
")",
"sum",
"/",
"(",
"double",
")",
"k",
";",
"median_idx",
"=",
"k",
"/",
"2",
";",
"k",
"=",
"0",
";",
"for",
"(",
"size_t",
"i",
"=",
"0",
";",
"i",
"<",
"alm",
"->",
"length_map",
"->",
"num_nodes",
";",
"++",
"i",
")",
"{",
"if",
"(",
"!",
"tree_map_set_node",
"(",
"&",
"node",
",",
"alm",
"->",
"length_map",
",",
"keyset",
"[",
"i",
"]",
")",
")",
"{",
"goto",
"fail",
";",
"}",
"k",
"+=",
"(",
"uint64_t",
")",
"node",
"->",
"value",
";",
"if",
"(",
"!",
"median_set",
"&&",
"k",
">=",
"median_idx",
")",
"{",
"alm",
"->",
"median",
"=",
"(",
"uint64_t",
")",
"keyset",
"[",
"i",
"]",
";",
"median_set",
"=",
"true",
";",
"}",
"}",
"alm",
"->",
"std_dev",
"=",
"k",
">",
"1",
"?",
"sqrt",
"(",
"(",
"(",
"double",
")",
"alm",
"->",
"sum_sq",
"-",
"(",
"double",
")",
"sum",
"*",
"(",
"(",
"double",
")",
"sum",
"/",
"(",
"double",
")",
"k",
")",
")",
"/",
"(",
"double",
")",
"(",
"k",
"-",
"1",
")",
")",
":",
"0.0",
";",
"}",
"else",
"{",
"alm",
"->",
"mean",
"=",
"0.0",
";",
"alm",
"->",
"median",
"=",
"0",
";",
"alm",
"->",
"std_dev",
"=",
"0.0",
";",
"}",
"fail",
":",
"free",
"(",
"keyset",
")",
";",
"}",
"}"
] | Finalize alignment length metrics once all records are processed. | [
"Finalize",
"alignment",
"length",
"metrics",
"once",
"all",
"records",
"are",
"processed",
"."
] | [
"/* Mean and mode alignment lengths */",
"/* Median alignment length */"
] | [
{
"param": "alm",
"type": "align_len_metrics_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "alm",
"type": "align_len_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d6359fc2208bfd8b943bec0c6045397504d6a0c9 | jfarek/alignstats | alignlen.c | [
"BSD-3-Clause"
] | C | align_len_report | void | void align_len_report(report_t *report, align_len_metrics_t *alm, read_type_t rt, char *key_buffer, char *value_buffer)
{
char *key_start;
size_t prefix_len, copy_size;
/*
* Add key prefix for read1 and read2
* All reads: prefix = ""
*/
const char *prefix = (rt == RT_READ1) ? "R1" : rt == RT_READ2 ? "R2" : "";
prefix_len = strlen(prefix);
copy_to_buffer(key_buffer, prefix, REPORT_BUFFER_SIZE);
key_start = key_buffer + strlen(prefix);
copy_size = REPORT_BUFFER_SIZE - prefix_len;
copy_to_buffer(key_start, "AlignedReadLengthMean", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%f", alm->mean);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_start, "AlignedReadLengthMedian", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", alm->median);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_start, "AlignedReadLengthMode", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", alm->mode);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_start, "AlignedReadLengthStandardDeviation", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%f", alm->std_dev);
report_add_key_value(report, key_buffer, value_buffer);
} | /**
* Add alignment length metrics to report.
*/ | Add alignment length metrics to report. | [
"Add",
"alignment",
"length",
"metrics",
"to",
"report",
"."
] | void align_len_report(report_t *report, align_len_metrics_t *alm, read_type_t rt, char *key_buffer, char *value_buffer)
{
char *key_start;
size_t prefix_len, copy_size;
const char *prefix = (rt == RT_READ1) ? "R1" : rt == RT_READ2 ? "R2" : "";
prefix_len = strlen(prefix);
copy_to_buffer(key_buffer, prefix, REPORT_BUFFER_SIZE);
key_start = key_buffer + strlen(prefix);
copy_size = REPORT_BUFFER_SIZE - prefix_len;
copy_to_buffer(key_start, "AlignedReadLengthMean", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%f", alm->mean);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_start, "AlignedReadLengthMedian", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", alm->median);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_start, "AlignedReadLengthMode", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", alm->mode);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_start, "AlignedReadLengthStandardDeviation", copy_size);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%f", alm->std_dev);
report_add_key_value(report, key_buffer, value_buffer);
} | [
"void",
"align_len_report",
"(",
"report_t",
"*",
"report",
",",
"align_len_metrics_t",
"*",
"alm",
",",
"read_type_t",
"rt",
",",
"char",
"*",
"key_buffer",
",",
"char",
"*",
"value_buffer",
")",
"{",
"char",
"*",
"key_start",
";",
"size_t",
"prefix_len",
",",
"copy_size",
";",
"const",
"char",
"*",
"prefix",
"=",
"(",
"rt",
"==",
"RT_READ1",
")",
"?",
"\"",
"\"",
":",
"rt",
"==",
"RT_READ2",
"?",
"\"",
"\"",
":",
"\"",
"\"",
";",
"prefix_len",
"=",
"strlen",
"(",
"prefix",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"prefix",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"key_start",
"=",
"key_buffer",
"+",
"strlen",
"(",
"prefix",
")",
";",
"copy_size",
"=",
"REPORT_BUFFER_SIZE",
"-",
"prefix_len",
";",
"copy_to_buffer",
"(",
"key_start",
",",
"\"",
"\"",
",",
"copy_size",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"alm",
"->",
"mean",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_start",
",",
"\"",
"\"",
",",
"copy_size",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"alm",
"->",
"median",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_start",
",",
"\"",
"\"",
",",
"copy_size",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"alm",
"->",
"mode",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_start",
",",
"\"",
"\"",
",",
"copy_size",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"alm",
"->",
"std_dev",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"}"
] | Add alignment length metrics to report. | [
"Add",
"alignment",
"length",
"metrics",
"to",
"report",
"."
] | [
"/*\n * Add key prefix for read1 and read2\n * All reads: prefix = \"\"\n */"
] | [
{
"param": "report",
"type": "report_t"
},
{
"param": "alm",
"type": "align_len_metrics_t"
},
{
"param": "rt",
"type": "read_type_t"
},
{
"param": "key_buffer",
"type": "char"
},
{
"param": "value_buffer",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "report",
"type": "report_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "alm",
"type": "align_len_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "rt",
"type": "read_type_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "key_buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value_buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
139984b6fd63305cd40d8dfe909ba5cb1b8fcbed | jfarek/alignstats | filter.c | [
"BSD-3-Clause"
] | C | filter_counter_init | filter_counter_t | filter_counter_t *filter_counter_init(uint8_t min_qual, uint16_t filter_incl, uint16_t filter_excl)
{
filter_counter_t *fc = calloc(1, sizeof(filter_counter_t));
die_on_alloc_fail(fc);
/* global record filter */
fc->min_qual = min_qual;
fc->filter_incl = filter_incl;
fc->filter_excl = filter_excl;
fc->r_filtered = 0;
fc->r_unfiltered = 0;
return fc;
} | /**
* Create new *filter_counter_t and initialize values
*/ | Create new *filter_counter_t and initialize values | [
"Create",
"new",
"*",
"filter_counter_t",
"and",
"initialize",
"values"
] | filter_counter_t *filter_counter_init(uint8_t min_qual, uint16_t filter_incl, uint16_t filter_excl)
{
filter_counter_t *fc = calloc(1, sizeof(filter_counter_t));
die_on_alloc_fail(fc);
fc->min_qual = min_qual;
fc->filter_incl = filter_incl;
fc->filter_excl = filter_excl;
fc->r_filtered = 0;
fc->r_unfiltered = 0;
return fc;
} | [
"filter_counter_t",
"*",
"filter_counter_init",
"(",
"uint8_t",
"min_qual",
",",
"uint16_t",
"filter_incl",
",",
"uint16_t",
"filter_excl",
")",
"{",
"filter_counter_t",
"*",
"fc",
"=",
"calloc",
"(",
"1",
",",
"sizeof",
"(",
"filter_counter_t",
")",
")",
";",
"die_on_alloc_fail",
"(",
"fc",
")",
";",
"fc",
"->",
"min_qual",
"=",
"min_qual",
";",
"fc",
"->",
"filter_incl",
"=",
"filter_incl",
";",
"fc",
"->",
"filter_excl",
"=",
"filter_excl",
";",
"fc",
"->",
"r_filtered",
"=",
"0",
";",
"fc",
"->",
"r_unfiltered",
"=",
"0",
";",
"return",
"fc",
";",
"}"
] | Create new *filter_counter_t and initialize values | [
"Create",
"new",
"*",
"filter_counter_t",
"and",
"initialize",
"values"
] | [
"/* global record filter */"
] | [
{
"param": "min_qual",
"type": "uint8_t"
},
{
"param": "filter_incl",
"type": "uint16_t"
},
{
"param": "filter_excl",
"type": "uint16_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "min_qual",
"type": "uint8_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "filter_incl",
"type": "uint16_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "filter_excl",
"type": "uint16_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
139984b6fd63305cd40d8dfe909ba5cb1b8fcbed | jfarek/alignstats | filter.c | [
"BSD-3-Clause"
] | C | filter_counter_process_record | void | void filter_counter_process_record(bam1_t *rec, filter_counter_t *fc)
{
if (filter_test_qual(rec->core.qual, fc->min_qual) ||
filter_test_flag(rec->core.flag, fc->filter_incl, fc->filter_excl))
{
++fc->r_filtered;
} else {
++fc->r_unfiltered;
}
} | /**
* Process a bam1_t record for filter counter.
*/ | Process a bam1_t record for filter counter. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"filter",
"counter",
"."
] | void filter_counter_process_record(bam1_t *rec, filter_counter_t *fc)
{
if (filter_test_qual(rec->core.qual, fc->min_qual) ||
filter_test_flag(rec->core.flag, fc->filter_incl, fc->filter_excl))
{
++fc->r_filtered;
} else {
++fc->r_unfiltered;
}
} | [
"void",
"filter_counter_process_record",
"(",
"bam1_t",
"*",
"rec",
",",
"filter_counter_t",
"*",
"fc",
")",
"{",
"if",
"(",
"filter_test_qual",
"(",
"rec",
"->",
"core",
".",
"qual",
",",
"fc",
"->",
"min_qual",
")",
"||",
"filter_test_flag",
"(",
"rec",
"->",
"core",
".",
"flag",
",",
"fc",
"->",
"filter_incl",
",",
"fc",
"->",
"filter_excl",
")",
")",
"{",
"++",
"fc",
"->",
"r_filtered",
";",
"}",
"else",
"{",
"++",
"fc",
"->",
"r_unfiltered",
";",
"}",
"}"
] | Process a bam1_t record for filter counter. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"filter",
"counter",
"."
] | [] | [
{
"param": "rec",
"type": "bam1_t"
},
{
"param": "fc",
"type": "filter_counter_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fc",
"type": "filter_counter_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
139984b6fd63305cd40d8dfe909ba5cb1b8fcbed | jfarek/alignstats | filter.c | [
"BSD-3-Clause"
] | C | filter_counter_report | void | void filter_counter_report(report_t *report, filter_counter_t *fc, char *key_buffer, char *value_buffer)
{
uint64_t r_total = fc->r_filtered + fc->r_unfiltered;
copy_to_buffer(key_buffer, "TotalRecords", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", r_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnfilteredRecords", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", fc->r_unfiltered);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnfilteredRecordsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, fc->r_unfiltered, r_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "FilteredRecords", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", fc->r_filtered);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "FilteredRecordsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, fc->r_filtered, r_total);
report_add_key_value(report, key_buffer, value_buffer);
} | /**
* Write metrics in fc to report.
*/ | Write metrics in fc to report. | [
"Write",
"metrics",
"in",
"fc",
"to",
"report",
"."
] | void filter_counter_report(report_t *report, filter_counter_t *fc, char *key_buffer, char *value_buffer)
{
uint64_t r_total = fc->r_filtered + fc->r_unfiltered;
copy_to_buffer(key_buffer, "TotalRecords", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", r_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnfilteredRecords", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", fc->r_unfiltered);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnfilteredRecordsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, fc->r_unfiltered, r_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "FilteredRecords", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", fc->r_filtered);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "FilteredRecordsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, fc->r_filtered, r_total);
report_add_key_value(report, key_buffer, value_buffer);
} | [
"void",
"filter_counter_report",
"(",
"report_t",
"*",
"report",
",",
"filter_counter_t",
"*",
"fc",
",",
"char",
"*",
"key_buffer",
",",
"char",
"*",
"value_buffer",
")",
"{",
"uint64_t",
"r_total",
"=",
"fc",
"->",
"r_filtered",
"+",
"fc",
"->",
"r_unfiltered",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"r_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"fc",
"->",
"r_unfiltered",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"fc",
"->",
"r_unfiltered",
",",
"r_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"fc",
"->",
"r_filtered",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"fc",
"->",
"r_filtered",
",",
"r_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"}"
] | Write metrics in fc to report. | [
"Write",
"metrics",
"in",
"fc",
"to",
"report",
"."
] | [] | [
{
"param": "report",
"type": "report_t"
},
{
"param": "fc",
"type": "filter_counter_t"
},
{
"param": "key_buffer",
"type": "char"
},
{
"param": "value_buffer",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "report",
"type": "report_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "fc",
"type": "filter_counter_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "key_buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value_buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
a9c36a085eb9a46fcdc8e96567c8ff457e90e86a | jfarek/alignstats | align.c | [
"BSD-3-Clause"
] | C | align_process_record | void | void align_process_record(bam1_t *rec, align_metrics_t *am, bool process_cigar)
{
char op;
uint8_t *nm_tag, /* *md_tag,*/ *qual;
int32_t pos, end_pos;
uint32_t oplen, *cigar;
uint64_t num_m, num_i, num_d, num_s, num_eq, num_x;
uint64_t num_matches, num_mismatches, num_aligned;
/* Total reads */
++am->r_total;
am->b_total += rec->core.l_qseq;
/* Unmapped reads */
if (rec->core.flag & BAM_FUNMAP) {
++am->r_unmapped;
am->b_unmapped += rec->core.l_qseq;
} else {
/* Mapped reads */
++am->r_mapped;
am->b_mapped += rec->core.l_qseq;
/* Aligned reads: filter out reads with filtered flags */
if (!(rec->core.flag & am->filter)) {
++am->r_aligned;
/* Duplicate reads */
if (rec->core.flag & BAM_FDUP) {
++am->r_dup;
am->b_dup += rec->core.l_qseq;
}
if (process_cigar) {
qual = bam_get_qual(rec);
cigar = bam_get_cigar(rec);
pos = 0;
num_m = num_i = num_d = num_s = num_eq = num_x = 0;
/* Count M, I, D, S in CIGAR string (processCIGAR) */
/* for each CIGAR operator */
for (uint32_t i = 0; i < rec->core.n_cigar; ++i) {
op = bam_cigar_op(cigar[i]);
oplen = bam_cigar_oplen(cigar[i]);
/* Sum the length of these operators */
switch (op) {
case BAM_CMATCH:
num_m += oplen;
break;
case BAM_CEQUAL:
num_eq += oplen;
break;
case BAM_CDIFF:
num_x += oplen;
break;
case BAM_CINS:
num_i += oplen;
break;
case BAM_CSOFT_CLIP:
num_s += oplen;
pos += (int32_t)oplen;
break;
case BAM_CDEL:
num_d += oplen;
break;
default:
break;
}
switch (op) {
case BAM_CMATCH:
case BAM_CEQUAL:
case BAM_CDIFF:
case BAM_CINS:
end_pos = pos + (int32_t)oplen;
/* for each aligned base check qual and increment pos */
while (pos < end_pos) {
if (qual[pos++] >= 20) {
++am->b_q20;
}
}
break;
default:
break;
}
}
/*
* Count mismatches from NM or MD tag if present.
* if num_mismatches was calculated from an MD tag, subtract dels
* otherwise num_mismatches becomes num_x
*/
if ((nm_tag = bam_aux_get(rec, "NM")) != NULL) {
num_mismatches = bam_aux2i(nm_tag);
num_mismatches -= num_d;
num_matches = num_m - num_mismatches;
}
/*
else if ((md_tag = bam_aux_get(rec, "MD")) != NULL) {
num_mismatches = 0;
for (char *md_str = bam_aux2Z(md_tag); *md_str != '\0'; ++md_str) {
if (isalpha(*md_str)) {
++num_mismatches;
}
}
num_mismatches -= num_d;
num_matches = num_m - num_mismatches;
}
*/
else {
num_mismatches = num_x;
num_matches = (num_m > num_eq) ? num_m - num_mismatches : num_eq;
}
/*
* Set alignment metrics
* b_matched + b_mismatched == num_m
* num_m + b_inserted == b_aligned
* b_aligned + b_soft_clipped == b_mapped == l_qseq
*/
num_aligned = rec->core.l_qseq;
if (num_s > 0) {
++am->r_soft_clipped;
am->b_soft_clipped += num_s;
num_aligned -= num_s;
}
am->b_aligned += num_aligned;
am->b_matched += num_matches;
am->b_mismatched += num_mismatches;
am->b_inserted += num_i;
am->b_deleted += num_d;
/* Exact matches: no mismatches, insertions, or deletions */
if (num_mismatches + num_d + num_i == 0) {
++am->r_exact_match;
am->b_exact_match += num_aligned;
}
}
}
}
} | /**
* Process a bam1_t record for alignment metrics.
*/ | Process a bam1_t record for alignment metrics. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"alignment",
"metrics",
"."
] | void align_process_record(bam1_t *rec, align_metrics_t *am, bool process_cigar)
{
char op;
uint8_t *nm_tag, *qual;
int32_t pos, end_pos;
uint32_t oplen, *cigar;
uint64_t num_m, num_i, num_d, num_s, num_eq, num_x;
uint64_t num_matches, num_mismatches, num_aligned;
++am->r_total;
am->b_total += rec->core.l_qseq;
if (rec->core.flag & BAM_FUNMAP) {
++am->r_unmapped;
am->b_unmapped += rec->core.l_qseq;
} else {
++am->r_mapped;
am->b_mapped += rec->core.l_qseq;
if (!(rec->core.flag & am->filter)) {
++am->r_aligned;
if (rec->core.flag & BAM_FDUP) {
++am->r_dup;
am->b_dup += rec->core.l_qseq;
}
if (process_cigar) {
qual = bam_get_qual(rec);
cigar = bam_get_cigar(rec);
pos = 0;
num_m = num_i = num_d = num_s = num_eq = num_x = 0;
for (uint32_t i = 0; i < rec->core.n_cigar; ++i) {
op = bam_cigar_op(cigar[i]);
oplen = bam_cigar_oplen(cigar[i]);
switch (op) {
case BAM_CMATCH:
num_m += oplen;
break;
case BAM_CEQUAL:
num_eq += oplen;
break;
case BAM_CDIFF:
num_x += oplen;
break;
case BAM_CINS:
num_i += oplen;
break;
case BAM_CSOFT_CLIP:
num_s += oplen;
pos += (int32_t)oplen;
break;
case BAM_CDEL:
num_d += oplen;
break;
default:
break;
}
switch (op) {
case BAM_CMATCH:
case BAM_CEQUAL:
case BAM_CDIFF:
case BAM_CINS:
end_pos = pos + (int32_t)oplen;
while (pos < end_pos) {
if (qual[pos++] >= 20) {
++am->b_q20;
}
}
break;
default:
break;
}
}
if ((nm_tag = bam_aux_get(rec, "NM")) != NULL) {
num_mismatches = bam_aux2i(nm_tag);
num_mismatches -= num_d;
num_matches = num_m - num_mismatches;
}
else {
num_mismatches = num_x;
num_matches = (num_m > num_eq) ? num_m - num_mismatches : num_eq;
}
num_aligned = rec->core.l_qseq;
if (num_s > 0) {
++am->r_soft_clipped;
am->b_soft_clipped += num_s;
num_aligned -= num_s;
}
am->b_aligned += num_aligned;
am->b_matched += num_matches;
am->b_mismatched += num_mismatches;
am->b_inserted += num_i;
am->b_deleted += num_d;
if (num_mismatches + num_d + num_i == 0) {
++am->r_exact_match;
am->b_exact_match += num_aligned;
}
}
}
}
} | [
"void",
"align_process_record",
"(",
"bam1_t",
"*",
"rec",
",",
"align_metrics_t",
"*",
"am",
",",
"bool",
"process_cigar",
")",
"{",
"char",
"op",
";",
"uint8_t",
"*",
"nm_tag",
",",
"*",
"qual",
";",
"int32_t",
"pos",
",",
"end_pos",
";",
"uint32_t",
"oplen",
",",
"*",
"cigar",
";",
"uint64_t",
"num_m",
",",
"num_i",
",",
"num_d",
",",
"num_s",
",",
"num_eq",
",",
"num_x",
";",
"uint64_t",
"num_matches",
",",
"num_mismatches",
",",
"num_aligned",
";",
"++",
"am",
"->",
"r_total",
";",
"am",
"->",
"b_total",
"+=",
"rec",
"->",
"core",
".",
"l_qseq",
";",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FUNMAP",
")",
"{",
"++",
"am",
"->",
"r_unmapped",
";",
"am",
"->",
"b_unmapped",
"+=",
"rec",
"->",
"core",
".",
"l_qseq",
";",
"}",
"else",
"{",
"++",
"am",
"->",
"r_mapped",
";",
"am",
"->",
"b_mapped",
"+=",
"rec",
"->",
"core",
".",
"l_qseq",
";",
"if",
"(",
"!",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"am",
"->",
"filter",
")",
")",
"{",
"++",
"am",
"->",
"r_aligned",
";",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FDUP",
")",
"{",
"++",
"am",
"->",
"r_dup",
";",
"am",
"->",
"b_dup",
"+=",
"rec",
"->",
"core",
".",
"l_qseq",
";",
"}",
"if",
"(",
"process_cigar",
")",
"{",
"qual",
"=",
"bam_get_qual",
"(",
"rec",
")",
";",
"cigar",
"=",
"bam_get_cigar",
"(",
"rec",
")",
";",
"pos",
"=",
"0",
";",
"num_m",
"=",
"num_i",
"=",
"num_d",
"=",
"num_s",
"=",
"num_eq",
"=",
"num_x",
"=",
"0",
";",
"for",
"(",
"uint32_t",
"i",
"=",
"0",
";",
"i",
"<",
"rec",
"->",
"core",
".",
"n_cigar",
";",
"++",
"i",
")",
"{",
"op",
"=",
"bam_cigar_op",
"(",
"cigar",
"[",
"i",
"]",
")",
";",
"oplen",
"=",
"bam_cigar_oplen",
"(",
"cigar",
"[",
"i",
"]",
")",
";",
"switch",
"(",
"op",
")",
"{",
"case",
"BAM_CMATCH",
":",
"num_m",
"+=",
"oplen",
";",
"break",
";",
"case",
"BAM_CEQUAL",
":",
"num_eq",
"+=",
"oplen",
";",
"break",
";",
"case",
"BAM_CDIFF",
":",
"num_x",
"+=",
"oplen",
";",
"break",
";",
"case",
"BAM_CINS",
":",
"num_i",
"+=",
"oplen",
";",
"break",
";",
"case",
"BAM_CSOFT_CLIP",
":",
"num_s",
"+=",
"oplen",
";",
"pos",
"+=",
"(",
"int32_t",
")",
"oplen",
";",
"break",
";",
"case",
"BAM_CDEL",
":",
"num_d",
"+=",
"oplen",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"switch",
"(",
"op",
")",
"{",
"case",
"BAM_CMATCH",
":",
"case",
"BAM_CEQUAL",
":",
"case",
"BAM_CDIFF",
":",
"case",
"BAM_CINS",
":",
"end_pos",
"=",
"pos",
"+",
"(",
"int32_t",
")",
"oplen",
";",
"while",
"(",
"pos",
"<",
"end_pos",
")",
"{",
"if",
"(",
"qual",
"[",
"pos",
"++",
"]",
">=",
"20",
")",
"{",
"++",
"am",
"->",
"b_q20",
";",
"}",
"}",
"break",
";",
"default",
":",
"break",
";",
"}",
"}",
"if",
"(",
"(",
"nm_tag",
"=",
"bam_aux_get",
"(",
"rec",
",",
"\"",
"\"",
")",
")",
"!=",
"NULL",
")",
"{",
"num_mismatches",
"=",
"bam_aux2i",
"(",
"nm_tag",
")",
";",
"num_mismatches",
"-=",
"num_d",
";",
"num_matches",
"=",
"num_m",
"-",
"num_mismatches",
";",
"}",
"else",
"{",
"num_mismatches",
"=",
"num_x",
";",
"num_matches",
"=",
"(",
"num_m",
">",
"num_eq",
")",
"?",
"num_m",
"-",
"num_mismatches",
":",
"num_eq",
";",
"}",
"num_aligned",
"=",
"rec",
"->",
"core",
".",
"l_qseq",
";",
"if",
"(",
"num_s",
">",
"0",
")",
"{",
"++",
"am",
"->",
"r_soft_clipped",
";",
"am",
"->",
"b_soft_clipped",
"+=",
"num_s",
";",
"num_aligned",
"-=",
"num_s",
";",
"}",
"am",
"->",
"b_aligned",
"+=",
"num_aligned",
";",
"am",
"->",
"b_matched",
"+=",
"num_matches",
";",
"am",
"->",
"b_mismatched",
"+=",
"num_mismatches",
";",
"am",
"->",
"b_inserted",
"+=",
"num_i",
";",
"am",
"->",
"b_deleted",
"+=",
"num_d",
";",
"if",
"(",
"num_mismatches",
"+",
"num_d",
"+",
"num_i",
"==",
"0",
")",
"{",
"++",
"am",
"->",
"r_exact_match",
";",
"am",
"->",
"b_exact_match",
"+=",
"num_aligned",
";",
"}",
"}",
"}",
"}",
"}"
] | Process a bam1_t record for alignment metrics. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"alignment",
"metrics",
"."
] | [
"/* *md_tag,*/",
"/* Total reads */",
"/* Unmapped reads */",
"/* Mapped reads */",
"/* Aligned reads: filter out reads with filtered flags */",
"/* Duplicate reads */",
"/* Count M, I, D, S in CIGAR string (processCIGAR) */",
"/* for each CIGAR operator */",
"/* Sum the length of these operators */",
"/* for each aligned base check qual and increment pos */",
"/*\n * Count mismatches from NM or MD tag if present.\n * if num_mismatches was calculated from an MD tag, subtract dels\n * otherwise num_mismatches becomes num_x\n */",
"/*\n else if ((md_tag = bam_aux_get(rec, \"MD\")) != NULL) {\n num_mismatches = 0;\n for (char *md_str = bam_aux2Z(md_tag); *md_str != '\\0'; ++md_str) {\n if (isalpha(*md_str)) {\n ++num_mismatches;\n }\n }\n num_mismatches -= num_d;\n num_matches = num_m - num_mismatches;\n }\n */",
"/*\n * Set alignment metrics\n * b_matched + b_mismatched == num_m\n * num_m + b_inserted == b_aligned\n * b_aligned + b_soft_clipped == b_mapped == l_qseq\n */",
"/* Exact matches: no mismatches, insertions, or deletions */"
] | [
{
"param": "rec",
"type": "bam1_t"
},
{
"param": "am",
"type": "align_metrics_t"
},
{
"param": "process_cigar",
"type": "bool"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "am",
"type": "align_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "process_cigar",
"type": "bool",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
1b91c39fb848589abf46f6456d4bca5302cdd368 | jfarek/alignstats | pairstats.c | [
"BSD-3-Clause"
] | C | pair_stats_process_record | void | void pair_stats_process_record(bam1_t *rec, pair_stats_metrics_t *psm)
{
/* Chimeric rate */
if (!(rec->core.flag & psm->cr_filter_mapped)) {
++psm->cr_mapped;
if (!(rec->core.flag & psm->cr_filter_improper_pair)) {
++psm->cr_improper_pair;
}
}
/* Ignore unpaired and 1st reads for pair stats */
if (!(rec->core.flag & BAM_FREAD1) && rec->core.flag & BAM_FPAIRED) {
/* Count 2nd reads for total pairs */
if (rec->core.flag & BAM_FREAD2) {
++psm->pairs_total;
}
if (rec->core.flag & BAM_FUNMAP) {
if (rec->core.flag & BAM_FMUNMAP) {
++psm->pairs_unmapped; /* If neither read in pair is mapped */
} else {
++psm->read1_mapped; /* Read 1 mapped, read 2 unmapped */
}
} else {
if (rec->core.flag & BAM_FMUNMAP) {
++psm->read2_mapped; /* Read 2 mapped, read 1 unmapped */
} else {
++psm->pairs_mapped; /* If both reads in pair are mapped */
/* Mapped to same chromosome */
if (rec->core.tid == rec->core.mtid) {
++psm->pairs_mapped_same_chr;
}
}
}
}
} | /**
* Process a bam1_t record for pair statistics metrics.
*/ | Process a bam1_t record for pair statistics metrics. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"pair",
"statistics",
"metrics",
"."
] | void pair_stats_process_record(bam1_t *rec, pair_stats_metrics_t *psm)
{
if (!(rec->core.flag & psm->cr_filter_mapped)) {
++psm->cr_mapped;
if (!(rec->core.flag & psm->cr_filter_improper_pair)) {
++psm->cr_improper_pair;
}
}
if (!(rec->core.flag & BAM_FREAD1) && rec->core.flag & BAM_FPAIRED) {
if (rec->core.flag & BAM_FREAD2) {
++psm->pairs_total;
}
if (rec->core.flag & BAM_FUNMAP) {
if (rec->core.flag & BAM_FMUNMAP) {
++psm->pairs_unmapped;
} else {
++psm->read1_mapped;
}
} else {
if (rec->core.flag & BAM_FMUNMAP) {
++psm->read2_mapped;
} else {
++psm->pairs_mapped;
if (rec->core.tid == rec->core.mtid) {
++psm->pairs_mapped_same_chr;
}
}
}
}
} | [
"void",
"pair_stats_process_record",
"(",
"bam1_t",
"*",
"rec",
",",
"pair_stats_metrics_t",
"*",
"psm",
")",
"{",
"if",
"(",
"!",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"psm",
"->",
"cr_filter_mapped",
")",
")",
"{",
"++",
"psm",
"->",
"cr_mapped",
";",
"if",
"(",
"!",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"psm",
"->",
"cr_filter_improper_pair",
")",
")",
"{",
"++",
"psm",
"->",
"cr_improper_pair",
";",
"}",
"}",
"if",
"(",
"!",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FREAD1",
")",
"&&",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FPAIRED",
")",
"{",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FREAD2",
")",
"{",
"++",
"psm",
"->",
"pairs_total",
";",
"}",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FUNMAP",
")",
"{",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FMUNMAP",
")",
"{",
"++",
"psm",
"->",
"pairs_unmapped",
";",
"}",
"else",
"{",
"++",
"psm",
"->",
"read1_mapped",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FMUNMAP",
")",
"{",
"++",
"psm",
"->",
"read2_mapped",
";",
"}",
"else",
"{",
"++",
"psm",
"->",
"pairs_mapped",
";",
"if",
"(",
"rec",
"->",
"core",
".",
"tid",
"==",
"rec",
"->",
"core",
".",
"mtid",
")",
"{",
"++",
"psm",
"->",
"pairs_mapped_same_chr",
";",
"}",
"}",
"}",
"}",
"}"
] | Process a bam1_t record for pair statistics metrics. | [
"Process",
"a",
"bam1_t",
"record",
"for",
"pair",
"statistics",
"metrics",
"."
] | [
"/* Chimeric rate */",
"/* Ignore unpaired and 1st reads for pair stats */",
"/* Count 2nd reads for total pairs */",
"/* If neither read in pair is mapped */",
"/* Read 1 mapped, read 2 unmapped */",
"/* Read 2 mapped, read 1 unmapped */",
"/* If both reads in pair are mapped */",
"/* Mapped to same chromosome */"
] | [
{
"param": "rec",
"type": "bam1_t"
},
{
"param": "psm",
"type": "pair_stats_metrics_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "rec",
"type": "bam1_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "psm",
"type": "pair_stats_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
1b91c39fb848589abf46f6456d4bca5302cdd368 | jfarek/alignstats | pairstats.c | [
"BSD-3-Clause"
] | C | pair_stats_report | void | void pair_stats_report(report_t *report, pair_stats_metrics_t *psm, char *key_buffer, char *value_buffer)
{
copy_to_buffer(key_buffer, "TotalPairs", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->pairs_mapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "TotalSameChrPairs", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->pairs_mapped_same_chr);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "TotalSameChrPairsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->pairs_mapped_same_chr, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnpairedReads", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->pairs_unmapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnpairedReadsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->pairs_unmapped, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R1UnpairedReads", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->read1_mapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R1UnpairedReadsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->read1_mapped, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R2UnpairedReads", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->read2_mapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R2UnpairedReadsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->read2_mapped, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "ChimericReadPairPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->cr_improper_pair, psm->cr_mapped);
report_add_key_value(report, key_buffer, value_buffer);
} | /**
* Write metrics in psm to report.
*/ | Write metrics in psm to report. | [
"Write",
"metrics",
"in",
"psm",
"to",
"report",
"."
] | void pair_stats_report(report_t *report, pair_stats_metrics_t *psm, char *key_buffer, char *value_buffer)
{
copy_to_buffer(key_buffer, "TotalPairs", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->pairs_mapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "TotalSameChrPairs", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->pairs_mapped_same_chr);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "TotalSameChrPairsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->pairs_mapped_same_chr, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnpairedReads", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->pairs_unmapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "UnpairedReadsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->pairs_unmapped, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R1UnpairedReads", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->read1_mapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R1UnpairedReadsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->read1_mapped, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R2UnpairedReads", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", psm->read2_mapped);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "R2UnpairedReadsPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->read2_mapped, psm->pairs_total);
report_add_key_value(report, key_buffer, value_buffer);
copy_to_buffer(key_buffer, "ChimericReadPairPct", REPORT_BUFFER_SIZE);
print_pct(value_buffer, REPORT_BUFFER_SIZE, psm->cr_improper_pair, psm->cr_mapped);
report_add_key_value(report, key_buffer, value_buffer);
} | [
"void",
"pair_stats_report",
"(",
"report_t",
"*",
"report",
",",
"pair_stats_metrics_t",
"*",
"psm",
",",
"char",
"*",
"key_buffer",
",",
"char",
"*",
"value_buffer",
")",
"{",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"psm",
"->",
"pairs_mapped",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"psm",
"->",
"pairs_mapped_same_chr",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"psm",
"->",
"pairs_mapped_same_chr",
",",
"psm",
"->",
"pairs_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"psm",
"->",
"pairs_unmapped",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"psm",
"->",
"pairs_unmapped",
",",
"psm",
"->",
"pairs_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"psm",
"->",
"read1_mapped",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"psm",
"->",
"read1_mapped",
",",
"psm",
"->",
"pairs_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"psm",
"->",
"read2_mapped",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"psm",
"->",
"read2_mapped",
",",
"psm",
"->",
"pairs_total",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"print_pct",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"psm",
"->",
"cr_improper_pair",
",",
"psm",
"->",
"cr_mapped",
")",
";",
"report_add_key_value",
"(",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"}"
] | Write metrics in psm to report. | [
"Write",
"metrics",
"in",
"psm",
"to",
"report",
"."
] | [] | [
{
"param": "report",
"type": "report_t"
},
{
"param": "psm",
"type": "pair_stats_metrics_t"
},
{
"param": "key_buffer",
"type": "char"
},
{
"param": "value_buffer",
"type": "char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "report",
"type": "report_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "psm",
"type": "pair_stats_metrics_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "key_buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "value_buffer",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | move_to_first_region | bool | bool move_to_first_region(args_t *args)
{
bool ret = true;
bed_chrom_t **chroms = args->regions->chroms;
/* no more regions */
if (args->regions_curr_chrom_idx >= args->regions->num_chroms) {
ret = false;
} else {
/* find first chrom */
while (ret && chroms[args->regions_curr_chrom_idx]->num_targets == 0) {
if (args->regions_curr_chrom_idx < args->regions->num_chroms) {
++args->regions_curr_chrom_idx;
args->regions_curr_target_idx = 0;
} else {
ret = false;
}
}
set_iter(args);
}
return ret;
} | /**
* Move to first region in args->region->chroms.
* Returns whether moved to next region.
*/ | Move to first region in args->region->chroms.
Returns whether moved to next region. | [
"Move",
"to",
"first",
"region",
"in",
"args",
"-",
">",
"region",
"-",
">",
"chroms",
".",
"Returns",
"whether",
"moved",
"to",
"next",
"region",
"."
] | bool move_to_first_region(args_t *args)
{
bool ret = true;
bed_chrom_t **chroms = args->regions->chroms;
if (args->regions_curr_chrom_idx >= args->regions->num_chroms) {
ret = false;
} else {
while (ret && chroms[args->regions_curr_chrom_idx]->num_targets == 0) {
if (args->regions_curr_chrom_idx < args->regions->num_chroms) {
++args->regions_curr_chrom_idx;
args->regions_curr_target_idx = 0;
} else {
ret = false;
}
}
set_iter(args);
}
return ret;
} | [
"bool",
"move_to_first_region",
"(",
"args_t",
"*",
"args",
")",
"{",
"bool",
"ret",
"=",
"true",
";",
"bed_chrom_t",
"*",
"*",
"chroms",
"=",
"args",
"->",
"regions",
"->",
"chroms",
";",
"if",
"(",
"args",
"->",
"regions_curr_chrom_idx",
">=",
"args",
"->",
"regions",
"->",
"num_chroms",
")",
"{",
"ret",
"=",
"false",
";",
"}",
"else",
"{",
"while",
"(",
"ret",
"&&",
"chroms",
"[",
"args",
"->",
"regions_curr_chrom_idx",
"]",
"->",
"num_targets",
"==",
"0",
")",
"{",
"if",
"(",
"args",
"->",
"regions_curr_chrom_idx",
"<",
"args",
"->",
"regions",
"->",
"num_chroms",
")",
"{",
"++",
"args",
"->",
"regions_curr_chrom_idx",
";",
"args",
"->",
"regions_curr_target_idx",
"=",
"0",
";",
"}",
"else",
"{",
"ret",
"=",
"false",
";",
"}",
"}",
"set_iter",
"(",
"args",
")",
";",
"}",
"return",
"ret",
";",
"}"
] | Move to first region in args->region->chroms. | [
"Move",
"to",
"first",
"region",
"in",
"args",
"-",
">",
"region",
"-",
">",
"chroms",
"."
] | [
"/* no more regions */",
"/* find first chrom */"
] | [
{
"param": "args",
"type": "args_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "args_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | read_bam1 | uint32_t | uint32_t read_bam1(args_t *args)
{
/* for each of up to the next RECORD_BUFFER_SIZE reads */
uint32_t record_idx = 0;
while (record_idx < args->reads_per_buffer &&
sam_read1(args->input_sf, args->hdr, args->read_buff[record_idx]) >= 0)
{
++record_idx;
}
return record_idx;
} | /**
* Base function for reading bam1_t records into args->read_buff
* Reads records using sam_itr_next
* Returns number of records read.
*/ | Base function for reading bam1_t records into args->read_buff
Reads records using sam_itr_next
Returns number of records read. | [
"Base",
"function",
"for",
"reading",
"bam1_t",
"records",
"into",
"args",
"-",
">",
"read_buff",
"Reads",
"records",
"using",
"sam_itr_next",
"Returns",
"number",
"of",
"records",
"read",
"."
] | uint32_t read_bam1(args_t *args)
{
uint32_t record_idx = 0;
while (record_idx < args->reads_per_buffer &&
sam_read1(args->input_sf, args->hdr, args->read_buff[record_idx]) >= 0)
{
++record_idx;
}
return record_idx;
} | [
"uint32_t",
"read_bam1",
"(",
"args_t",
"*",
"args",
")",
"{",
"uint32_t",
"record_idx",
"=",
"0",
";",
"while",
"(",
"record_idx",
"<",
"args",
"->",
"reads_per_buffer",
"&&",
"sam_read1",
"(",
"args",
"->",
"input_sf",
",",
"args",
"->",
"hdr",
",",
"args",
"->",
"read_buff",
"[",
"record_idx",
"]",
")",
">=",
"0",
")",
"{",
"++",
"record_idx",
";",
"}",
"return",
"record_idx",
";",
"}"
] | Base function for reading bam1_t records into args->read_buff
Reads records using sam_itr_next
Returns number of records read. | [
"Base",
"function",
"for",
"reading",
"bam1_t",
"records",
"into",
"args",
"-",
">",
"read_buff",
"Reads",
"records",
"using",
"sam_itr_next",
"Returns",
"number",
"of",
"records",
"read",
"."
] | [
"/* for each of up to the next RECORD_BUFFER_SIZE reads */"
] | [
{
"param": "args",
"type": "args_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "args_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | read_bam_itr | uint32_t | uint32_t read_bam_itr(args_t *args)
{
uint32_t record_idx = 0;
while (record_idx < args->reads_per_buffer) {
if (sam_itr_next(args->input_sf, args->iter, args->read_buff[record_idx]) < 0)
{
if (!move_to_next_region(args)) {
/* process '*' chrom reads */
if (args->process_unmapped && !args->process_unmapped_done) {
if (args->iter != NULL) {
sam_itr_destroy(args->iter);
}
args->iter = sam_itr_querys(args->index, args->hdr, "*");
args->process_unmapped_done = true;
} else {
break;
}
}
} else {
++record_idx;
}
}
return record_idx;
} | /**
* Base function for reading bam1_t records into args->read_buff.
* Reads records using sam_itr_next
* Returns number of records read.
*/ | Base function for reading bam1_t records into args->read_buff.
Reads records using sam_itr_next
Returns number of records read. | [
"Base",
"function",
"for",
"reading",
"bam1_t",
"records",
"into",
"args",
"-",
">",
"read_buff",
".",
"Reads",
"records",
"using",
"sam_itr_next",
"Returns",
"number",
"of",
"records",
"read",
"."
] | uint32_t read_bam_itr(args_t *args)
{
uint32_t record_idx = 0;
while (record_idx < args->reads_per_buffer) {
if (sam_itr_next(args->input_sf, args->iter, args->read_buff[record_idx]) < 0)
{
if (!move_to_next_region(args)) {
if (args->process_unmapped && !args->process_unmapped_done) {
if (args->iter != NULL) {
sam_itr_destroy(args->iter);
}
args->iter = sam_itr_querys(args->index, args->hdr, "*");
args->process_unmapped_done = true;
} else {
break;
}
}
} else {
++record_idx;
}
}
return record_idx;
} | [
"uint32_t",
"read_bam_itr",
"(",
"args_t",
"*",
"args",
")",
"{",
"uint32_t",
"record_idx",
"=",
"0",
";",
"while",
"(",
"record_idx",
"<",
"args",
"->",
"reads_per_buffer",
")",
"{",
"if",
"(",
"sam_itr_next",
"(",
"args",
"->",
"input_sf",
",",
"args",
"->",
"iter",
",",
"args",
"->",
"read_buff",
"[",
"record_idx",
"]",
")",
"<",
"0",
")",
"{",
"if",
"(",
"!",
"move_to_next_region",
"(",
"args",
")",
")",
"{",
"if",
"(",
"args",
"->",
"process_unmapped",
"&&",
"!",
"args",
"->",
"process_unmapped_done",
")",
"{",
"if",
"(",
"args",
"->",
"iter",
"!=",
"NULL",
")",
"{",
"sam_itr_destroy",
"(",
"args",
"->",
"iter",
")",
";",
"}",
"args",
"->",
"iter",
"=",
"sam_itr_querys",
"(",
"args",
"->",
"index",
",",
"args",
"->",
"hdr",
",",
"\"",
"\"",
")",
";",
"args",
"->",
"process_unmapped_done",
"=",
"true",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"++",
"record_idx",
";",
"}",
"}",
"return",
"record_idx",
";",
"}"
] | Base function for reading bam1_t records into args->read_buff. | [
"Base",
"function",
"for",
"reading",
"bam1_t",
"records",
"into",
"args",
"-",
">",
"read_buff",
"."
] | [
"/* process '*' chrom reads */"
] | [
{
"param": "args",
"type": "args_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "args_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | process_records | uint32_t | uint32_t process_records(args_t *args)
{
bool is_read_filtered = false;
int32_t prev_rec_pos = -2;
uint32_t record_idx = 0;
bam1_t *rec;
/* for each read in read buffer reads */
while (record_idx < args->read_buff_size[args->process_section_idx]) {
rec = args->curr_buff[record_idx++];
/* if new chromosome */
if (rec->core.tid != args->curr_chrom_idx) {
args->new_chrom = true;
args->prev_chrom_idx = args->curr_chrom_idx;
if (args->curr_chrom_idx >= 0) {
args->prev_mapped_chrom_idx = args->curr_chrom_idx;
}
args->prev_chrom_name = args->curr_chrom_name;
args->prev_chrom_len = args->curr_chrom_len;
if ((args->curr_chrom_idx = rec->core.tid) >= 0) {
args->curr_chrom_name = args->hdr->target_name[args->curr_chrom_idx];
args->curr_chrom_len = args->hdr->target_len[args->curr_chrom_idx];
} else {
args->curr_chrom_name = NULL;
args->curr_chrom_len = 0;
}
if (args->order_warn &&
!check_order_tid(args->prev_mapped_chrom_idx, args->curr_chrom_idx))
{
log_warning(
"Record not in coordinate-sorted order. "
"Results may not be accurate: "
"tid %d > %d",
args->prev_mapped_chrom_idx,
args->curr_chrom_idx);
args->order_warn = false;
}
prev_rec_pos = -2;
/* Don't process CIGAR if RNAME is "*" */
args->process_cigar = (
args->curr_chrom_name == NULL ||
*args->curr_chrom_name != '*');
}
if (args->order_warn &&
!check_order_pos(prev_rec_pos, rec->core.pos))
{
log_warning(
"Record not in coordinate-sorted order. "
"Results may not be accurate: "
"tid %d, pos %d > %d",
args->curr_chrom_idx,
prev_rec_pos + 1,
rec->core.pos + 1);
args->order_warn = false;
}
/* Preliminary filtering */
filter_counter_process_record(rec, args->fc);
is_read_filtered = (
filter_test_qual(rec->core.qual, args->fc->min_qual) ||
filter_test_flag(rec->core.flag, args->fc->filter_incl, args->fc->filter_excl)
);
if (!is_read_filtered) {
prev_rec_pos = rec->core.pos;
/* Alignment stats */
if (args->do_alignment) {
align_process_record(rec, args->am_all, args->process_cigar);
align_len_process_record(rec, args->alm_all);
if (rec->core.flag & BAM_FREAD1) {
align_process_record(rec, args->am_read1, args->process_cigar);
align_len_process_record(rec, args->alm_read1);
} else if (rec->core.flag & BAM_FREAD2) {
align_process_record(rec, args->am_read2, args->process_cigar);
align_len_process_record(rec, args->alm_read2);
}
/*
align_process_record(rec, args->am_fragment, args->process_cigar);
align_len_process_record(rec, args->alm_fragment);
*/
pair_stats_process_record(rec, args->psm);
insert_size_process_record(rec, args->ism);
}
}
/* Whole genome or capture stats */
if (args->do_wgs || args->do_capture) {
/* if new chromosome */
if (args->new_chrom) {
/* Non-target good hits for previous chromosome */
if (args->prev_chrom_idx >= 0) {
if (args->do_cov_mask) {
handle_coverage_mask(
args->coverage,
args->cov_mask_ti,
args->prev_chrom_idx,
args->prev_chrom_len);
}
if (args->do_wgs) {
handle_wgs_coverage(
args->coverage,
args->cm_wgs,
args->ci_wgs,
args->prev_chrom_len);
}
if (args->do_capture) {
handle_target_coverage(
args->coverage,
args->cm,
args->ci,
args->ti,
args->prev_chrom_idx,
args->prev_chrom_name,
args->prev_chrom_len);
handle_miss_reads(
args->coverage,
args->cm,
args->ti,
args->prev_chrom_idx,
args->prev_chrom_len);
}
}
/* Next chromosome id, if available */
if (args->curr_chrom_idx >= 0) {
/* Reset entire coverage array */
clear_coverage(
args->coverage,
0,
args->curr_chrom_len,
args->curr_chrom_len);
if (args->do_wgs) {
args->cm_wgs->b_total += args->curr_chrom_len;
}
if (args->do_capture) {
args->cm->b_total += args->curr_chrom_len;
set_target_cov(
args->coverage,
args->cm,
args->ti,
args->curr_chrom_idx,
args->curr_chrom_len);
if (args->do_cov_mask) {
handle_coverage_mask_target(
args->coverage,
args->cm,
args->cov_mask_ti,
args->curr_chrom_idx,
args->curr_chrom_len);
}
}
}
args->new_chrom = false;
}
if (!is_read_filtered) {
/* Process read for target and coverage info */
capture_process_record(
rec,
args->coverage,
args->cm_wgs,
args->cm,
args->olh,
args->curr_chrom_len,
args->remove_dups,
args->remove_overlaps,
args->remove_overlaps_mc,
args->min_base_qual);
}
}
if (args->verbose &&
++args->num_records_processed % args->interval == 0)
{
log_info("%lu records processed ...", args->num_records_processed);
}
}
return record_idx;
} | /**
* Base function for processing bam1_t records in args->curr_buff.
* Returs number of records processed
*/ | Base function for processing bam1_t records in args->curr_buff.
Returs number of records processed | [
"Base",
"function",
"for",
"processing",
"bam1_t",
"records",
"in",
"args",
"-",
">",
"curr_buff",
".",
"Returs",
"number",
"of",
"records",
"processed"
] | uint32_t process_records(args_t *args)
{
bool is_read_filtered = false;
int32_t prev_rec_pos = -2;
uint32_t record_idx = 0;
bam1_t *rec;
while (record_idx < args->read_buff_size[args->process_section_idx]) {
rec = args->curr_buff[record_idx++];
if (rec->core.tid != args->curr_chrom_idx) {
args->new_chrom = true;
args->prev_chrom_idx = args->curr_chrom_idx;
if (args->curr_chrom_idx >= 0) {
args->prev_mapped_chrom_idx = args->curr_chrom_idx;
}
args->prev_chrom_name = args->curr_chrom_name;
args->prev_chrom_len = args->curr_chrom_len;
if ((args->curr_chrom_idx = rec->core.tid) >= 0) {
args->curr_chrom_name = args->hdr->target_name[args->curr_chrom_idx];
args->curr_chrom_len = args->hdr->target_len[args->curr_chrom_idx];
} else {
args->curr_chrom_name = NULL;
args->curr_chrom_len = 0;
}
if (args->order_warn &&
!check_order_tid(args->prev_mapped_chrom_idx, args->curr_chrom_idx))
{
log_warning(
"Record not in coordinate-sorted order. "
"Results may not be accurate: "
"tid %d > %d",
args->prev_mapped_chrom_idx,
args->curr_chrom_idx);
args->order_warn = false;
}
prev_rec_pos = -2;
args->process_cigar = (
args->curr_chrom_name == NULL ||
*args->curr_chrom_name != '*');
}
if (args->order_warn &&
!check_order_pos(prev_rec_pos, rec->core.pos))
{
log_warning(
"Record not in coordinate-sorted order. "
"Results may not be accurate: "
"tid %d, pos %d > %d",
args->curr_chrom_idx,
prev_rec_pos + 1,
rec->core.pos + 1);
args->order_warn = false;
}
filter_counter_process_record(rec, args->fc);
is_read_filtered = (
filter_test_qual(rec->core.qual, args->fc->min_qual) ||
filter_test_flag(rec->core.flag, args->fc->filter_incl, args->fc->filter_excl)
);
if (!is_read_filtered) {
prev_rec_pos = rec->core.pos;
if (args->do_alignment) {
align_process_record(rec, args->am_all, args->process_cigar);
align_len_process_record(rec, args->alm_all);
if (rec->core.flag & BAM_FREAD1) {
align_process_record(rec, args->am_read1, args->process_cigar);
align_len_process_record(rec, args->alm_read1);
} else if (rec->core.flag & BAM_FREAD2) {
align_process_record(rec, args->am_read2, args->process_cigar);
align_len_process_record(rec, args->alm_read2);
}
pair_stats_process_record(rec, args->psm);
insert_size_process_record(rec, args->ism);
}
}
if (args->do_wgs || args->do_capture) {
if (args->new_chrom) {
if (args->prev_chrom_idx >= 0) {
if (args->do_cov_mask) {
handle_coverage_mask(
args->coverage,
args->cov_mask_ti,
args->prev_chrom_idx,
args->prev_chrom_len);
}
if (args->do_wgs) {
handle_wgs_coverage(
args->coverage,
args->cm_wgs,
args->ci_wgs,
args->prev_chrom_len);
}
if (args->do_capture) {
handle_target_coverage(
args->coverage,
args->cm,
args->ci,
args->ti,
args->prev_chrom_idx,
args->prev_chrom_name,
args->prev_chrom_len);
handle_miss_reads(
args->coverage,
args->cm,
args->ti,
args->prev_chrom_idx,
args->prev_chrom_len);
}
}
if (args->curr_chrom_idx >= 0) {
clear_coverage(
args->coverage,
0,
args->curr_chrom_len,
args->curr_chrom_len);
if (args->do_wgs) {
args->cm_wgs->b_total += args->curr_chrom_len;
}
if (args->do_capture) {
args->cm->b_total += args->curr_chrom_len;
set_target_cov(
args->coverage,
args->cm,
args->ti,
args->curr_chrom_idx,
args->curr_chrom_len);
if (args->do_cov_mask) {
handle_coverage_mask_target(
args->coverage,
args->cm,
args->cov_mask_ti,
args->curr_chrom_idx,
args->curr_chrom_len);
}
}
}
args->new_chrom = false;
}
if (!is_read_filtered) {
capture_process_record(
rec,
args->coverage,
args->cm_wgs,
args->cm,
args->olh,
args->curr_chrom_len,
args->remove_dups,
args->remove_overlaps,
args->remove_overlaps_mc,
args->min_base_qual);
}
}
if (args->verbose &&
++args->num_records_processed % args->interval == 0)
{
log_info("%lu records processed ...", args->num_records_processed);
}
}
return record_idx;
} | [
"uint32_t",
"process_records",
"(",
"args_t",
"*",
"args",
")",
"{",
"bool",
"is_read_filtered",
"=",
"false",
";",
"int32_t",
"prev_rec_pos",
"=",
"-2",
";",
"uint32_t",
"record_idx",
"=",
"0",
";",
"bam1_t",
"*",
"rec",
";",
"while",
"(",
"record_idx",
"<",
"args",
"->",
"read_buff_size",
"[",
"args",
"->",
"process_section_idx",
"]",
")",
"{",
"rec",
"=",
"args",
"->",
"curr_buff",
"[",
"record_idx",
"++",
"]",
";",
"if",
"(",
"rec",
"->",
"core",
".",
"tid",
"!=",
"args",
"->",
"curr_chrom_idx",
")",
"{",
"args",
"->",
"new_chrom",
"=",
"true",
";",
"args",
"->",
"prev_chrom_idx",
"=",
"args",
"->",
"curr_chrom_idx",
";",
"if",
"(",
"args",
"->",
"curr_chrom_idx",
">=",
"0",
")",
"{",
"args",
"->",
"prev_mapped_chrom_idx",
"=",
"args",
"->",
"curr_chrom_idx",
";",
"}",
"args",
"->",
"prev_chrom_name",
"=",
"args",
"->",
"curr_chrom_name",
";",
"args",
"->",
"prev_chrom_len",
"=",
"args",
"->",
"curr_chrom_len",
";",
"if",
"(",
"(",
"args",
"->",
"curr_chrom_idx",
"=",
"rec",
"->",
"core",
".",
"tid",
")",
">=",
"0",
")",
"{",
"args",
"->",
"curr_chrom_name",
"=",
"args",
"->",
"hdr",
"->",
"target_name",
"[",
"args",
"->",
"curr_chrom_idx",
"]",
";",
"args",
"->",
"curr_chrom_len",
"=",
"args",
"->",
"hdr",
"->",
"target_len",
"[",
"args",
"->",
"curr_chrom_idx",
"]",
";",
"}",
"else",
"{",
"args",
"->",
"curr_chrom_name",
"=",
"NULL",
";",
"args",
"->",
"curr_chrom_len",
"=",
"0",
";",
"}",
"if",
"(",
"args",
"->",
"order_warn",
"&&",
"!",
"check_order_tid",
"(",
"args",
"->",
"prev_mapped_chrom_idx",
",",
"args",
"->",
"curr_chrom_idx",
")",
")",
"{",
"log_warning",
"(",
"\"",
"\"",
"\"",
"\"",
"\"",
"\"",
",",
"args",
"->",
"prev_mapped_chrom_idx",
",",
"args",
"->",
"curr_chrom_idx",
")",
";",
"args",
"->",
"order_warn",
"=",
"false",
";",
"}",
"prev_rec_pos",
"=",
"-2",
";",
"args",
"->",
"process_cigar",
"=",
"(",
"args",
"->",
"curr_chrom_name",
"==",
"NULL",
"||",
"*",
"args",
"->",
"curr_chrom_name",
"!=",
"'",
"'",
")",
";",
"}",
"if",
"(",
"args",
"->",
"order_warn",
"&&",
"!",
"check_order_pos",
"(",
"prev_rec_pos",
",",
"rec",
"->",
"core",
".",
"pos",
")",
")",
"{",
"log_warning",
"(",
"\"",
"\"",
"\"",
"\"",
"\"",
"\"",
",",
"args",
"->",
"curr_chrom_idx",
",",
"prev_rec_pos",
"+",
"1",
",",
"rec",
"->",
"core",
".",
"pos",
"+",
"1",
")",
";",
"args",
"->",
"order_warn",
"=",
"false",
";",
"}",
"filter_counter_process_record",
"(",
"rec",
",",
"args",
"->",
"fc",
")",
";",
"is_read_filtered",
"=",
"(",
"filter_test_qual",
"(",
"rec",
"->",
"core",
".",
"qual",
",",
"args",
"->",
"fc",
"->",
"min_qual",
")",
"||",
"filter_test_flag",
"(",
"rec",
"->",
"core",
".",
"flag",
",",
"args",
"->",
"fc",
"->",
"filter_incl",
",",
"args",
"->",
"fc",
"->",
"filter_excl",
")",
")",
";",
"if",
"(",
"!",
"is_read_filtered",
")",
"{",
"prev_rec_pos",
"=",
"rec",
"->",
"core",
".",
"pos",
";",
"if",
"(",
"args",
"->",
"do_alignment",
")",
"{",
"align_process_record",
"(",
"rec",
",",
"args",
"->",
"am_all",
",",
"args",
"->",
"process_cigar",
")",
";",
"align_len_process_record",
"(",
"rec",
",",
"args",
"->",
"alm_all",
")",
";",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FREAD1",
")",
"{",
"align_process_record",
"(",
"rec",
",",
"args",
"->",
"am_read1",
",",
"args",
"->",
"process_cigar",
")",
";",
"align_len_process_record",
"(",
"rec",
",",
"args",
"->",
"alm_read1",
")",
";",
"}",
"else",
"if",
"(",
"rec",
"->",
"core",
".",
"flag",
"&",
"BAM_FREAD2",
")",
"{",
"align_process_record",
"(",
"rec",
",",
"args",
"->",
"am_read2",
",",
"args",
"->",
"process_cigar",
")",
";",
"align_len_process_record",
"(",
"rec",
",",
"args",
"->",
"alm_read2",
")",
";",
"}",
"pair_stats_process_record",
"(",
"rec",
",",
"args",
"->",
"psm",
")",
";",
"insert_size_process_record",
"(",
"rec",
",",
"args",
"->",
"ism",
")",
";",
"}",
"}",
"if",
"(",
"args",
"->",
"do_wgs",
"||",
"args",
"->",
"do_capture",
")",
"{",
"if",
"(",
"args",
"->",
"new_chrom",
")",
"{",
"if",
"(",
"args",
"->",
"prev_chrom_idx",
">=",
"0",
")",
"{",
"if",
"(",
"args",
"->",
"do_cov_mask",
")",
"{",
"handle_coverage_mask",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cov_mask_ti",
",",
"args",
"->",
"prev_chrom_idx",
",",
"args",
"->",
"prev_chrom_len",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_wgs",
")",
"{",
"handle_wgs_coverage",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm_wgs",
",",
"args",
"->",
"ci_wgs",
",",
"args",
"->",
"prev_chrom_len",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_capture",
")",
"{",
"handle_target_coverage",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"ci",
",",
"args",
"->",
"ti",
",",
"args",
"->",
"prev_chrom_idx",
",",
"args",
"->",
"prev_chrom_name",
",",
"args",
"->",
"prev_chrom_len",
")",
";",
"handle_miss_reads",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"ti",
",",
"args",
"->",
"prev_chrom_idx",
",",
"args",
"->",
"prev_chrom_len",
")",
";",
"}",
"}",
"if",
"(",
"args",
"->",
"curr_chrom_idx",
">=",
"0",
")",
"{",
"clear_coverage",
"(",
"args",
"->",
"coverage",
",",
"0",
",",
"args",
"->",
"curr_chrom_len",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"if",
"(",
"args",
"->",
"do_wgs",
")",
"{",
"args",
"->",
"cm_wgs",
"->",
"b_total",
"+=",
"args",
"->",
"curr_chrom_len",
";",
"}",
"if",
"(",
"args",
"->",
"do_capture",
")",
"{",
"args",
"->",
"cm",
"->",
"b_total",
"+=",
"args",
"->",
"curr_chrom_len",
";",
"set_target_cov",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"ti",
",",
"args",
"->",
"curr_chrom_idx",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"if",
"(",
"args",
"->",
"do_cov_mask",
")",
"{",
"handle_coverage_mask_target",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"cov_mask_ti",
",",
"args",
"->",
"curr_chrom_idx",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"}",
"}",
"}",
"args",
"->",
"new_chrom",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"is_read_filtered",
")",
"{",
"capture_process_record",
"(",
"rec",
",",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm_wgs",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"olh",
",",
"args",
"->",
"curr_chrom_len",
",",
"args",
"->",
"remove_dups",
",",
"args",
"->",
"remove_overlaps",
",",
"args",
"->",
"remove_overlaps_mc",
",",
"args",
"->",
"min_base_qual",
")",
";",
"}",
"}",
"if",
"(",
"args",
"->",
"verbose",
"&&",
"++",
"args",
"->",
"num_records_processed",
"%",
"args",
"->",
"interval",
"==",
"0",
")",
"{",
"log_info",
"(",
"\"",
"\"",
",",
"args",
"->",
"num_records_processed",
")",
";",
"}",
"}",
"return",
"record_idx",
";",
"}"
] | Base function for processing bam1_t records in args->curr_buff. | [
"Base",
"function",
"for",
"processing",
"bam1_t",
"records",
"in",
"args",
"-",
">",
"curr_buff",
"."
] | [
"/* for each read in read buffer reads */",
"/* if new chromosome */",
"/* Don't process CIGAR if RNAME is \"*\" */",
"/* Preliminary filtering */",
"/* Alignment stats */",
"/*\n align_process_record(rec, args->am_fragment, args->process_cigar);\n align_len_process_record(rec, args->alm_fragment);\n */",
"/* Whole genome or capture stats */",
"/* if new chromosome */",
"/* Non-target good hits for previous chromosome */",
"/* Next chromosome id, if available */",
"/* Reset entire coverage array */",
"/* Process read for target and coverage info */"
] | [
{
"param": "args",
"type": "args_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "args_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | finalize_results | void | void finalize_results(args_t *args)
{
/* Target coverage and miss reads for last chromosome */
if ((args->do_wgs || args->do_capture) && args->curr_chrom_idx >= 0) {
if (args->do_cov_mask) {
handle_coverage_mask(
args->coverage,
args->cov_mask_ti,
args->curr_chrom_idx,
args->curr_chrom_len);
}
if (args->do_wgs) {
handle_wgs_coverage(
args->coverage,
args->cm_wgs,
args->ci_wgs,
args->curr_chrom_len);
}
if (args->do_capture) {
handle_target_coverage(
args->coverage,
args->cm,
args->ci,
args->ti,
args->curr_chrom_idx,
args->curr_chrom_name,
args->curr_chrom_len);
handle_miss_reads(
args->coverage,
args->cm,
args->ti,
args->curr_chrom_idx,
args->curr_chrom_len);
}
}
/* Finalize results */
if (args->do_alignment) {
align_len_finalize(args->alm_all);
align_len_finalize(args->alm_read1);
align_len_finalize(args->alm_read2);
/*align_len_finalize(args->alm_fragment);*/
insert_size_finalize(args->ism);
}
if (args->do_wgs) {
capture_metrics_finalize(args->cm_wgs, args->ci_wgs, NULL);
}
if (args->do_capture) {
capture_metrics_finalize(args->cm, args->ci, args->ti);
}
if (args->verbose) {
log_info("Finished processing records.");
}
/* Write report */
if (args->verbose) {
log_info("Writing report.");
}
char *key_buffer = malloc(REPORT_BUFFER_SIZE * sizeof(char));
die_on_alloc_fail(key_buffer);
char *value_buffer = malloc(REPORT_BUFFER_SIZE * sizeof(char));
die_on_alloc_fail(value_buffer);
char *input_fn;
if (args->input_fn != NULL) {
input_fn = args->input_fn;
} else {
input_fn = "-";
}
copy_to_buffer(key_buffer, "InputFileName", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "\"%s\"", args->input_fn);
report_add_key_value(args->report, key_buffer, value_buffer);
off_t filesize = 0;
if (strcmp(args->input_fn, "-") != 0) {
struct stat statbuf;
stat(input_fn, &statbuf);
filesize = statbuf.st_size;
}
copy_to_buffer(key_buffer, "InputFileSize", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", filesize);
report_add_key_value(args->report, key_buffer, value_buffer);
/* Report filtered/unfiltered read counts */
filter_counter_report(args->report, args->fc, key_buffer, value_buffer);
/* Write alignment stats report */
if (args->do_alignment) {
align_report(args->report, args->am_all, RT_ALL, key_buffer, value_buffer);
align_report(args->report, args->am_read1, RT_READ1, key_buffer, value_buffer);
align_report(args->report, args->am_read2, RT_READ2, key_buffer, value_buffer);
align_len_report(args->report, args->alm_all, RT_ALL, key_buffer, value_buffer);
align_len_report(args->report, args->alm_read1, RT_READ1, key_buffer, value_buffer);
align_len_report(args->report, args->alm_read2, RT_READ2, key_buffer, value_buffer);
pair_stats_report(args->report, args->psm, key_buffer, value_buffer);
insert_size_report(args->report, args->ism, key_buffer, value_buffer);
}
/* Write whole genome stats report */
if (args->do_wgs) {
capture_report(args->report, args->cm_wgs, NULL, key_buffer, value_buffer);
}
/* Write capture stats report */
if (args->do_capture) {
capture_report(args->report, args->cm, args->ti, key_buffer, value_buffer);
}
report_print(args->output_fp, args->report);
free(key_buffer);
free(value_buffer);
} | /**
* Handle coverage operations for last processed chromosome and write final
* report to file.
*/ | Handle coverage operations for last processed chromosome and write final
report to file. | [
"Handle",
"coverage",
"operations",
"for",
"last",
"processed",
"chromosome",
"and",
"write",
"final",
"report",
"to",
"file",
"."
] | void finalize_results(args_t *args)
{
if ((args->do_wgs || args->do_capture) && args->curr_chrom_idx >= 0) {
if (args->do_cov_mask) {
handle_coverage_mask(
args->coverage,
args->cov_mask_ti,
args->curr_chrom_idx,
args->curr_chrom_len);
}
if (args->do_wgs) {
handle_wgs_coverage(
args->coverage,
args->cm_wgs,
args->ci_wgs,
args->curr_chrom_len);
}
if (args->do_capture) {
handle_target_coverage(
args->coverage,
args->cm,
args->ci,
args->ti,
args->curr_chrom_idx,
args->curr_chrom_name,
args->curr_chrom_len);
handle_miss_reads(
args->coverage,
args->cm,
args->ti,
args->curr_chrom_idx,
args->curr_chrom_len);
}
}
if (args->do_alignment) {
align_len_finalize(args->alm_all);
align_len_finalize(args->alm_read1);
align_len_finalize(args->alm_read2);
insert_size_finalize(args->ism);
}
if (args->do_wgs) {
capture_metrics_finalize(args->cm_wgs, args->ci_wgs, NULL);
}
if (args->do_capture) {
capture_metrics_finalize(args->cm, args->ci, args->ti);
}
if (args->verbose) {
log_info("Finished processing records.");
}
if (args->verbose) {
log_info("Writing report.");
}
char *key_buffer = malloc(REPORT_BUFFER_SIZE * sizeof(char));
die_on_alloc_fail(key_buffer);
char *value_buffer = malloc(REPORT_BUFFER_SIZE * sizeof(char));
die_on_alloc_fail(value_buffer);
char *input_fn;
if (args->input_fn != NULL) {
input_fn = args->input_fn;
} else {
input_fn = "-";
}
copy_to_buffer(key_buffer, "InputFileName", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "\"%s\"", args->input_fn);
report_add_key_value(args->report, key_buffer, value_buffer);
off_t filesize = 0;
if (strcmp(args->input_fn, "-") != 0) {
struct stat statbuf;
stat(input_fn, &statbuf);
filesize = statbuf.st_size;
}
copy_to_buffer(key_buffer, "InputFileSize", REPORT_BUFFER_SIZE);
snprintf(value_buffer, REPORT_BUFFER_SIZE, "%lu", filesize);
report_add_key_value(args->report, key_buffer, value_buffer);
filter_counter_report(args->report, args->fc, key_buffer, value_buffer);
if (args->do_alignment) {
align_report(args->report, args->am_all, RT_ALL, key_buffer, value_buffer);
align_report(args->report, args->am_read1, RT_READ1, key_buffer, value_buffer);
align_report(args->report, args->am_read2, RT_READ2, key_buffer, value_buffer);
align_len_report(args->report, args->alm_all, RT_ALL, key_buffer, value_buffer);
align_len_report(args->report, args->alm_read1, RT_READ1, key_buffer, value_buffer);
align_len_report(args->report, args->alm_read2, RT_READ2, key_buffer, value_buffer);
pair_stats_report(args->report, args->psm, key_buffer, value_buffer);
insert_size_report(args->report, args->ism, key_buffer, value_buffer);
}
if (args->do_wgs) {
capture_report(args->report, args->cm_wgs, NULL, key_buffer, value_buffer);
}
if (args->do_capture) {
capture_report(args->report, args->cm, args->ti, key_buffer, value_buffer);
}
report_print(args->output_fp, args->report);
free(key_buffer);
free(value_buffer);
} | [
"void",
"finalize_results",
"(",
"args_t",
"*",
"args",
")",
"{",
"if",
"(",
"(",
"args",
"->",
"do_wgs",
"||",
"args",
"->",
"do_capture",
")",
"&&",
"args",
"->",
"curr_chrom_idx",
">=",
"0",
")",
"{",
"if",
"(",
"args",
"->",
"do_cov_mask",
")",
"{",
"handle_coverage_mask",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cov_mask_ti",
",",
"args",
"->",
"curr_chrom_idx",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_wgs",
")",
"{",
"handle_wgs_coverage",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm_wgs",
",",
"args",
"->",
"ci_wgs",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_capture",
")",
"{",
"handle_target_coverage",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"ci",
",",
"args",
"->",
"ti",
",",
"args",
"->",
"curr_chrom_idx",
",",
"args",
"->",
"curr_chrom_name",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"handle_miss_reads",
"(",
"args",
"->",
"coverage",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"ti",
",",
"args",
"->",
"curr_chrom_idx",
",",
"args",
"->",
"curr_chrom_len",
")",
";",
"}",
"}",
"if",
"(",
"args",
"->",
"do_alignment",
")",
"{",
"align_len_finalize",
"(",
"args",
"->",
"alm_all",
")",
";",
"align_len_finalize",
"(",
"args",
"->",
"alm_read1",
")",
";",
"align_len_finalize",
"(",
"args",
"->",
"alm_read2",
")",
";",
"insert_size_finalize",
"(",
"args",
"->",
"ism",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_wgs",
")",
"{",
"capture_metrics_finalize",
"(",
"args",
"->",
"cm_wgs",
",",
"args",
"->",
"ci_wgs",
",",
"NULL",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_capture",
")",
"{",
"capture_metrics_finalize",
"(",
"args",
"->",
"cm",
",",
"args",
"->",
"ci",
",",
"args",
"->",
"ti",
")",
";",
"}",
"if",
"(",
"args",
"->",
"verbose",
")",
"{",
"log_info",
"(",
"\"",
"\"",
")",
";",
"}",
"if",
"(",
"args",
"->",
"verbose",
")",
"{",
"log_info",
"(",
"\"",
"\"",
")",
";",
"}",
"char",
"*",
"key_buffer",
"=",
"malloc",
"(",
"REPORT_BUFFER_SIZE",
"*",
"sizeof",
"(",
"char",
")",
")",
";",
"die_on_alloc_fail",
"(",
"key_buffer",
")",
";",
"char",
"*",
"value_buffer",
"=",
"malloc",
"(",
"REPORT_BUFFER_SIZE",
"*",
"sizeof",
"(",
"char",
")",
")",
";",
"die_on_alloc_fail",
"(",
"value_buffer",
")",
";",
"char",
"*",
"input_fn",
";",
"if",
"(",
"args",
"->",
"input_fn",
"!=",
"NULL",
")",
"{",
"input_fn",
"=",
"args",
"->",
"input_fn",
";",
"}",
"else",
"{",
"input_fn",
"=",
"\"",
"\"",
";",
"}",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"args",
"->",
"input_fn",
")",
";",
"report_add_key_value",
"(",
"args",
"->",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"off_t",
"filesize",
"=",
"0",
";",
"if",
"(",
"strcmp",
"(",
"args",
"->",
"input_fn",
",",
"\"",
"\"",
")",
"!=",
"0",
")",
"{",
"struct",
"stat",
"statbuf",
";",
"stat",
"(",
"input_fn",
",",
"&",
"statbuf",
")",
";",
"filesize",
"=",
"statbuf",
".",
"st_size",
";",
"}",
"copy_to_buffer",
"(",
"key_buffer",
",",
"\"",
"\"",
",",
"REPORT_BUFFER_SIZE",
")",
";",
"snprintf",
"(",
"value_buffer",
",",
"REPORT_BUFFER_SIZE",
",",
"\"",
"\"",
",",
"filesize",
")",
";",
"report_add_key_value",
"(",
"args",
"->",
"report",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"filter_counter_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"fc",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"if",
"(",
"args",
"->",
"do_alignment",
")",
"{",
"align_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"am_all",
",",
"RT_ALL",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"align_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"am_read1",
",",
"RT_READ1",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"align_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"am_read2",
",",
"RT_READ2",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"align_len_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"alm_all",
",",
"RT_ALL",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"align_len_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"alm_read1",
",",
"RT_READ1",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"align_len_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"alm_read2",
",",
"RT_READ2",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"pair_stats_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"psm",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"insert_size_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"ism",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_wgs",
")",
"{",
"capture_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"cm_wgs",
",",
"NULL",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"}",
"if",
"(",
"args",
"->",
"do_capture",
")",
"{",
"capture_report",
"(",
"args",
"->",
"report",
",",
"args",
"->",
"cm",
",",
"args",
"->",
"ti",
",",
"key_buffer",
",",
"value_buffer",
")",
";",
"}",
"report_print",
"(",
"args",
"->",
"output_fp",
",",
"args",
"->",
"report",
")",
";",
"free",
"(",
"key_buffer",
")",
";",
"free",
"(",
"value_buffer",
")",
";",
"}"
] | Handle coverage operations for last processed chromosome and write final
report to file. | [
"Handle",
"coverage",
"operations",
"for",
"last",
"processed",
"chromosome",
"and",
"write",
"final",
"report",
"to",
"file",
"."
] | [
"/* Target coverage and miss reads for last chromosome */",
"/* Finalize results */",
"/*align_len_finalize(args->alm_fragment);*/",
"/* Write report */",
"/* Report filtered/unfiltered read counts */",
"/* Write alignment stats report */",
"/* Write whole genome stats report */",
"/* Write capture stats report */"
] | [
{
"param": "args",
"type": "args_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "args_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | pt_read_bam | void | void *pt_read_bam(void *arg)
{
args_t *args = (args_t *)arg;
args->read_section_idx = 0;
args->read_buff = args->rec_buff_arr[args->read_section_idx];
uint32_t read_size;
do {
/* read section */
sem_wait(&args->read_sem);
args->read_buff_size[args->read_section_idx] = args->read_bam_func(args);
sem_post(&args->proc_sem);
/* advance to next section in ring buffer */
read_size = args->read_buff_size[args->process_section_idx];
args->read_section_idx = (args->read_section_idx + 1) % RECORD_BUFFER_SECTIONS;
args->read_buff = args->rec_buff_arr[args->read_section_idx];
} while (read_size > 0);
pthread_exit(NULL);
} | /**
* Pthread function to read bam1_t records into buffers.
*/ | Pthread function to read bam1_t records into buffers. | [
"Pthread",
"function",
"to",
"read",
"bam1_t",
"records",
"into",
"buffers",
"."
] | void *pt_read_bam(void *arg)
{
args_t *args = (args_t *)arg;
args->read_section_idx = 0;
args->read_buff = args->rec_buff_arr[args->read_section_idx];
uint32_t read_size;
do {
sem_wait(&args->read_sem);
args->read_buff_size[args->read_section_idx] = args->read_bam_func(args);
sem_post(&args->proc_sem);
read_size = args->read_buff_size[args->process_section_idx];
args->read_section_idx = (args->read_section_idx + 1) % RECORD_BUFFER_SECTIONS;
args->read_buff = args->rec_buff_arr[args->read_section_idx];
} while (read_size > 0);
pthread_exit(NULL);
} | [
"void",
"*",
"pt_read_bam",
"(",
"void",
"*",
"arg",
")",
"{",
"args_t",
"*",
"args",
"=",
"(",
"args_t",
"*",
")",
"arg",
";",
"args",
"->",
"read_section_idx",
"=",
"0",
";",
"args",
"->",
"read_buff",
"=",
"args",
"->",
"rec_buff_arr",
"[",
"args",
"->",
"read_section_idx",
"]",
";",
"uint32_t",
"read_size",
";",
"do",
"{",
"sem_wait",
"(",
"&",
"args",
"->",
"read_sem",
")",
";",
"args",
"->",
"read_buff_size",
"[",
"args",
"->",
"read_section_idx",
"]",
"=",
"args",
"->",
"read_bam_func",
"(",
"args",
")",
";",
"sem_post",
"(",
"&",
"args",
"->",
"proc_sem",
")",
";",
"read_size",
"=",
"args",
"->",
"read_buff_size",
"[",
"args",
"->",
"process_section_idx",
"]",
";",
"args",
"->",
"read_section_idx",
"=",
"(",
"args",
"->",
"read_section_idx",
"+",
"1",
")",
"%",
"RECORD_BUFFER_SECTIONS",
";",
"args",
"->",
"read_buff",
"=",
"args",
"->",
"rec_buff_arr",
"[",
"args",
"->",
"read_section_idx",
"]",
";",
"}",
"while",
"(",
"read_size",
">",
"0",
")",
";",
"pthread_exit",
"(",
"NULL",
")",
";",
"}"
] | Pthread function to read bam1_t records into buffers. | [
"Pthread",
"function",
"to",
"read",
"bam1_t",
"records",
"into",
"buffers",
"."
] | [
"/* read section */",
"/* advance to next section in ring buffer */"
] | [
{
"param": "arg",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | pt_process_records | void | void *pt_process_records(void *arg)
{
args_t *args = (args_t *)arg;
args->process_section_idx = 0;
args->curr_buff = args->rec_buff_arr[args->process_section_idx];
uint32_t process_size;
do {
/* process section */
sem_wait(&args->proc_sem);
process_records(args);
process_size = args->read_buff_size[args->process_section_idx];
sem_post(&args->read_sem);
/* advance to next section in ring buffer */
args->process_section_idx = (args->process_section_idx + 1) % RECORD_BUFFER_SECTIONS;
args->curr_buff = args->rec_buff_arr[args->process_section_idx];
} while (process_size > 0);
finalize_results(args);
pthread_exit(NULL);
} | /**
* Pthread function to process bam1_t records read into buffers.
*/ | Pthread function to process bam1_t records read into buffers. | [
"Pthread",
"function",
"to",
"process",
"bam1_t",
"records",
"read",
"into",
"buffers",
"."
] | void *pt_process_records(void *arg)
{
args_t *args = (args_t *)arg;
args->process_section_idx = 0;
args->curr_buff = args->rec_buff_arr[args->process_section_idx];
uint32_t process_size;
do {
sem_wait(&args->proc_sem);
process_records(args);
process_size = args->read_buff_size[args->process_section_idx];
sem_post(&args->read_sem);
args->process_section_idx = (args->process_section_idx + 1) % RECORD_BUFFER_SECTIONS;
args->curr_buff = args->rec_buff_arr[args->process_section_idx];
} while (process_size > 0);
finalize_results(args);
pthread_exit(NULL);
} | [
"void",
"*",
"pt_process_records",
"(",
"void",
"*",
"arg",
")",
"{",
"args_t",
"*",
"args",
"=",
"(",
"args_t",
"*",
")",
"arg",
";",
"args",
"->",
"process_section_idx",
"=",
"0",
";",
"args",
"->",
"curr_buff",
"=",
"args",
"->",
"rec_buff_arr",
"[",
"args",
"->",
"process_section_idx",
"]",
";",
"uint32_t",
"process_size",
";",
"do",
"{",
"sem_wait",
"(",
"&",
"args",
"->",
"proc_sem",
")",
";",
"process_records",
"(",
"args",
")",
";",
"process_size",
"=",
"args",
"->",
"read_buff_size",
"[",
"args",
"->",
"process_section_idx",
"]",
";",
"sem_post",
"(",
"&",
"args",
"->",
"read_sem",
")",
";",
"args",
"->",
"process_section_idx",
"=",
"(",
"args",
"->",
"process_section_idx",
"+",
"1",
")",
"%",
"RECORD_BUFFER_SECTIONS",
";",
"args",
"->",
"curr_buff",
"=",
"args",
"->",
"rec_buff_arr",
"[",
"args",
"->",
"process_section_idx",
"]",
";",
"}",
"while",
"(",
"process_size",
">",
"0",
")",
";",
"finalize_results",
"(",
"args",
")",
";",
"pthread_exit",
"(",
"NULL",
")",
";",
"}"
] | Pthread function to process bam1_t records read into buffers. | [
"Pthread",
"function",
"to",
"process",
"bam1_t",
"records",
"read",
"into",
"buffers",
"."
] | [
"/* process section */",
"/* advance to next section in ring buffer */"
] | [
{
"param": "arg",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b22ba204a84cb861bccbd9e549cdc41fe7c98127 | jfarek/alignstats | processing.c | [
"BSD-3-Clause"
] | C | read_and_process | void | void read_and_process(args_t *args)
{
size_t section_idx = 0;
args->read_buff = args->curr_buff = args->rec_buff_arr[section_idx];
/* while read records */
while ((args->read_buff_size[section_idx] = args->read_bam_func(args)) > 0) {
/* process ... */
process_records(args);
/* then advance to next section in ring buffer */
section_idx = (section_idx + 1) % RECORD_BUFFER_SECTIONS;
args->read_buff = args->curr_buff = args->rec_buff_arr[section_idx];
args->read_section_idx = args->process_section_idx = section_idx;
}
finalize_results(args);
} | /**
* Read bam1_t records into buffers and then process.
*/ | Read bam1_t records into buffers and then process. | [
"Read",
"bam1_t",
"records",
"into",
"buffers",
"and",
"then",
"process",
"."
] | void read_and_process(args_t *args)
{
size_t section_idx = 0;
args->read_buff = args->curr_buff = args->rec_buff_arr[section_idx];
while ((args->read_buff_size[section_idx] = args->read_bam_func(args)) > 0) {
process_records(args);
section_idx = (section_idx + 1) % RECORD_BUFFER_SECTIONS;
args->read_buff = args->curr_buff = args->rec_buff_arr[section_idx];
args->read_section_idx = args->process_section_idx = section_idx;
}
finalize_results(args);
} | [
"void",
"read_and_process",
"(",
"args_t",
"*",
"args",
")",
"{",
"size_t",
"section_idx",
"=",
"0",
";",
"args",
"->",
"read_buff",
"=",
"args",
"->",
"curr_buff",
"=",
"args",
"->",
"rec_buff_arr",
"[",
"section_idx",
"]",
";",
"while",
"(",
"(",
"args",
"->",
"read_buff_size",
"[",
"section_idx",
"]",
"=",
"args",
"->",
"read_bam_func",
"(",
"args",
")",
")",
">",
"0",
")",
"{",
"process_records",
"(",
"args",
")",
";",
"section_idx",
"=",
"(",
"section_idx",
"+",
"1",
")",
"%",
"RECORD_BUFFER_SECTIONS",
";",
"args",
"->",
"read_buff",
"=",
"args",
"->",
"curr_buff",
"=",
"args",
"->",
"rec_buff_arr",
"[",
"section_idx",
"]",
";",
"args",
"->",
"read_section_idx",
"=",
"args",
"->",
"process_section_idx",
"=",
"section_idx",
";",
"}",
"finalize_results",
"(",
"args",
")",
";",
"}"
] | Read bam1_t records into buffers and then process. | [
"Read",
"bam1_t",
"records",
"into",
"buffers",
"and",
"then",
"process",
"."
] | [
"/* while read records */",
"/* process ... */",
"/* then advance to next section in ring buffer */"
] | [
{
"param": "args",
"type": "args_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "args",
"type": "args_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
17fc8f6fb68894f9b8304048cc4229eb628ce117 | tstivers1990/sway | sway/desktop/render.c | [
"MIT"
] | C | render_view | void | static void render_view(struct sway_output *output, pixman_region32_t *damage,
struct sway_container *con, struct border_colors *colors) {
struct sway_view *view = con->view;
if (!wl_list_empty(&view->saved_buffers)) {
render_saved_view(view, output, damage, view->container->alpha);
} else if (view->surface) {
render_view_toplevels(view, output, damage, view->container->alpha);
}
if (con->current.border == B_NONE || con->current.border == B_CSD) {
return;
}
struct wlr_box box;
float output_scale = output->wlr_output->scale;
float color[4];
struct sway_container_state *state = &con->current;
if (state->border_left) {
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
box.x = floor(state->x);
box.y = floor(state->content_y);
box.width = state->border_thickness;
box.height = state->content_height;
scale_box(&box, output_scale);
render_rect(output, damage, &box, color);
}
list_t *siblings = container_get_current_siblings(con);
enum sway_container_layout layout =
container_current_parent_layout(con);
if (state->border_right) {
if (!container_is_current_floating(con) && siblings->length == 1 && layout == L_HORIZ) {
memcpy(&color, colors->indicator, sizeof(float) * 4);
} else {
memcpy(&color, colors->child_border, sizeof(float) * 4);
}
premultiply_alpha(color, con->alpha);
box.x = floor(state->content_x + state->content_width);
box.y = floor(state->content_y);
box.width = state->border_thickness;
box.height = state->content_height;
scale_box(&box, output_scale);
render_rect(output, damage, &box, color);
}
if (state->border_bottom) {
if (!container_is_current_floating(con) && siblings->length == 1 && layout == L_VERT) {
memcpy(&color, colors->indicator, sizeof(float) * 4);
} else {
memcpy(&color, colors->child_border, sizeof(float) * 4);
}
premultiply_alpha(color, con->alpha);
box.x = floor(state->x);
box.y = floor(state->content_y + state->content_height);
box.width = state->width;
box.height = state->border_thickness;
scale_box(&box, output_scale);
render_rect(output, damage, &box, color);
}
} | /**
* Render a view's surface and left/bottom/right borders.
*/ | Render a view's surface and left/bottom/right borders. | [
"Render",
"a",
"view",
"'",
"s",
"surface",
"and",
"left",
"/",
"bottom",
"/",
"right",
"borders",
"."
] | static void render_view(struct sway_output *output, pixman_region32_t *damage,
struct sway_container *con, struct border_colors *colors) {
struct sway_view *view = con->view;
if (!wl_list_empty(&view->saved_buffers)) {
render_saved_view(view, output, damage, view->container->alpha);
} else if (view->surface) {
render_view_toplevels(view, output, damage, view->container->alpha);
}
if (con->current.border == B_NONE || con->current.border == B_CSD) {
return;
}
struct wlr_box box;
float output_scale = output->wlr_output->scale;
float color[4];
struct sway_container_state *state = &con->current;
if (state->border_left) {
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
box.x = floor(state->x);
box.y = floor(state->content_y);
box.width = state->border_thickness;
box.height = state->content_height;
scale_box(&box, output_scale);
render_rect(output, damage, &box, color);
}
list_t *siblings = container_get_current_siblings(con);
enum sway_container_layout layout =
container_current_parent_layout(con);
if (state->border_right) {
if (!container_is_current_floating(con) && siblings->length == 1 && layout == L_HORIZ) {
memcpy(&color, colors->indicator, sizeof(float) * 4);
} else {
memcpy(&color, colors->child_border, sizeof(float) * 4);
}
premultiply_alpha(color, con->alpha);
box.x = floor(state->content_x + state->content_width);
box.y = floor(state->content_y);
box.width = state->border_thickness;
box.height = state->content_height;
scale_box(&box, output_scale);
render_rect(output, damage, &box, color);
}
if (state->border_bottom) {
if (!container_is_current_floating(con) && siblings->length == 1 && layout == L_VERT) {
memcpy(&color, colors->indicator, sizeof(float) * 4);
} else {
memcpy(&color, colors->child_border, sizeof(float) * 4);
}
premultiply_alpha(color, con->alpha);
box.x = floor(state->x);
box.y = floor(state->content_y + state->content_height);
box.width = state->width;
box.height = state->border_thickness;
scale_box(&box, output_scale);
render_rect(output, damage, &box, color);
}
} | [
"static",
"void",
"render_view",
"(",
"struct",
"sway_output",
"*",
"output",
",",
"pixman_region32_t",
"*",
"damage",
",",
"struct",
"sway_container",
"*",
"con",
",",
"struct",
"border_colors",
"*",
"colors",
")",
"{",
"struct",
"sway_view",
"*",
"view",
"=",
"con",
"->",
"view",
";",
"if",
"(",
"!",
"wl_list_empty",
"(",
"&",
"view",
"->",
"saved_buffers",
")",
")",
"{",
"render_saved_view",
"(",
"view",
",",
"output",
",",
"damage",
",",
"view",
"->",
"container",
"->",
"alpha",
")",
";",
"}",
"else",
"if",
"(",
"view",
"->",
"surface",
")",
"{",
"render_view_toplevels",
"(",
"view",
",",
"output",
",",
"damage",
",",
"view",
"->",
"container",
"->",
"alpha",
")",
";",
"}",
"if",
"(",
"con",
"->",
"current",
".",
"border",
"==",
"B_NONE",
"||",
"con",
"->",
"current",
".",
"border",
"==",
"B_CSD",
")",
"{",
"return",
";",
"}",
"struct",
"wlr_box",
"box",
";",
"float",
"output_scale",
"=",
"output",
"->",
"wlr_output",
"->",
"scale",
";",
"float",
"color",
"[",
"4",
"]",
";",
"struct",
"sway_container_state",
"*",
"state",
"=",
"&",
"con",
"->",
"current",
";",
"if",
"(",
"state",
"->",
"border_left",
")",
"{",
"memcpy",
"(",
"&",
"color",
",",
"colors",
"->",
"child_border",
",",
"sizeof",
"(",
"float",
")",
"*",
"4",
")",
";",
"premultiply_alpha",
"(",
"color",
",",
"con",
"->",
"alpha",
")",
";",
"box",
".",
"x",
"=",
"floor",
"(",
"state",
"->",
"x",
")",
";",
"box",
".",
"y",
"=",
"floor",
"(",
"state",
"->",
"content_y",
")",
";",
"box",
".",
"width",
"=",
"state",
"->",
"border_thickness",
";",
"box",
".",
"height",
"=",
"state",
"->",
"content_height",
";",
"scale_box",
"(",
"&",
"box",
",",
"output_scale",
")",
";",
"render_rect",
"(",
"output",
",",
"damage",
",",
"&",
"box",
",",
"color",
")",
";",
"}",
"list_t",
"*",
"siblings",
"=",
"container_get_current_siblings",
"(",
"con",
")",
";",
"enum",
"sway_container_layout",
"layout",
"=",
"container_current_parent_layout",
"(",
"con",
")",
";",
"if",
"(",
"state",
"->",
"border_right",
")",
"{",
"if",
"(",
"!",
"container_is_current_floating",
"(",
"con",
")",
"&&",
"siblings",
"->",
"length",
"==",
"1",
"&&",
"layout",
"==",
"L_HORIZ",
")",
"{",
"memcpy",
"(",
"&",
"color",
",",
"colors",
"->",
"indicator",
",",
"sizeof",
"(",
"float",
")",
"*",
"4",
")",
";",
"}",
"else",
"{",
"memcpy",
"(",
"&",
"color",
",",
"colors",
"->",
"child_border",
",",
"sizeof",
"(",
"float",
")",
"*",
"4",
")",
";",
"}",
"premultiply_alpha",
"(",
"color",
",",
"con",
"->",
"alpha",
")",
";",
"box",
".",
"x",
"=",
"floor",
"(",
"state",
"->",
"content_x",
"+",
"state",
"->",
"content_width",
")",
";",
"box",
".",
"y",
"=",
"floor",
"(",
"state",
"->",
"content_y",
")",
";",
"box",
".",
"width",
"=",
"state",
"->",
"border_thickness",
";",
"box",
".",
"height",
"=",
"state",
"->",
"content_height",
";",
"scale_box",
"(",
"&",
"box",
",",
"output_scale",
")",
";",
"render_rect",
"(",
"output",
",",
"damage",
",",
"&",
"box",
",",
"color",
")",
";",
"}",
"if",
"(",
"state",
"->",
"border_bottom",
")",
"{",
"if",
"(",
"!",
"container_is_current_floating",
"(",
"con",
")",
"&&",
"siblings",
"->",
"length",
"==",
"1",
"&&",
"layout",
"==",
"L_VERT",
")",
"{",
"memcpy",
"(",
"&",
"color",
",",
"colors",
"->",
"indicator",
",",
"sizeof",
"(",
"float",
")",
"*",
"4",
")",
";",
"}",
"else",
"{",
"memcpy",
"(",
"&",
"color",
",",
"colors",
"->",
"child_border",
",",
"sizeof",
"(",
"float",
")",
"*",
"4",
")",
";",
"}",
"premultiply_alpha",
"(",
"color",
",",
"con",
"->",
"alpha",
")",
";",
"box",
".",
"x",
"=",
"floor",
"(",
"state",
"->",
"x",
")",
";",
"box",
".",
"y",
"=",
"floor",
"(",
"state",
"->",
"content_y",
"+",
"state",
"->",
"content_height",
")",
";",
"box",
".",
"width",
"=",
"state",
"->",
"width",
";",
"box",
".",
"height",
"=",
"state",
"->",
"border_thickness",
";",
"scale_box",
"(",
"&",
"box",
",",
"output_scale",
")",
";",
"render_rect",
"(",
"output",
",",
"damage",
",",
"&",
"box",
",",
"color",
")",
";",
"}",
"}"
] | Render a view's surface and left/bottom/right borders. | [
"Render",
"a",
"view",
"'",
"s",
"surface",
"and",
"left",
"/",
"bottom",
"/",
"right",
"borders",
"."
] | [] | [
{
"param": "output",
"type": "struct sway_output"
},
{
"param": "damage",
"type": "pixman_region32_t"
},
{
"param": "con",
"type": "struct sway_container"
},
{
"param": "colors",
"type": "struct border_colors"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "output",
"type": "struct sway_output",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "damage",
"type": "pixman_region32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "con",
"type": "struct sway_container",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "colors",
"type": "struct border_colors",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
17fc8f6fb68894f9b8304048cc4229eb628ce117 | tstivers1990/sway | sway/desktop/render.c | [
"MIT"
] | C | render_top_border | void | static void render_top_border(struct sway_output *output,
pixman_region32_t *output_damage, struct sway_container *con,
struct border_colors *colors) {
struct sway_container_state *state = &con->current;
if (!state->border_top) {
return;
}
struct wlr_box box;
float color[4];
float output_scale = output->wlr_output->scale;
// Child border - top edge
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
box.x = floor(state->x);
box.y = floor(state->y);
box.width = state->width;
box.height = state->border_thickness;
scale_box(&box, output_scale);
render_rect(output, output_damage, &box, color);
} | /**
* Render the top border line for a view using "border pixel".
*/ | Render the top border line for a view using "border pixel". | [
"Render",
"the",
"top",
"border",
"line",
"for",
"a",
"view",
"using",
"\"",
"border",
"pixel",
"\"",
"."
] | static void render_top_border(struct sway_output *output,
pixman_region32_t *output_damage, struct sway_container *con,
struct border_colors *colors) {
struct sway_container_state *state = &con->current;
if (!state->border_top) {
return;
}
struct wlr_box box;
float color[4];
float output_scale = output->wlr_output->scale;
memcpy(&color, colors->child_border, sizeof(float) * 4);
premultiply_alpha(color, con->alpha);
box.x = floor(state->x);
box.y = floor(state->y);
box.width = state->width;
box.height = state->border_thickness;
scale_box(&box, output_scale);
render_rect(output, output_damage, &box, color);
} | [
"static",
"void",
"render_top_border",
"(",
"struct",
"sway_output",
"*",
"output",
",",
"pixman_region32_t",
"*",
"output_damage",
",",
"struct",
"sway_container",
"*",
"con",
",",
"struct",
"border_colors",
"*",
"colors",
")",
"{",
"struct",
"sway_container_state",
"*",
"state",
"=",
"&",
"con",
"->",
"current",
";",
"if",
"(",
"!",
"state",
"->",
"border_top",
")",
"{",
"return",
";",
"}",
"struct",
"wlr_box",
"box",
";",
"float",
"color",
"[",
"4",
"]",
";",
"float",
"output_scale",
"=",
"output",
"->",
"wlr_output",
"->",
"scale",
";",
"memcpy",
"(",
"&",
"color",
",",
"colors",
"->",
"child_border",
",",
"sizeof",
"(",
"float",
")",
"*",
"4",
")",
";",
"premultiply_alpha",
"(",
"color",
",",
"con",
"->",
"alpha",
")",
";",
"box",
".",
"x",
"=",
"floor",
"(",
"state",
"->",
"x",
")",
";",
"box",
".",
"y",
"=",
"floor",
"(",
"state",
"->",
"y",
")",
";",
"box",
".",
"width",
"=",
"state",
"->",
"width",
";",
"box",
".",
"height",
"=",
"state",
"->",
"border_thickness",
";",
"scale_box",
"(",
"&",
"box",
",",
"output_scale",
")",
";",
"render_rect",
"(",
"output",
",",
"output_damage",
",",
"&",
"box",
",",
"color",
")",
";",
"}"
] | Render the top border line for a view using "border pixel". | [
"Render",
"the",
"top",
"border",
"line",
"for",
"a",
"view",
"using",
"\"",
"border",
"pixel",
"\"",
"."
] | [
"// Child border - top edge"
] | [
{
"param": "output",
"type": "struct sway_output"
},
{
"param": "output_damage",
"type": "pixman_region32_t"
},
{
"param": "con",
"type": "struct sway_container"
},
{
"param": "colors",
"type": "struct border_colors"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "output",
"type": "struct sway_output",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "output_damage",
"type": "pixman_region32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "con",
"type": "struct sway_container",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "colors",
"type": "struct border_colors",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
17fc8f6fb68894f9b8304048cc4229eb628ce117 | tstivers1990/sway | sway/desktop/render.c | [
"MIT"
] | C | render_containers_linear | void | static void render_containers_linear(struct sway_output *output,
pixman_region32_t *damage, struct parent_data *parent) {
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
if (child->view) {
struct sway_view *view = child->view;
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
struct sway_container_state *state = &child->current;
if (view_is_urgent(view)) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
marks_texture = child->marks_urgent;
} else if (state->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
marks_texture = child->marks_unfocused;
}
if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, floor(state->x),
floor(state->y), state->width, colors,
title_texture, marks_texture);
} else if (state->border == B_PIXEL) {
render_top_border(output, damage, child, colors);
}
render_view(output, damage, child, colors);
} else {
render_container(output, damage, child,
parent->focused || child->current.focused);
}
}
} | /**
* Render a container's children using a L_HORIZ or L_VERT layout.
*
* Wrap child views in borders and leave child containers borderless because
* they'll apply their own borders to their children.
*/ | Render a container's children using a L_HORIZ or L_VERT layout.
Wrap child views in borders and leave child containers borderless because
they'll apply their own borders to their children. | [
"Render",
"a",
"container",
"'",
"s",
"children",
"using",
"a",
"L_HORIZ",
"or",
"L_VERT",
"layout",
".",
"Wrap",
"child",
"views",
"in",
"borders",
"and",
"leave",
"child",
"containers",
"borderless",
"because",
"they",
"'",
"ll",
"apply",
"their",
"own",
"borders",
"to",
"their",
"children",
"."
] | static void render_containers_linear(struct sway_output *output,
pixman_region32_t *damage, struct parent_data *parent) {
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
if (child->view) {
struct sway_view *view = child->view;
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
struct sway_container_state *state = &child->current;
if (view_is_urgent(view)) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
marks_texture = child->marks_urgent;
} else if (state->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
marks_texture = child->marks_unfocused;
}
if (state->border == B_NORMAL) {
render_titlebar(output, damage, child, floor(state->x),
floor(state->y), state->width, colors,
title_texture, marks_texture);
} else if (state->border == B_PIXEL) {
render_top_border(output, damage, child, colors);
}
render_view(output, damage, child, colors);
} else {
render_container(output, damage, child,
parent->focused || child->current.focused);
}
}
} | [
"static",
"void",
"render_containers_linear",
"(",
"struct",
"sway_output",
"*",
"output",
",",
"pixman_region32_t",
"*",
"damage",
",",
"struct",
"parent_data",
"*",
"parent",
")",
"{",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parent",
"->",
"children",
"->",
"length",
";",
"++",
"i",
")",
"{",
"struct",
"sway_container",
"*",
"child",
"=",
"parent",
"->",
"children",
"->",
"items",
"[",
"i",
"]",
";",
"if",
"(",
"child",
"->",
"view",
")",
"{",
"struct",
"sway_view",
"*",
"view",
"=",
"child",
"->",
"view",
";",
"struct",
"border_colors",
"*",
"colors",
";",
"struct",
"wlr_texture",
"*",
"title_texture",
";",
"struct",
"wlr_texture",
"*",
"marks_texture",
";",
"struct",
"sway_container_state",
"*",
"state",
"=",
"&",
"child",
"->",
"current",
";",
"if",
"(",
"view_is_urgent",
"(",
"view",
")",
")",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"urgent",
";",
"title_texture",
"=",
"child",
"->",
"title_urgent",
";",
"marks_texture",
"=",
"child",
"->",
"marks_urgent",
";",
"}",
"else",
"if",
"(",
"state",
"->",
"focused",
"||",
"parent",
"->",
"focused",
")",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"focused",
";",
"title_texture",
"=",
"child",
"->",
"title_focused",
";",
"marks_texture",
"=",
"child",
"->",
"marks_focused",
";",
"}",
"else",
"if",
"(",
"child",
"==",
"parent",
"->",
"active_child",
")",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"focused_inactive",
";",
"title_texture",
"=",
"child",
"->",
"title_focused_inactive",
";",
"marks_texture",
"=",
"child",
"->",
"marks_focused_inactive",
";",
"}",
"else",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"unfocused",
";",
"title_texture",
"=",
"child",
"->",
"title_unfocused",
";",
"marks_texture",
"=",
"child",
"->",
"marks_unfocused",
";",
"}",
"if",
"(",
"state",
"->",
"border",
"==",
"B_NORMAL",
")",
"{",
"render_titlebar",
"(",
"output",
",",
"damage",
",",
"child",
",",
"floor",
"(",
"state",
"->",
"x",
")",
",",
"floor",
"(",
"state",
"->",
"y",
")",
",",
"state",
"->",
"width",
",",
"colors",
",",
"title_texture",
",",
"marks_texture",
")",
";",
"}",
"else",
"if",
"(",
"state",
"->",
"border",
"==",
"B_PIXEL",
")",
"{",
"render_top_border",
"(",
"output",
",",
"damage",
",",
"child",
",",
"colors",
")",
";",
"}",
"render_view",
"(",
"output",
",",
"damage",
",",
"child",
",",
"colors",
")",
";",
"}",
"else",
"{",
"render_container",
"(",
"output",
",",
"damage",
",",
"child",
",",
"parent",
"->",
"focused",
"||",
"child",
"->",
"current",
".",
"focused",
")",
";",
"}",
"}",
"}"
] | Render a container's children using a L_HORIZ or L_VERT layout. | [
"Render",
"a",
"container",
"'",
"s",
"children",
"using",
"a",
"L_HORIZ",
"or",
"L_VERT",
"layout",
"."
] | [] | [
{
"param": "output",
"type": "struct sway_output"
},
{
"param": "damage",
"type": "pixman_region32_t"
},
{
"param": "parent",
"type": "struct parent_data"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "output",
"type": "struct sway_output",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "damage",
"type": "pixman_region32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "parent",
"type": "struct parent_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
17fc8f6fb68894f9b8304048cc4229eb628ce117 | tstivers1990/sway | sway/desktop/render.c | [
"MIT"
] | C | render_containers_tabbed | void | static void render_containers_tabbed(struct sway_output *output,
pixman_region32_t *damage, struct parent_data *parent) {
if (!parent->children->length) {
return;
}
struct sway_container *current = parent->active_child;
struct border_colors *current_colors = &config->border_colors.unfocused;
int tab_width = parent->box.width / parent->children->length;
// Render tabs
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
struct sway_view *view = child->view;
struct sway_container_state *cstate = &child->current;
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
bool urgent = view ?
view_is_urgent(view) : container_has_urgent_child(child);
if (urgent) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
marks_texture = child->marks_urgent;
} else if (cstate->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
marks_texture = child->marks_unfocused;
}
int x = floor(cstate->x + tab_width * i);
// Make last tab use the remaining width of the parent
if (i == parent->children->length - 1) {
tab_width = parent->box.width - tab_width * i;
}
render_titlebar(output, damage, child, x, parent->box.y, tab_width,
colors, title_texture, marks_texture);
if (child == current) {
current_colors = colors;
}
}
// Render surface and left/right/bottom borders
if (current->view) {
render_view(output, damage, current, current_colors);
} else {
render_container(output, damage, current,
parent->focused || current->current.focused);
}
} | /**
* Render a container's children using the L_TABBED layout.
*/ | Render a container's children using the L_TABBED layout. | [
"Render",
"a",
"container",
"'",
"s",
"children",
"using",
"the",
"L_TABBED",
"layout",
"."
] | static void render_containers_tabbed(struct sway_output *output,
pixman_region32_t *damage, struct parent_data *parent) {
if (!parent->children->length) {
return;
}
struct sway_container *current = parent->active_child;
struct border_colors *current_colors = &config->border_colors.unfocused;
int tab_width = parent->box.width / parent->children->length;
for (int i = 0; i < parent->children->length; ++i) {
struct sway_container *child = parent->children->items[i];
struct sway_view *view = child->view;
struct sway_container_state *cstate = &child->current;
struct border_colors *colors;
struct wlr_texture *title_texture;
struct wlr_texture *marks_texture;
bool urgent = view ?
view_is_urgent(view) : container_has_urgent_child(child);
if (urgent) {
colors = &config->border_colors.urgent;
title_texture = child->title_urgent;
marks_texture = child->marks_urgent;
} else if (cstate->focused || parent->focused) {
colors = &config->border_colors.focused;
title_texture = child->title_focused;
marks_texture = child->marks_focused;
} else if (child == parent->active_child) {
colors = &config->border_colors.focused_inactive;
title_texture = child->title_focused_inactive;
marks_texture = child->marks_focused_inactive;
} else {
colors = &config->border_colors.unfocused;
title_texture = child->title_unfocused;
marks_texture = child->marks_unfocused;
}
int x = floor(cstate->x + tab_width * i);
if (i == parent->children->length - 1) {
tab_width = parent->box.width - tab_width * i;
}
render_titlebar(output, damage, child, x, parent->box.y, tab_width,
colors, title_texture, marks_texture);
if (child == current) {
current_colors = colors;
}
}
if (current->view) {
render_view(output, damage, current, current_colors);
} else {
render_container(output, damage, current,
parent->focused || current->current.focused);
}
} | [
"static",
"void",
"render_containers_tabbed",
"(",
"struct",
"sway_output",
"*",
"output",
",",
"pixman_region32_t",
"*",
"damage",
",",
"struct",
"parent_data",
"*",
"parent",
")",
"{",
"if",
"(",
"!",
"parent",
"->",
"children",
"->",
"length",
")",
"{",
"return",
";",
"}",
"struct",
"sway_container",
"*",
"current",
"=",
"parent",
"->",
"active_child",
";",
"struct",
"border_colors",
"*",
"current_colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"unfocused",
";",
"int",
"tab_width",
"=",
"parent",
"->",
"box",
".",
"width",
"/",
"parent",
"->",
"children",
"->",
"length",
";",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parent",
"->",
"children",
"->",
"length",
";",
"++",
"i",
")",
"{",
"struct",
"sway_container",
"*",
"child",
"=",
"parent",
"->",
"children",
"->",
"items",
"[",
"i",
"]",
";",
"struct",
"sway_view",
"*",
"view",
"=",
"child",
"->",
"view",
";",
"struct",
"sway_container_state",
"*",
"cstate",
"=",
"&",
"child",
"->",
"current",
";",
"struct",
"border_colors",
"*",
"colors",
";",
"struct",
"wlr_texture",
"*",
"title_texture",
";",
"struct",
"wlr_texture",
"*",
"marks_texture",
";",
"bool",
"urgent",
"=",
"view",
"?",
"view_is_urgent",
"(",
"view",
")",
":",
"container_has_urgent_child",
"(",
"child",
")",
";",
"if",
"(",
"urgent",
")",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"urgent",
";",
"title_texture",
"=",
"child",
"->",
"title_urgent",
";",
"marks_texture",
"=",
"child",
"->",
"marks_urgent",
";",
"}",
"else",
"if",
"(",
"cstate",
"->",
"focused",
"||",
"parent",
"->",
"focused",
")",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"focused",
";",
"title_texture",
"=",
"child",
"->",
"title_focused",
";",
"marks_texture",
"=",
"child",
"->",
"marks_focused",
";",
"}",
"else",
"if",
"(",
"child",
"==",
"parent",
"->",
"active_child",
")",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"focused_inactive",
";",
"title_texture",
"=",
"child",
"->",
"title_focused_inactive",
";",
"marks_texture",
"=",
"child",
"->",
"marks_focused_inactive",
";",
"}",
"else",
"{",
"colors",
"=",
"&",
"config",
"->",
"border_colors",
".",
"unfocused",
";",
"title_texture",
"=",
"child",
"->",
"title_unfocused",
";",
"marks_texture",
"=",
"child",
"->",
"marks_unfocused",
";",
"}",
"int",
"x",
"=",
"floor",
"(",
"cstate",
"->",
"x",
"+",
"tab_width",
"*",
"i",
")",
";",
"if",
"(",
"i",
"==",
"parent",
"->",
"children",
"->",
"length",
"-",
"1",
")",
"{",
"tab_width",
"=",
"parent",
"->",
"box",
".",
"width",
"-",
"tab_width",
"*",
"i",
";",
"}",
"render_titlebar",
"(",
"output",
",",
"damage",
",",
"child",
",",
"x",
",",
"parent",
"->",
"box",
".",
"y",
",",
"tab_width",
",",
"colors",
",",
"title_texture",
",",
"marks_texture",
")",
";",
"if",
"(",
"child",
"==",
"current",
")",
"{",
"current_colors",
"=",
"colors",
";",
"}",
"}",
"if",
"(",
"current",
"->",
"view",
")",
"{",
"render_view",
"(",
"output",
",",
"damage",
",",
"current",
",",
"current_colors",
")",
";",
"}",
"else",
"{",
"render_container",
"(",
"output",
",",
"damage",
",",
"current",
",",
"parent",
"->",
"focused",
"||",
"current",
"->",
"current",
".",
"focused",
")",
";",
"}",
"}"
] | Render a container's children using the L_TABBED layout. | [
"Render",
"a",
"container",
"'",
"s",
"children",
"using",
"the",
"L_TABBED",
"layout",
"."
] | [
"// Render tabs",
"// Make last tab use the remaining width of the parent",
"// Render surface and left/right/bottom borders"
] | [
{
"param": "output",
"type": "struct sway_output"
},
{
"param": "damage",
"type": "pixman_region32_t"
},
{
"param": "parent",
"type": "struct parent_data"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "output",
"type": "struct sway_output",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "damage",
"type": "pixman_region32_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "parent",
"type": "struct parent_data",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
8dd7789dca19ec43d0e4375dcb56289ce40f1f5e | tstivers1990/sway | sway/tree/workspace.c | [
"MIT"
] | C | workspace_output_prev_next_impl | null | static struct sway_workspace *workspace_output_prev_next_impl(
struct sway_output *output, int dir) {
struct sway_seat *seat = input_manager_current_seat();
struct sway_workspace *workspace = seat_get_focused_workspace(seat);
if (!workspace) {
sway_log(SWAY_DEBUG,
"No focused workspace to base prev/next on output off of");
return NULL;
}
int index = list_find(output->workspaces, workspace);
size_t new_index = wrap(index + dir, output->workspaces->length);
return output->workspaces->items[new_index];
} | /**
* Get the previous or next workspace on the specified output. Wraps around at
* the end and beginning. If next is false, the previous workspace is returned,
* otherwise the next one is returned.
*/ | Get the previous or next workspace on the specified output. Wraps around at
the end and beginning. If next is false, the previous workspace is returned,
otherwise the next one is returned. | [
"Get",
"the",
"previous",
"or",
"next",
"workspace",
"on",
"the",
"specified",
"output",
".",
"Wraps",
"around",
"at",
"the",
"end",
"and",
"beginning",
".",
"If",
"next",
"is",
"false",
"the",
"previous",
"workspace",
"is",
"returned",
"otherwise",
"the",
"next",
"one",
"is",
"returned",
"."
] | static struct sway_workspace *workspace_output_prev_next_impl(
struct sway_output *output, int dir) {
struct sway_seat *seat = input_manager_current_seat();
struct sway_workspace *workspace = seat_get_focused_workspace(seat);
if (!workspace) {
sway_log(SWAY_DEBUG,
"No focused workspace to base prev/next on output off of");
return NULL;
}
int index = list_find(output->workspaces, workspace);
size_t new_index = wrap(index + dir, output->workspaces->length);
return output->workspaces->items[new_index];
} | [
"static",
"struct",
"sway_workspace",
"*",
"workspace_output_prev_next_impl",
"(",
"struct",
"sway_output",
"*",
"output",
",",
"int",
"dir",
")",
"{",
"struct",
"sway_seat",
"*",
"seat",
"=",
"input_manager_current_seat",
"(",
")",
";",
"struct",
"sway_workspace",
"*",
"workspace",
"=",
"seat_get_focused_workspace",
"(",
"seat",
")",
";",
"if",
"(",
"!",
"workspace",
")",
"{",
"sway_log",
"(",
"SWAY_DEBUG",
",",
"\"",
"\"",
")",
";",
"return",
"NULL",
";",
"}",
"int",
"index",
"=",
"list_find",
"(",
"output",
"->",
"workspaces",
",",
"workspace",
")",
";",
"size_t",
"new_index",
"=",
"wrap",
"(",
"index",
"+",
"dir",
",",
"output",
"->",
"workspaces",
"->",
"length",
")",
";",
"return",
"output",
"->",
"workspaces",
"->",
"items",
"[",
"new_index",
"]",
";",
"}"
] | Get the previous or next workspace on the specified output. | [
"Get",
"the",
"previous",
"or",
"next",
"workspace",
"on",
"the",
"specified",
"output",
"."
] | [] | [
{
"param": "output",
"type": "struct sway_output"
},
{
"param": "dir",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "output",
"type": "struct sway_output",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "dir",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
d42d5889204faa3cfe771e09ecf089b6277e0688 | aitorvs/ercos | arch/SPARC/ERC32/halt.c | [
"Apache-2.0"
] | C | CPU_Reset | void | void CPU_Reset(void)
{
volatile unsigned int* dirmec = (unsigned int*)0x01f80000;
dirmec[0x04 / 4] = 0xffffffff;
} | /** \brief Resets the system by writing on a special MEC register */ | \brief Resets the system by writing on a special MEC register | [
"\\",
"brief",
"Resets",
"the",
"system",
"by",
"writing",
"on",
"a",
"special",
"MEC",
"register"
] | void CPU_Reset(void)
{
volatile unsigned int* dirmec = (unsigned int*)0x01f80000;
dirmec[0x04 / 4] = 0xffffffff;
} | [
"void",
"CPU_Reset",
"(",
"void",
")",
"{",
"volatile",
"unsigned",
"int",
"*",
"dirmec",
"=",
"(",
"unsigned",
"int",
"*",
")",
"0x01f80000",
";",
"dirmec",
"[",
"0x04",
"/",
"4",
"]",
"=",
"0xffffffff",
";",
"}"
] | \brief Resets the system by writing on a special MEC register | [
"\\",
"brief",
"Resets",
"the",
"system",
"by",
"writing",
"on",
"a",
"special",
"MEC",
"register"
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
722c303dd603fe8d7bad53ade0c16c7f682fa3ba | aitorvs/ercos | kernel/time.c | [
"Apache-2.0"
] | C | OS_TimeInit | void | void OS_TimeInit(void)
{
/* Init the Real Time Clock */
OS_ClockInit();
/* Init the General Purpose Timer */
OS_TimerInit();
} | /*
* Function: void OS_TimeInit(void)
*
* This routine init the system timming. The routine init the Real Time Clock
* and the General Purpose Timer.
*/ |
This routine init the system timming. The routine init the Real Time Clock
and the General Purpose Timer. | [
"This",
"routine",
"init",
"the",
"system",
"timming",
".",
"The",
"routine",
"init",
"the",
"Real",
"Time",
"Clock",
"and",
"the",
"General",
"Purpose",
"Timer",
"."
] | void OS_TimeInit(void)
{
OS_ClockInit();
OS_TimerInit();
} | [
"void",
"OS_TimeInit",
"(",
"void",
")",
"{",
"OS_ClockInit",
"(",
")",
";",
"OS_TimerInit",
"(",
")",
";",
"}"
] | Function: void OS_TimeInit(void) | [
"Function",
":",
"void",
"OS_TimeInit",
"(",
"void",
")"
] | [
"/* Init the Real Time Clock */",
"/* Init the General Purpose Timer */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
722c303dd603fe8d7bad53ade0c16c7f682fa3ba | aitorvs/ercos | kernel/time.c | [
"Apache-2.0"
] | C | OS_TimerInit | void | static void OS_TimerInit(void)
{
uint64 clicks = OVERHEAD_CLICKS;
DEBUG ("Timer init...");
/* Register the General Purpose Timer ISR */
OS_RegisterIRQ(TIMER_TRAP, OS_TimerISR);
/* 10ms real time clock tick configuration */
CPU_TimerInit();
/* Reset the time queue */
OS_ListReset(&time_list);
/* Reset the counter */
timer_tick_counter = 0;
/* Init the system time structure */
OS_Time.seconds = OS_Time.useconds = 0;
useconds_per_timer_tick = __div64_32(&clicks, CLICKS_PER_SEC) * CLICKS_PER_USEC;
seconds_per_timer_tick = (uint32)clicks;
} | /*
* Function: static void OS_TimerInit(void)
*
* This function initializes the General Purpose Timer. It basically registers
* a timer interrupt service routine.
*/ |
This function initializes the General Purpose Timer. It basically registers
a timer interrupt service routine. | [
"This",
"function",
"initializes",
"the",
"General",
"Purpose",
"Timer",
".",
"It",
"basically",
"registers",
"a",
"timer",
"interrupt",
"service",
"routine",
"."
] | static void OS_TimerInit(void)
{
uint64 clicks = OVERHEAD_CLICKS;
DEBUG ("Timer init...");
OS_RegisterIRQ(TIMER_TRAP, OS_TimerISR);
CPU_TimerInit();
OS_ListReset(&time_list);
timer_tick_counter = 0;
OS_Time.seconds = OS_Time.useconds = 0;
useconds_per_timer_tick = __div64_32(&clicks, CLICKS_PER_SEC) * CLICKS_PER_USEC;
seconds_per_timer_tick = (uint32)clicks;
} | [
"static",
"void",
"OS_TimerInit",
"(",
"void",
")",
"{",
"uint64",
"clicks",
"=",
"OVERHEAD_CLICKS",
";",
"DEBUG",
"(",
"\"",
"\"",
")",
";",
"OS_RegisterIRQ",
"(",
"TIMER_TRAP",
",",
"OS_TimerISR",
")",
";",
"CPU_TimerInit",
"(",
")",
";",
"OS_ListReset",
"(",
"&",
"time_list",
")",
";",
"timer_tick_counter",
"=",
"0",
";",
"OS_Time",
".",
"seconds",
"=",
"OS_Time",
".",
"useconds",
"=",
"0",
";",
"useconds_per_timer_tick",
"=",
"__div64_32",
"(",
"&",
"clicks",
",",
"CLICKS_PER_SEC",
")",
"*",
"CLICKS_PER_USEC",
";",
"seconds_per_timer_tick",
"=",
"(",
"uint32",
")",
"clicks",
";",
"}"
] | Function: static void OS_TimerInit(void) | [
"Function",
":",
"static",
"void",
"OS_TimerInit",
"(",
"void",
")"
] | [
"/* Register the General Purpose Timer ISR */",
"/* 10ms real time clock tick configuration */",
"/* Reset the time queue */",
"/* Reset the counter */",
"/* Init the system time structure */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
722c303dd603fe8d7bad53ade0c16c7f682fa3ba | aitorvs/ercos | kernel/time.c | [
"Apache-2.0"
] | C | OS_DoSleep | int | int OS_DoSleep(OS_Time_t _ticks)
{
OS_Node_t *pos;
int inserted = 0;
int retval;
volatile OS_Time_t current_time = 0;
OS_Time_t clock_program_value = 0;
if(_ticks < OS_TimeGetTicks() + TIME_PENALTY)
{
retval = 0;
}
else {
/* Init the absolute clock */
current->abs_timeout = _ticks;
// DEBUG2 ("Task #%d; until %x %d\n", current - task_table, (uint32)(_ticks >> 32), (uint32)_ticks);
/* Change the task status */
current->status |= TS_TIME_BLOCKED;
if(OS_ListGetNum(&time_list) == 0)
OS_ListInsert(&time_list, &(current->time_node));
else {
list_for_each(pos, &time_list)
{
if(GET_TIME_THREAD(pos)->abs_timeout > current->abs_timeout)
{
if(pos->prev != NULL){
OS_ListAdd(&time_list, &(current->time_node), pos->prev);
}
else {
OS_ListInsert(&time_list, &(current->time_node));
}
inserted = 1;
break;
}
}
if(!inserted) {
OS_ListAppend(&time_list, &(current->time_node));
}
}
current_time = OS_TimeGetTicks() + TIME_PENALTY;
clock_program_value = FIRST_TIME_THREAD->abs_timeout - current_time;
if(clock_program_value < OVERHEAD_CLICKS &&
(FIRST_TIME_THREAD->abs_timeout > current_time))
{
OS_ProgramClock((uint32)clock_program_value);
}
else if(FIRST_TIME_THREAD->abs_timeout <= current_time)
{
OS_IRQMarkClockEvent();
}
retval = -1;
}
return retval;
} | /*
* Function: void OS_DoSleep(uint32 _ticks)
*
* In this sleep system call implementation the current task is been blocked.
* For this reason we not insert the current task in the ready queue.
*/ |
In this sleep system call implementation the current task is been blocked.
For this reason we not insert the current task in the ready queue. | [
"In",
"this",
"sleep",
"system",
"call",
"implementation",
"the",
"current",
"task",
"is",
"been",
"blocked",
".",
"For",
"this",
"reason",
"we",
"not",
"insert",
"the",
"current",
"task",
"in",
"the",
"ready",
"queue",
"."
] | int OS_DoSleep(OS_Time_t _ticks)
{
OS_Node_t *pos;
int inserted = 0;
int retval;
volatile OS_Time_t current_time = 0;
OS_Time_t clock_program_value = 0;
if(_ticks < OS_TimeGetTicks() + TIME_PENALTY)
{
retval = 0;
}
else {
current->abs_timeout = _ticks;
current->status |= TS_TIME_BLOCKED;
if(OS_ListGetNum(&time_list) == 0)
OS_ListInsert(&time_list, &(current->time_node));
else {
list_for_each(pos, &time_list)
{
if(GET_TIME_THREAD(pos)->abs_timeout > current->abs_timeout)
{
if(pos->prev != NULL){
OS_ListAdd(&time_list, &(current->time_node), pos->prev);
}
else {
OS_ListInsert(&time_list, &(current->time_node));
}
inserted = 1;
break;
}
}
if(!inserted) {
OS_ListAppend(&time_list, &(current->time_node));
}
}
current_time = OS_TimeGetTicks() + TIME_PENALTY;
clock_program_value = FIRST_TIME_THREAD->abs_timeout - current_time;
if(clock_program_value < OVERHEAD_CLICKS &&
(FIRST_TIME_THREAD->abs_timeout > current_time))
{
OS_ProgramClock((uint32)clock_program_value);
}
else if(FIRST_TIME_THREAD->abs_timeout <= current_time)
{
OS_IRQMarkClockEvent();
}
retval = -1;
}
return retval;
} | [
"int",
"OS_DoSleep",
"(",
"OS_Time_t",
"_ticks",
")",
"{",
"OS_Node_t",
"*",
"pos",
";",
"int",
"inserted",
"=",
"0",
";",
"int",
"retval",
";",
"volatile",
"OS_Time_t",
"current_time",
"=",
"0",
";",
"OS_Time_t",
"clock_program_value",
"=",
"0",
";",
"if",
"(",
"_ticks",
"<",
"OS_TimeGetTicks",
"(",
")",
"+",
"TIME_PENALTY",
")",
"{",
"retval",
"=",
"0",
";",
"}",
"else",
"{",
"current",
"->",
"abs_timeout",
"=",
"_ticks",
";",
"current",
"->",
"status",
"|=",
"TS_TIME_BLOCKED",
";",
"if",
"(",
"OS_ListGetNum",
"(",
"&",
"time_list",
")",
"==",
"0",
")",
"OS_ListInsert",
"(",
"&",
"time_list",
",",
"&",
"(",
"current",
"->",
"time_node",
")",
")",
";",
"else",
"{",
"list_for_each",
"(",
"pos",
",",
"&",
"time_list",
")",
"",
"{",
"if",
"(",
"GET_TIME_THREAD",
"(",
"pos",
")",
"->",
"abs_timeout",
">",
"current",
"->",
"abs_timeout",
")",
"{",
"if",
"(",
"pos",
"->",
"prev",
"!=",
"NULL",
")",
"{",
"OS_ListAdd",
"(",
"&",
"time_list",
",",
"&",
"(",
"current",
"->",
"time_node",
")",
",",
"pos",
"->",
"prev",
")",
";",
"}",
"else",
"{",
"OS_ListInsert",
"(",
"&",
"time_list",
",",
"&",
"(",
"current",
"->",
"time_node",
")",
")",
";",
"}",
"inserted",
"=",
"1",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"inserted",
")",
"{",
"OS_ListAppend",
"(",
"&",
"time_list",
",",
"&",
"(",
"current",
"->",
"time_node",
")",
")",
";",
"}",
"}",
"current_time",
"=",
"OS_TimeGetTicks",
"(",
")",
"+",
"TIME_PENALTY",
";",
"clock_program_value",
"=",
"FIRST_TIME_THREAD",
"->",
"abs_timeout",
"-",
"current_time",
";",
"if",
"(",
"clock_program_value",
"<",
"OVERHEAD_CLICKS",
"&&",
"(",
"FIRST_TIME_THREAD",
"->",
"abs_timeout",
">",
"current_time",
")",
")",
"{",
"OS_ProgramClock",
"(",
"(",
"uint32",
")",
"clock_program_value",
")",
";",
"}",
"else",
"if",
"(",
"FIRST_TIME_THREAD",
"->",
"abs_timeout",
"<=",
"current_time",
")",
"{",
"OS_IRQMarkClockEvent",
"(",
")",
";",
"}",
"retval",
"=",
"-1",
";",
"}",
"return",
"retval",
";",
"}"
] | Function: void OS_DoSleep(uint32 _ticks) | [
"Function",
":",
"void",
"OS_DoSleep",
"(",
"uint32",
"_ticks",
")"
] | [
"/* Init the absolute clock */",
"// DEBUG2 (\"Task #%d; until %x %d\\n\", current - task_table, (uint32)(_ticks >> 32), (uint32)_ticks);",
"/* Change the task status */"
] | [
{
"param": "_ticks",
"type": "OS_Time_t"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "_ticks",
"type": "OS_Time_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
722c303dd603fe8d7bad53ade0c16c7f682fa3ba | aitorvs/ercos | kernel/time.c | [
"Apache-2.0"
] | C | OS_ClockInit | void | static void OS_ClockInit(void)
{
DEBUG ("Real Time Clock init...");
/* Register IRQ for the Real Time Clock */
OS_RegisterIRQ(CLOCK_TRAP, OS_ClockISR);
} | /*
* Function: static void OS_ClockInit(void)
*
* This function initializes the system Real Time Clock
*/ |
This function initializes the system Real Time Clock | [
"This",
"function",
"initializes",
"the",
"system",
"Real",
"Time",
"Clock"
] | static void OS_ClockInit(void)
{
DEBUG ("Real Time Clock init...");
OS_RegisterIRQ(CLOCK_TRAP, OS_ClockISR);
} | [
"static",
"void",
"OS_ClockInit",
"(",
"void",
")",
"{",
"DEBUG",
"(",
"\"",
"\"",
")",
";",
"OS_RegisterIRQ",
"(",
"CLOCK_TRAP",
",",
"OS_ClockISR",
")",
";",
"}"
] | Function: static void OS_ClockInit(void) | [
"Function",
":",
"static",
"void",
"OS_ClockInit",
"(",
"void",
")"
] | [
"/* Register IRQ for the Real Time Clock */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
722c303dd603fe8d7bad53ade0c16c7f682fa3ba | aitorvs/ercos | kernel/time.c | [
"Apache-2.0"
] | C | OS_TimerISR | void | static void OS_TimerISR(int level)
{
/* Increment the real time clock counter ticks */
timer_tick_counter += (OS_Time_t)((OS_Time_t)CPU_TIMER_COUNTER + 1);
OS_Time.seconds += seconds_per_timer_tick;
OS_Time.useconds += useconds_per_timer_tick;
_OS_Timeval_normalize(&OS_Time);
/*
* If the one shot timer is not programmed means that it is possible that
* the next thread to be programmed has the abs_timeout greater than the
* timer overflow value. So we must call the OS_ClockBottomISR routine in
* order to try a new one shot programation
*/
if(IS_ONESHOT_TIMER_NOT_PROGRAMMED() &&
OS_ListGetNum(&time_list) != 0)
{
OS_ClockBottomISR();
}
} | /*
* Function: static void OS_ClockISR(int level)
*
* This function implements the Real Time Clock service routine
*/ |
This function implements the Real Time Clock service routine | [
"This",
"function",
"implements",
"the",
"Real",
"Time",
"Clock",
"service",
"routine"
] | static void OS_TimerISR(int level)
{
timer_tick_counter += (OS_Time_t)((OS_Time_t)CPU_TIMER_COUNTER + 1);
OS_Time.seconds += seconds_per_timer_tick;
OS_Time.useconds += useconds_per_timer_tick;
_OS_Timeval_normalize(&OS_Time);
if(IS_ONESHOT_TIMER_NOT_PROGRAMMED() &&
OS_ListGetNum(&time_list) != 0)
{
OS_ClockBottomISR();
}
} | [
"static",
"void",
"OS_TimerISR",
"(",
"int",
"level",
")",
"{",
"timer_tick_counter",
"+=",
"(",
"OS_Time_t",
")",
"(",
"(",
"OS_Time_t",
")",
"CPU_TIMER_COUNTER",
"+",
"1",
")",
";",
"OS_Time",
".",
"seconds",
"+=",
"seconds_per_timer_tick",
";",
"OS_Time",
".",
"useconds",
"+=",
"useconds_per_timer_tick",
";",
"_OS_Timeval_normalize",
"(",
"&",
"OS_Time",
")",
";",
"if",
"(",
"IS_ONESHOT_TIMER_NOT_PROGRAMMED",
"(",
")",
"&&",
"OS_ListGetNum",
"(",
"&",
"time_list",
")",
"!=",
"0",
")",
"{",
"OS_ClockBottomISR",
"(",
")",
";",
"}",
"}"
] | Function: static void OS_ClockISR(int level) | [
"Function",
":",
"static",
"void",
"OS_ClockISR",
"(",
"int",
"level",
")"
] | [
"/* Increment the real time clock counter ticks */",
"/*\n * If the one shot timer is not programmed means that it is possible that \n * the next thread to be programmed has the abs_timeout greater than the\n * timer overflow value. So we must call the OS_ClockBottomISR routine in \n * order to try a new one shot programation\n */"
] | [
{
"param": "level",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "level",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
b7f9293286b951cb52533c938d9d6ce08ba9628d | aitorvs/ercos | kernel/traps.c | [
"Apache-2.0"
] | C | OS_TrapInit | void | void OS_TrapInit(void)
{
unsigned int i;
DEBUG ("Initializing the Trap Table...");
/* Initialize all the interrupt handlers to NULL */
for (i = CPU_TRAP_MIN_NUMBER; i < CPU_TRAP_MAX_NUMBER ; ++i) {
/* No interrupt handler */
interrupt_handler[i].isr = NULL;
/* No previvous interrupt handler */
interrupt_handler[i].old_isr = NULL;
}
/* Mask all interrupts */
OS_MaskAllInterrupts();
} | /*
* Function: void OS_TrapInit(void)
*
* This function initializes the interrupts and traps.
*/ |
This function initializes the interrupts and traps. | [
"This",
"function",
"initializes",
"the",
"interrupts",
"and",
"traps",
"."
] | void OS_TrapInit(void)
{
unsigned int i;
DEBUG ("Initializing the Trap Table...");
for (i = CPU_TRAP_MIN_NUMBER; i < CPU_TRAP_MAX_NUMBER ; ++i) {
interrupt_handler[i].isr = NULL;
interrupt_handler[i].old_isr = NULL;
}
OS_MaskAllInterrupts();
} | [
"void",
"OS_TrapInit",
"(",
"void",
")",
"{",
"unsigned",
"int",
"i",
";",
"DEBUG",
"(",
"\"",
"\"",
")",
";",
"for",
"(",
"i",
"=",
"CPU_TRAP_MIN_NUMBER",
";",
"i",
"<",
"CPU_TRAP_MAX_NUMBER",
";",
"++",
"i",
")",
"{",
"interrupt_handler",
"[",
"i",
"]",
".",
"isr",
"=",
"NULL",
";",
"interrupt_handler",
"[",
"i",
"]",
".",
"old_isr",
"=",
"NULL",
";",
"}",
"OS_MaskAllInterrupts",
"(",
")",
";",
"}"
] | Function: void OS_TrapInit(void) | [
"Function",
":",
"void",
"OS_TrapInit",
"(",
"void",
")"
] | [
"/* Initialize all the interrupt handlers to NULL */",
"/* No interrupt handler */",
"/* No previvous interrupt handler */",
"/* Mask all interrupts */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
80434c574254797aa5bc3b4a9d516d68d2363c37 | aitorvs/ercos | gdb/sparc-stub.c | [
"Apache-2.0"
] | C | hex | int | static int hex (unsigned char ch)
{
if (ch >= 'a' && ch <= 'f')
return ch-'a'+10;
if (ch >= '0' && ch <= '9')
return ch-'0';
if (ch >= 'A' && ch <= 'F')
return ch-'A'+10;
return -1;
} | /* Convert ch from a hex digit to an int */ | Convert ch from a hex digit to an int | [
"Convert",
"ch",
"from",
"a",
"hex",
"digit",
"to",
"an",
"int"
] | static int hex (unsigned char ch)
{
if (ch >= 'a' && ch <= 'f')
return ch-'a'+10;
if (ch >= '0' && ch <= '9')
return ch-'0';
if (ch >= 'A' && ch <= 'F')
return ch-'A'+10;
return -1;
} | [
"static",
"int",
"hex",
"(",
"unsigned",
"char",
"ch",
")",
"{",
"if",
"(",
"ch",
">=",
"'",
"'",
"&&",
"ch",
"<=",
"'",
"'",
")",
"return",
"ch",
"-",
"'",
"'",
"+",
"10",
";",
"if",
"(",
"ch",
">=",
"'",
"'",
"&&",
"ch",
"<=",
"'",
"'",
")",
"return",
"ch",
"-",
"'",
"'",
";",
"if",
"(",
"ch",
">=",
"'",
"'",
"&&",
"ch",
"<=",
"'",
"'",
")",
"return",
"ch",
"-",
"'",
"'",
"+",
"10",
";",
"return",
"-1",
";",
"}"
] | Convert ch from a hex digit to an int | [
"Convert",
"ch",
"from",
"a",
"hex",
"digit",
"to",
"an",
"int"
] | [] | [
{
"param": "ch",
"type": "unsigned char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ch",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80434c574254797aa5bc3b4a9d516d68d2363c37 | aitorvs/ercos | gdb/sparc-stub.c | [
"Apache-2.0"
] | C | putpacket | void | static void putpacket (unsigned char *buffer)
{
unsigned char checksum;
int count;
unsigned char ch;
/* $<packet info>#<checksum>. */
do
{
putDebugChar('$');
checksum = 0;
count = 0;
while (ch = buffer[count])
{
putDebugChar(ch);
checksum += ch;
count += 1;
}
putDebugChar('#');
putDebugChar(hexchars[checksum >> 4]);
putDebugChar(hexchars[checksum & 0xf]);
}
while (getDebugChar() != '+');
} | /* send the packet in buffer. */ | send the packet in buffer. | [
"send",
"the",
"packet",
"in",
"buffer",
"."
] | static void putpacket (unsigned char *buffer)
{
unsigned char checksum;
int count;
unsigned char ch;
do
{
putDebugChar('$');
checksum = 0;
count = 0;
while (ch = buffer[count])
{
putDebugChar(ch);
checksum += ch;
count += 1;
}
putDebugChar('#');
putDebugChar(hexchars[checksum >> 4]);
putDebugChar(hexchars[checksum & 0xf]);
}
while (getDebugChar() != '+');
} | [
"static",
"void",
"putpacket",
"(",
"unsigned",
"char",
"*",
"buffer",
")",
"{",
"unsigned",
"char",
"checksum",
";",
"int",
"count",
";",
"unsigned",
"char",
"ch",
";",
"do",
"{",
"putDebugChar",
"(",
"'",
"'",
")",
";",
"checksum",
"=",
"0",
";",
"count",
"=",
"0",
";",
"while",
"(",
"ch",
"=",
"buffer",
"[",
"count",
"]",
")",
"{",
"putDebugChar",
"(",
"ch",
")",
";",
"checksum",
"+=",
"ch",
";",
"count",
"+=",
"1",
";",
"}",
"putDebugChar",
"(",
"'",
"'",
")",
";",
"putDebugChar",
"(",
"hexchars",
"[",
"checksum",
">>",
"4",
"]",
")",
";",
"putDebugChar",
"(",
"hexchars",
"[",
"checksum",
"&",
"0xf",
"]",
")",
";",
"}",
"while",
"(",
"getDebugChar",
"(",
")",
"!=",
"'",
"'",
")",
";",
"}"
] | send the packet in buffer. | [
"send",
"the",
"packet",
"in",
"buffer",
"."
] | [
"/* $<packet info>#<checksum>. */"
] | [
{
"param": "buffer",
"type": "unsigned char"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buffer",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80434c574254797aa5bc3b4a9d516d68d2363c37 | aitorvs/ercos | gdb/sparc-stub.c | [
"Apache-2.0"
] | C | mem2hex | null | static unsigned char *
mem2hex (unsigned char *mem, unsigned char *buf, int count, int may_fault)
{
unsigned char ch;
set_mem_fault_trap(may_fault);
while (count-- > 0)
{
ch = *mem++;
if (mem_err)
return 0;
*buf++ = hexchars[ch >> 4];
*buf++ = hexchars[ch & 0xf];
}
*buf = 0;
set_mem_fault_trap(0);
return buf;
} | /* Convert the memory pointed to by mem into hex, placing result in buf.
* Return a pointer to the last char put in buf (null), in case of mem fault,
* return 0.
* If MAY_FAULT is non-zero, then we will handle memory faults by returning
* a 0, else treat a fault like any other fault in the stub.
*/ | Convert the memory pointed to by mem into hex, placing result in buf.
Return a pointer to the last char put in buf (null), in case of mem fault,
return 0.
If MAY_FAULT is non-zero, then we will handle memory faults by returning
a 0, else treat a fault like any other fault in the stub. | [
"Convert",
"the",
"memory",
"pointed",
"to",
"by",
"mem",
"into",
"hex",
"placing",
"result",
"in",
"buf",
".",
"Return",
"a",
"pointer",
"to",
"the",
"last",
"char",
"put",
"in",
"buf",
"(",
"null",
")",
"in",
"case",
"of",
"mem",
"fault",
"return",
"0",
".",
"If",
"MAY_FAULT",
"is",
"non",
"-",
"zero",
"then",
"we",
"will",
"handle",
"memory",
"faults",
"by",
"returning",
"a",
"0",
"else",
"treat",
"a",
"fault",
"like",
"any",
"other",
"fault",
"in",
"the",
"stub",
"."
] | static unsigned char *
mem2hex (unsigned char *mem, unsigned char *buf, int count, int may_fault)
{
unsigned char ch;
set_mem_fault_trap(may_fault);
while (count-- > 0)
{
ch = *mem++;
if (mem_err)
return 0;
*buf++ = hexchars[ch >> 4];
*buf++ = hexchars[ch & 0xf];
}
*buf = 0;
set_mem_fault_trap(0);
return buf;
} | [
"static",
"unsigned",
"char",
"*",
"mem2hex",
"(",
"unsigned",
"char",
"*",
"mem",
",",
"unsigned",
"char",
"*",
"buf",
",",
"int",
"count",
",",
"int",
"may_fault",
")",
"{",
"unsigned",
"char",
"ch",
";",
"set_mem_fault_trap",
"(",
"may_fault",
")",
";",
"while",
"(",
"count",
"--",
">",
"0",
")",
"{",
"ch",
"=",
"*",
"mem",
"++",
";",
"if",
"(",
"mem_err",
")",
"return",
"0",
";",
"*",
"buf",
"++",
"=",
"hexchars",
"[",
"ch",
">>",
"4",
"]",
";",
"*",
"buf",
"++",
"=",
"hexchars",
"[",
"ch",
"&",
"0xf",
"]",
";",
"}",
"*",
"buf",
"=",
"0",
";",
"set_mem_fault_trap",
"(",
"0",
")",
";",
"return",
"buf",
";",
"}"
] | Convert the memory pointed to by mem into hex, placing result in buf. | [
"Convert",
"the",
"memory",
"pointed",
"to",
"by",
"mem",
"into",
"hex",
"placing",
"result",
"in",
"buf",
"."
] | [] | [
{
"param": "mem",
"type": "unsigned char"
},
{
"param": "buf",
"type": "unsigned char"
},
{
"param": "count",
"type": "int"
},
{
"param": "may_fault",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "mem",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "buf",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "count",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "may_fault",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80434c574254797aa5bc3b4a9d516d68d2363c37 | aitorvs/ercos | gdb/sparc-stub.c | [
"Apache-2.0"
] | C | hex2mem | char | static char *
hex2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault)
{
int i;
unsigned char ch;
set_mem_fault_trap(may_fault);
for (i=0; i<count; i++)
{
ch = hex(*buf++) << 4;
ch |= hex(*buf++);
*mem++ = ch;
if (mem_err)
return 0;
}
set_mem_fault_trap(0);
return mem;
} | /* convert the hex array pointed to by buf into binary to be placed in mem
* return a pointer to the character AFTER the last byte written */ | convert the hex array pointed to by buf into binary to be placed in mem
return a pointer to the character AFTER the last byte written | [
"convert",
"the",
"hex",
"array",
"pointed",
"to",
"by",
"buf",
"into",
"binary",
"to",
"be",
"placed",
"in",
"mem",
"return",
"a",
"pointer",
"to",
"the",
"character",
"AFTER",
"the",
"last",
"byte",
"written"
] | static char *
hex2mem (unsigned char *buf, unsigned char *mem, int count, int may_fault)
{
int i;
unsigned char ch;
set_mem_fault_trap(may_fault);
for (i=0; i<count; i++)
{
ch = hex(*buf++) << 4;
ch |= hex(*buf++);
*mem++ = ch;
if (mem_err)
return 0;
}
set_mem_fault_trap(0);
return mem;
} | [
"static",
"char",
"*",
"hex2mem",
"(",
"unsigned",
"char",
"*",
"buf",
",",
"unsigned",
"char",
"*",
"mem",
",",
"int",
"count",
",",
"int",
"may_fault",
")",
"{",
"int",
"i",
";",
"unsigned",
"char",
"ch",
";",
"set_mem_fault_trap",
"(",
"may_fault",
")",
";",
"for",
"(",
"i",
"=",
"0",
";",
"i",
"<",
"count",
";",
"i",
"++",
")",
"{",
"ch",
"=",
"hex",
"(",
"*",
"buf",
"++",
")",
"<<",
"4",
";",
"ch",
"|=",
"hex",
"(",
"*",
"buf",
"++",
")",
";",
"*",
"mem",
"++",
"=",
"ch",
";",
"if",
"(",
"mem_err",
")",
"return",
"0",
";",
"}",
"set_mem_fault_trap",
"(",
"0",
")",
";",
"return",
"mem",
";",
"}"
] | convert the hex array pointed to by buf into binary to be placed in mem
return a pointer to the character AFTER the last byte written | [
"convert",
"the",
"hex",
"array",
"pointed",
"to",
"by",
"buf",
"into",
"binary",
"to",
"be",
"placed",
"in",
"mem",
"return",
"a",
"pointer",
"to",
"the",
"character",
"AFTER",
"the",
"last",
"byte",
"written"
] | [] | [
{
"param": "buf",
"type": "unsigned char"
},
{
"param": "mem",
"type": "unsigned char"
},
{
"param": "count",
"type": "int"
},
{
"param": "may_fault",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "buf",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "mem",
"type": "unsigned char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "count",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "may_fault",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80434c574254797aa5bc3b4a9d516d68d2363c37 | aitorvs/ercos | gdb/sparc-stub.c | [
"Apache-2.0"
] | C | computeSignal | int | static int computeSignal (int tt)
{
struct hard_trap_info *ht;
for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
if (ht->tt == tt)
return ht->signo;
return SIGHUP; /* default for things we don't know about */
} | /* Convert the SPARC hardware trap type code to a unix signal number. */ | Convert the SPARC hardware trap type code to a unix signal number. | [
"Convert",
"the",
"SPARC",
"hardware",
"trap",
"type",
"code",
"to",
"a",
"unix",
"signal",
"number",
"."
] | static int computeSignal (int tt)
{
struct hard_trap_info *ht;
for (ht = hard_trap_info; ht->tt && ht->signo; ht++)
if (ht->tt == tt)
return ht->signo;
return SIGHUP;
} | [
"static",
"int",
"computeSignal",
"(",
"int",
"tt",
")",
"{",
"struct",
"hard_trap_info",
"*",
"ht",
";",
"for",
"(",
"ht",
"=",
"hard_trap_info",
";",
"ht",
"->",
"tt",
"&&",
"ht",
"->",
"signo",
";",
"ht",
"++",
")",
"if",
"(",
"ht",
"->",
"tt",
"==",
"tt",
")",
"return",
"ht",
"->",
"signo",
";",
"return",
"SIGHUP",
";",
"}"
] | Convert the SPARC hardware trap type code to a unix signal number. | [
"Convert",
"the",
"SPARC",
"hardware",
"trap",
"type",
"code",
"to",
"a",
"unix",
"signal",
"number",
"."
] | [
"/* default for things we don't know about */"
] | [
{
"param": "tt",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "tt",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
80434c574254797aa5bc3b4a9d516d68d2363c37 | aitorvs/ercos | gdb/sparc-stub.c | [
"Apache-2.0"
] | C | hexToInt | int | static int hexToInt(char **ptr, int *intValue)
{
int numChars = 0;
int hexValue;
*intValue = 0;
while (**ptr)
{
hexValue = hex(**ptr);
if (hexValue < 0)
break;
*intValue = (*intValue << 4) | hexValue;
numChars ++;
(*ptr)++;
}
return (numChars);
} | /*
* While we find nice hex chars, build an int.
* Return number of chars processed.
*/ | While we find nice hex chars, build an int.
Return number of chars processed. | [
"While",
"we",
"find",
"nice",
"hex",
"chars",
"build",
"an",
"int",
".",
"Return",
"number",
"of",
"chars",
"processed",
"."
] | static int hexToInt(char **ptr, int *intValue)
{
int numChars = 0;
int hexValue;
*intValue = 0;
while (**ptr)
{
hexValue = hex(**ptr);
if (hexValue < 0)
break;
*intValue = (*intValue << 4) | hexValue;
numChars ++;
(*ptr)++;
}
return (numChars);
} | [
"static",
"int",
"hexToInt",
"(",
"char",
"*",
"*",
"ptr",
",",
"int",
"*",
"intValue",
")",
"{",
"int",
"numChars",
"=",
"0",
";",
"int",
"hexValue",
";",
"*",
"intValue",
"=",
"0",
";",
"while",
"(",
"*",
"*",
"ptr",
")",
"{",
"hexValue",
"=",
"hex",
"(",
"*",
"*",
"ptr",
")",
";",
"if",
"(",
"hexValue",
"<",
"0",
")",
"break",
";",
"*",
"intValue",
"=",
"(",
"*",
"intValue",
"<<",
"4",
")",
"|",
"hexValue",
";",
"numChars",
"++",
";",
"(",
"*",
"ptr",
")",
"++",
";",
"}",
"return",
"(",
"numChars",
")",
";",
"}"
] | While we find nice hex chars, build an int. | [
"While",
"we",
"find",
"nice",
"hex",
"chars",
"build",
"an",
"int",
"."
] | [] | [
{
"param": "ptr",
"type": "char"
},
{
"param": "intValue",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "ptr",
"type": "char",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "intValue",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
c773122a5b1d5cef0886c692f577dc4fa17ee68a | aitorvs/ercos | arch/SPARC/common/cpu.c | [
"Apache-2.0"
] | C | CPU_ContextInit | void | void CPU_ContextInit(CPU_context_t *the_context,
uint8 *stack_base,
uint32 size,
uint32 new_level,
void *entry_point)
{
uint32 stack_high; /* highest "stack aligned" address */
uint32 the_size;
uint32 tmp_psr;
/*
* On CPUs with stacks which grow down (i.e. SPARC), we build the stack
* based on the stack_high address.
*/
stack_high = (uint32)((stack_base) + size);
stack_high &= ~(CPU_STACK_ALIGNMENT - 1);
the_size = size & ~(CPU_STACK_ALIGNMENT - 1);
/*
* See the README in this directory for a diagram of the stack.
*/
// the_context->i6_fp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE;
// the_context->o6_sp = the_context->i6_fp - CPU_MINIMUM_STACK_FRAME_SIZE;
the_context->i6_fp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE;
the_context->l1 = ((uint32) entry_point);
the_context->l2 = ((uint32) entry_point) + 4;
/*
* Build the PSR for the task. Most everything can be 0 and the
* CWP is corrected during the context switch.
*
* The EF bit determines if the floating point unit is available.
* The FPU is ONLY enabled if the context is associated with an FP task
* and this SPARC model has an FPU.
*/
sparc_get_psr( tmp_psr );
tmp_psr &= ~PSR_PIL;
tmp_psr |= (new_level << 8) & PSR_PIL;
tmp_psr &= ~PSR_EF; /* disabled by default */
the_context->psr = tmp_psr;
} | /*
* Function: void CPU_ContextInit(OS_context_t *the_context,
uint32 *stack_base,
uint32 size,
uint32 new_level,
void *entry_point)
*
* This function initializes the thread context
*/ |
This function initializes the thread context | [
"This",
"function",
"initializes",
"the",
"thread",
"context"
] | void CPU_ContextInit(CPU_context_t *the_context,
uint8 *stack_base,
uint32 size,
uint32 new_level,
void *entry_point)
{
uint32 stack_high;
uint32 the_size;
uint32 tmp_psr;
stack_high = (uint32)((stack_base) + size);
stack_high &= ~(CPU_STACK_ALIGNMENT - 1);
the_size = size & ~(CPU_STACK_ALIGNMENT - 1);
the_context->i6_fp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE;
the_context->l1 = ((uint32) entry_point);
the_context->l2 = ((uint32) entry_point) + 4;
sparc_get_psr( tmp_psr );
tmp_psr &= ~PSR_PIL;
tmp_psr |= (new_level << 8) & PSR_PIL;
tmp_psr &= ~PSR_EF;
the_context->psr = tmp_psr;
} | [
"void",
"CPU_ContextInit",
"(",
"CPU_context_t",
"*",
"the_context",
",",
"uint8",
"*",
"stack_base",
",",
"uint32",
"size",
",",
"uint32",
"new_level",
",",
"void",
"*",
"entry_point",
")",
"{",
"uint32",
"stack_high",
";",
"uint32",
"the_size",
";",
"uint32",
"tmp_psr",
";",
"stack_high",
"=",
"(",
"uint32",
")",
"(",
"(",
"stack_base",
")",
"+",
"size",
")",
";",
"stack_high",
"&=",
"~",
"(",
"CPU_STACK_ALIGNMENT",
"-",
"1",
")",
";",
"the_size",
"=",
"size",
"&",
"~",
"(",
"CPU_STACK_ALIGNMENT",
"-",
"1",
")",
";",
"the_context",
"->",
"i6_fp",
"=",
"stack_high",
"-",
"CPU_MINIMUM_STACK_FRAME_SIZE",
";",
"the_context",
"->",
"l1",
"=",
"(",
"(",
"uint32",
")",
"entry_point",
")",
";",
"the_context",
"->",
"l2",
"=",
"(",
"(",
"uint32",
")",
"entry_point",
")",
"+",
"4",
";",
"sparc_get_psr",
"(",
"tmp_psr",
")",
";",
"tmp_psr",
"&=",
"~",
"PSR_PIL",
";",
"tmp_psr",
"|=",
"(",
"new_level",
"<<",
"8",
")",
"&",
"PSR_PIL",
";",
"tmp_psr",
"&=",
"~",
"PSR_EF",
";",
"the_context",
"->",
"psr",
"=",
"tmp_psr",
";",
"}"
] | Function: void CPU_ContextInit(OS_context_t *the_context,
uint32 *stack_base,
uint32 size,
uint32 new_level,
void *entry_point) | [
"Function",
":",
"void",
"CPU_ContextInit",
"(",
"OS_context_t",
"*",
"the_context",
"uint32",
"*",
"stack_base",
"uint32",
"size",
"uint32",
"new_level",
"void",
"*",
"entry_point",
")"
] | [
"/* highest \"stack aligned\" address */",
"/*\n * On CPUs with stacks which grow down (i.e. SPARC), we build the stack\n * based on the stack_high address. \n */",
"/*\n * See the README in this directory for a diagram of the stack.\n */",
"// the_context->i6_fp = stack_high - CPU_MINIMUM_STACK_FRAME_SIZE;",
"// the_context->o6_sp = the_context->i6_fp - CPU_MINIMUM_STACK_FRAME_SIZE;",
"/*\n * Build the PSR for the task. Most everything can be 0 and the\n * CWP is corrected during the context switch.\n *\n * The EF bit determines if the floating point unit is available.\n * The FPU is ONLY enabled if the context is associated with an FP task\n * and this SPARC model has an FPU.\n */",
"/* disabled by default */"
] | [
{
"param": "the_context",
"type": "CPU_context_t"
},
{
"param": "stack_base",
"type": "uint8"
},
{
"param": "size",
"type": "uint32"
},
{
"param": "new_level",
"type": "uint32"
},
{
"param": "entry_point",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "the_context",
"type": "CPU_context_t",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "stack_base",
"type": "uint8",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "size",
"type": "uint32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "new_level",
"type": "uint32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "entry_point",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
3d651c36370a1b095914e07137dcb189ad0aca2f | aitorvs/ercos | kernel/cppinit.c | [
"Apache-2.0"
] | C | OS_CPPInit | void | void OS_CPPInit(void)
{
unsigned int i = 0;
while(__ctors_GLOBAL__[i] != 0)
{
/* DEBUG ("Calling constructor at %p", * (void **) (__ctors_GLOBAL__ + i)); */
__ctors_GLOBAL__[i++] ();
}
} | /**
* This routine is in charge of call all the C++ constructors in order to
* execute C++ code.
*/ | This routine is in charge of call all the C++ constructors in order to
execute C++ code. | [
"This",
"routine",
"is",
"in",
"charge",
"of",
"call",
"all",
"the",
"C",
"++",
"constructors",
"in",
"order",
"to",
"execute",
"C",
"++",
"code",
"."
] | void OS_CPPInit(void)
{
unsigned int i = 0;
while(__ctors_GLOBAL__[i] != 0)
{
__ctors_GLOBAL__[i++] ();
}
} | [
"void",
"OS_CPPInit",
"(",
"void",
")",
"{",
"unsigned",
"int",
"i",
"=",
"0",
";",
"while",
"(",
"__ctors_GLOBAL__",
"[",
"i",
"]",
"!=",
"0",
")",
"{",
"__ctors_GLOBAL__",
"[",
"i",
"++",
"]",
"(",
")",
";",
"}",
"}"
] | This routine is in charge of call all the C++ constructors in order to
execute C++ code. | [
"This",
"routine",
"is",
"in",
"charge",
"of",
"call",
"all",
"the",
"C",
"++",
"constructors",
"in",
"order",
"to",
"execute",
"C",
"++",
"code",
"."
] | [
"/* DEBUG (\"Calling constructor at %p\", * (void **) (__ctors_GLOBAL__ + i)); */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6734a36a68de7106379931750bb7537f98e3a87d | aitorvs/ercos | arch/SPARC/LEON2/timer.c | [
"Apache-2.0"
] | C | CPU_TimerInit | void | void CPU_TimerInit(void)
{
int value;
/*
* SYSCLOCK MHz -> Timeout = GPCC * (GPCS+1) / SYSCLOCK
*/
REGMAP.timer_1_counter = LEON2_TIMER_COUNTER; /* RTCC */
REGMAP.timer_1_reload = LEON2_TIMER_COUNTER;
REGMAP.prescaler_counter = KCONFIG_CLOCK_SPEED - 1; /* RTCS */
REGMAP.prescaler_reload = KCONFIG_CLOCK_SPEED - 1; /* RTCS */
/* Periodic configuration */
LEON2_Set_GP_Timer_Control(LEON2_TIMER_CONTROL_RELOAD |
LEON2_TIMER_CONTROL_LOAD |
LEON2_TIMER_CONTROL_ENABLE);
CPU_EnableInterrupt(TRAP_GP_TIMER);
} | /*
* Function: void CPU_TimerInit(uint32 _ticks)
*
* This function configures the General Purpose Timer tick resolution.
* This is a ONE SHOT timer.
*/ |
This function configures the General Purpose Timer tick resolution.
This is a ONE SHOT timer. | [
"This",
"function",
"configures",
"the",
"General",
"Purpose",
"Timer",
"tick",
"resolution",
".",
"This",
"is",
"a",
"ONE",
"SHOT",
"timer",
"."
] | void CPU_TimerInit(void)
{
int value;
REGMAP.timer_1_counter = LEON2_TIMER_COUNTER;
REGMAP.timer_1_reload = LEON2_TIMER_COUNTER;
REGMAP.prescaler_counter = KCONFIG_CLOCK_SPEED - 1;
REGMAP.prescaler_reload = KCONFIG_CLOCK_SPEED - 1;
LEON2_Set_GP_Timer_Control(LEON2_TIMER_CONTROL_RELOAD |
LEON2_TIMER_CONTROL_LOAD |
LEON2_TIMER_CONTROL_ENABLE);
CPU_EnableInterrupt(TRAP_GP_TIMER);
} | [
"void",
"CPU_TimerInit",
"(",
"void",
")",
"{",
"int",
"value",
";",
"REGMAP",
".",
"timer_1_counter",
"=",
"LEON2_TIMER_COUNTER",
";",
"REGMAP",
".",
"timer_1_reload",
"=",
"LEON2_TIMER_COUNTER",
";",
"REGMAP",
".",
"prescaler_counter",
"=",
"KCONFIG_CLOCK_SPEED",
"-",
"1",
";",
"REGMAP",
".",
"prescaler_reload",
"=",
"KCONFIG_CLOCK_SPEED",
"-",
"1",
";",
"LEON2_Set_GP_Timer_Control",
"(",
"LEON2_TIMER_CONTROL_RELOAD",
"|",
"LEON2_TIMER_CONTROL_LOAD",
"|",
"LEON2_TIMER_CONTROL_ENABLE",
")",
";",
"CPU_EnableInterrupt",
"(",
"TRAP_GP_TIMER",
")",
";",
"}"
] | Function: void CPU_TimerInit(uint32 _ticks) | [
"Function",
":",
"void",
"CPU_TimerInit",
"(",
"uint32",
"_ticks",
")"
] | [
"/* \n * SYSCLOCK MHz -> Timeout = GPCC * (GPCS+1) / SYSCLOCK \n */",
"/* RTCC */",
"/* RTCS */",
"/* RTCS */",
"/* Periodic configuration */"
] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
6734a36a68de7106379931750bb7537f98e3a87d | aitorvs/ercos | arch/SPARC/LEON2/timer.c | [
"Apache-2.0"
] | C | CPU_ClockInit | void | void CPU_ClockInit(uint32 _ticks)
{
REGMAP.timer_2_reload = _ticks;
LEON2_Set_RT_Timer_Control(LEON2_TIMER_CONTROL_LOAD |
LEON2_TIMER_CONTROL_ENABLE);
CPU_EnableInterrupt(TRAP_REAL_TIME_CLOCK);
} | /*
* Function: void CPU_ClockInit(void)
*
* This function configures the Real Time Clock interrupt period.
*/ |
This function configures the Real Time Clock interrupt period. | [
"This",
"function",
"configures",
"the",
"Real",
"Time",
"Clock",
"interrupt",
"period",
"."
] | void CPU_ClockInit(uint32 _ticks)
{
REGMAP.timer_2_reload = _ticks;
LEON2_Set_RT_Timer_Control(LEON2_TIMER_CONTROL_LOAD |
LEON2_TIMER_CONTROL_ENABLE);
CPU_EnableInterrupt(TRAP_REAL_TIME_CLOCK);
} | [
"void",
"CPU_ClockInit",
"(",
"uint32",
"_ticks",
")",
"{",
"REGMAP",
".",
"timer_2_reload",
"=",
"_ticks",
";",
"LEON2_Set_RT_Timer_Control",
"(",
"LEON2_TIMER_CONTROL_LOAD",
"|",
"LEON2_TIMER_CONTROL_ENABLE",
")",
";",
"CPU_EnableInterrupt",
"(",
"TRAP_REAL_TIME_CLOCK",
")",
";",
"}"
] | Function: void CPU_ClockInit(void) | [
"Function",
":",
"void",
"CPU_ClockInit",
"(",
"void",
")"
] | [] | [
{
"param": "_ticks",
"type": "uint32"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "_ticks",
"type": "uint32",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
ced8cde56d154790a5b401f8992cec98a3793f7c | JeraKrs/linear-algebra-notes | src/High Performance Computing/An Introduction to High Performance Computing/Assignment01/src/gaussian/jacobi.c | [
"Apache-2.0"
] | C | run | int | int run(double *A, double *b, double *x) {
double *d = (double *)malloc(N*(N+1)*sizeof(double));
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++)
d[row * N + row + col] = A[row * N + col];
d[row * (N + 1) + N] = b[row];
}
gauss_elimination(d, N);
for (int row = 0; row < N; row++)
x[row] = d[row * (N + 1) + row];
return 0;
} | // Run the Jacobi solver
// Returns the number of iterations performed | Run the Jacobi solver
Returns the number of iterations performed | [
"Run",
"the",
"Jacobi",
"solver",
"Returns",
"the",
"number",
"of",
"iterations",
"performed"
] | int run(double *A, double *b, double *x) {
double *d = (double *)malloc(N*(N+1)*sizeof(double));
for (int row = 0; row < N; row++) {
for (int col = 0; col < N; col++)
d[row * N + row + col] = A[row * N + col];
d[row * (N + 1) + N] = b[row];
}
gauss_elimination(d, N);
for (int row = 0; row < N; row++)
x[row] = d[row * (N + 1) + row];
return 0;
} | [
"int",
"run",
"(",
"double",
"*",
"A",
",",
"double",
"*",
"b",
",",
"double",
"*",
"x",
")",
"{",
"double",
"*",
"d",
"=",
"(",
"double",
"*",
")",
"malloc",
"(",
"N",
"*",
"(",
"N",
"+",
"1",
")",
"*",
"sizeof",
"(",
"double",
")",
")",
";",
"for",
"(",
"int",
"row",
"=",
"0",
";",
"row",
"<",
"N",
";",
"row",
"++",
")",
"{",
"for",
"(",
"int",
"col",
"=",
"0",
";",
"col",
"<",
"N",
";",
"col",
"++",
")",
"d",
"[",
"row",
"*",
"N",
"+",
"row",
"+",
"col",
"]",
"=",
"A",
"[",
"row",
"*",
"N",
"+",
"col",
"]",
";",
"d",
"[",
"row",
"*",
"(",
"N",
"+",
"1",
")",
"+",
"N",
"]",
"=",
"b",
"[",
"row",
"]",
";",
"}",
"gauss_elimination",
"(",
"d",
",",
"N",
")",
";",
"for",
"(",
"int",
"row",
"=",
"0",
";",
"row",
"<",
"N",
";",
"row",
"++",
")",
"x",
"[",
"row",
"]",
"=",
"d",
"[",
"row",
"*",
"(",
"N",
"+",
"1",
")",
"+",
"row",
"]",
";",
"return",
"0",
";",
"}"
] | Run the Jacobi solver
Returns the number of iterations performed | [
"Run",
"the",
"Jacobi",
"solver",
"Returns",
"the",
"number",
"of",
"iterations",
"performed"
] | [] | [
{
"param": "A",
"type": "double"
},
{
"param": "b",
"type": "double"
},
{
"param": "x",
"type": "double"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "A",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "b",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "x",
"type": "double",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
7d953c0b9e55aca4af9148ab60dbf289af9d17ae | JeraKrs/linear-algebra-notes | src/Server Software/Assignment01/src/version01.c | [
"Apache-2.0"
] | C | grab | int | int grab(int studentID, int* markerIDs) {
int num_grabbed = 0, markerID = 0;
while ((num_grabbed < parameters.K) && (markerID < parameters.M)) {
if (markers[markerID].is_grabbed == 0) {
/* Modify the status of marker */
markerIDs[num_grabbed] = markerID;
markers[markerID].is_grabbed = 1;
markers[markerID].studentID = studentID;
num_grabbed = num_grabbed + 1;
}
markerID = markerID + 1;
}
idle_marker = idle_marker - parameters.K;
if (idle_marker < 0) {
fprintf(stderr, "grab(): The number of idle marker "
"is less than zero after grabbed.\n");
return 1;
}
if (num_grabbed != parameters.K) {
fprintf(stderr, "grab(): The number of idle marker "
"is less than %d.\n", parameters.K);
return 2;
}
return 0;
} | /*
* grab(): grab markers
* return 0 means success, else fail
*/ | grab markers
return 0 means success, else fail | [
"grab",
"markers",
"return",
"0",
"means",
"success",
"else",
"fail"
] | int grab(int studentID, int* markerIDs) {
int num_grabbed = 0, markerID = 0;
while ((num_grabbed < parameters.K) && (markerID < parameters.M)) {
if (markers[markerID].is_grabbed == 0) {
markerIDs[num_grabbed] = markerID;
markers[markerID].is_grabbed = 1;
markers[markerID].studentID = studentID;
num_grabbed = num_grabbed + 1;
}
markerID = markerID + 1;
}
idle_marker = idle_marker - parameters.K;
if (idle_marker < 0) {
fprintf(stderr, "grab(): The number of idle marker "
"is less than zero after grabbed.\n");
return 1;
}
if (num_grabbed != parameters.K) {
fprintf(stderr, "grab(): The number of idle marker "
"is less than %d.\n", parameters.K);
return 2;
}
return 0;
} | [
"int",
"grab",
"(",
"int",
"studentID",
",",
"int",
"*",
"markerIDs",
")",
"{",
"int",
"num_grabbed",
"=",
"0",
",",
"markerID",
"=",
"0",
";",
"while",
"(",
"(",
"num_grabbed",
"<",
"parameters",
".",
"K",
")",
"&&",
"(",
"markerID",
"<",
"parameters",
".",
"M",
")",
")",
"{",
"if",
"(",
"markers",
"[",
"markerID",
"]",
".",
"is_grabbed",
"==",
"0",
")",
"{",
"markerIDs",
"[",
"num_grabbed",
"]",
"=",
"markerID",
";",
"markers",
"[",
"markerID",
"]",
".",
"is_grabbed",
"=",
"1",
";",
"markers",
"[",
"markerID",
"]",
".",
"studentID",
"=",
"studentID",
";",
"num_grabbed",
"=",
"num_grabbed",
"+",
"1",
";",
"}",
"markerID",
"=",
"markerID",
"+",
"1",
";",
"}",
"idle_marker",
"=",
"idle_marker",
"-",
"parameters",
".",
"K",
";",
"if",
"(",
"idle_marker",
"<",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
")",
";",
"return",
"1",
";",
"}",
"if",
"(",
"num_grabbed",
"!=",
"parameters",
".",
"K",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"parameters",
".",
"K",
")",
";",
"return",
"2",
";",
"}",
"return",
"0",
";",
"}"
] | grab(): grab markers
return 0 means success, else fail | [
"grab",
"()",
":",
"grab",
"markers",
"return",
"0",
"means",
"success",
"else",
"fail"
] | [
"/* Modify the status of marker */"
] | [
{
"param": "studentID",
"type": "int"
},
{
"param": "markerIDs",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "studentID",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "markerIDs",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
7d953c0b9e55aca4af9148ab60dbf289af9d17ae | JeraKrs/linear-algebra-notes | src/Server Software/Assignment01/src/version01.c | [
"Apache-2.0"
] | C | release | int | int release(int markerID, int job) {
if (markerID < 0 || markerID >= parameters.M) {
fprintf(stderr, "release(): The markerID=%d is illegal.\n", markerID);
return 2;
}
markers[markerID].job = job;
idle_marker = idle_marker + 1;
if (idle_marker > parameters.M) {
fprintf(stderr, "release(): The number of idle marker is "
"bigger than %d after release.\n", parameters.M);
return 1;
}
return 0;
} | /*
* release(): release marker
* return 0 means success, else fail
*/ | release marker
return 0 means success, else fail | [
"release",
"marker",
"return",
"0",
"means",
"success",
"else",
"fail"
] | int release(int markerID, int job) {
if (markerID < 0 || markerID >= parameters.M) {
fprintf(stderr, "release(): The markerID=%d is illegal.\n", markerID);
return 2;
}
markers[markerID].job = job;
idle_marker = idle_marker + 1;
if (idle_marker > parameters.M) {
fprintf(stderr, "release(): The number of idle marker is "
"bigger than %d after release.\n", parameters.M);
return 1;
}
return 0;
} | [
"int",
"release",
"(",
"int",
"markerID",
",",
"int",
"job",
")",
"{",
"if",
"(",
"markerID",
"<",
"0",
"||",
"markerID",
">=",
"parameters",
".",
"M",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\n",
"\"",
",",
"markerID",
")",
";",
"return",
"2",
";",
"}",
"markers",
"[",
"markerID",
"]",
".",
"job",
"=",
"job",
";",
"idle_marker",
"=",
"idle_marker",
"+",
"1",
";",
"if",
"(",
"idle_marker",
">",
"parameters",
".",
"M",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"parameters",
".",
"M",
")",
";",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | release(): release marker
return 0 means success, else fail | [
"release",
"()",
":",
"release",
"marker",
"return",
"0",
"means",
"success",
"else",
"fail"
] | [] | [
{
"param": "markerID",
"type": "int"
},
{
"param": "job",
"type": "int"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "markerID",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
},
{
"identifier": "job",
"type": "int",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
7d953c0b9e55aca4af9148ab60dbf289af9d17ae | JeraKrs/linear-algebra-notes | src/Server Software/Assignment01/src/version01.c | [
"Apache-2.0"
] | C | timenow | int | int timenow() {
struct timeval now;
gettimeofday(&now, NULL);
return (now.tv_sec - starttime.tv_sec) * 100 + (now.tv_usec - starttime.tv_usec) / 10000;
} | /*
* timenow(): returns current simulated time in "minutes" (cs).
* Assumes that starttime has been set already.
* This function is safe to call in the student and marker threads as
* starttime is set in the run() function.
*/ | returns current simulated time in "minutes" (cs).
Assumes that starttime has been set already.
This function is safe to call in the student and marker threads as
starttime is set in the run() function. | [
"returns",
"current",
"simulated",
"time",
"in",
"\"",
"minutes",
"\"",
"(",
"cs",
")",
".",
"Assumes",
"that",
"starttime",
"has",
"been",
"set",
"already",
".",
"This",
"function",
"is",
"safe",
"to",
"call",
"in",
"the",
"student",
"and",
"marker",
"threads",
"as",
"starttime",
"is",
"set",
"in",
"the",
"run",
"()",
"function",
"."
] | int timenow() {
struct timeval now;
gettimeofday(&now, NULL);
return (now.tv_sec - starttime.tv_sec) * 100 + (now.tv_usec - starttime.tv_usec) / 10000;
} | [
"int",
"timenow",
"(",
")",
"{",
"struct",
"timeval",
"now",
";",
"gettimeofday",
"(",
"&",
"now",
",",
"NULL",
")",
";",
"return",
"(",
"now",
".",
"tv_sec",
"-",
"starttime",
".",
"tv_sec",
")",
"*",
"100",
"+",
"(",
"now",
".",
"tv_usec",
"-",
"starttime",
".",
"tv_usec",
")",
"/",
"10000",
";",
"}"
] | timenow(): returns current simulated time in "minutes" (cs). | [
"timenow",
"()",
":",
"returns",
"current",
"simulated",
"time",
"in",
"\"",
"minutes",
"\"",
"(",
"cs",
")",
"."
] | [] | [] | {
"returns": [],
"raises": [],
"params": [],
"outlier_params": [],
"others": []
} |
7d953c0b9e55aca4af9148ab60dbf289af9d17ae | JeraKrs/linear-algebra-notes | src/Server Software/Assignment01/src/version01.c | [
"Apache-2.0"
] | C | marker | void | void *marker(void *arg) {
int markerID = *(int *)arg;
/*
* The following variable is used in the printf statements when a marker is
* grabbed by a student. It shall be set by this function whenever the
* marker is grabbed - and before the printf statements referencing it are
* executed.
*/
int studentID;
/*
* The following variable shall indicate which job the marker is currently
* executing, the first being job 0. The variable ranges from 0 to
* (parameters.N - 1) .
*/
int job = 0;
/* Error code */
int err;
/* 1. Enter the lab. */
printf("%d marker %d: enters lab\n", timenow(), markerID);
/* A marker marks up to N projects. */
/* 2. Repeat (N times).
* (a) Wait to be grabbed by a student.
* (b) Wait for the student's demo to begin
* (you may not need to do anything here).
* (c) Wait for the demo to finish.
* Do not just wait a given time -
* let the student signal when the demo is over.
* (d) Exit the lab.
*/
/* Repeat N times */
while (job < parameters.N) {
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to acquire "
"locker (mut), %s.\n", markerID, strerror(errno));
abort();
}
/* Wait to be grabbed by a student or timeout */
while ((markers[markerID].is_grabbed == 0) && (timeout == 0)) {
err = pthread_cond_wait(&c_marker, &mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"wait conditional variable (c_marker, mut), "
"%s.\n", studentID, strerror(errno));
abort();
}
}
if (timeout == 1) {
/*
* 3. If the end of the session approaches (i.e. there is no time
* to start another demo) then the marker waits for the current
* demo to finish (if they are currently attending one) and then
* exits the lab.
*/
/*
* Marker exit lab since timeout
* Unlock the locker before exit lab
*/
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
printf("%d marker %d: exits lab (timeout)\n", timenow(), markerID);
return NULL;
} else {
/* Get the studentID which grabed the current marker */
studentID = markers[markerID].studentID;
if (studentID < 0 || studentID >= parameters.S) {
fprintf(stderr, "**ERROR**: Marker %d grabbed by student %d is illegal.\n", markerID, studentID);
abort();
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"release locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
}
/* The following line shall be printed when a marker is grabbed by a student. */
printf("%d marker %d: grabbed by student %d (job %d)\n", timenow(), markerID, studentID, job + 1);
demo();
/* The following line shall be printed when a marker has finished attending a demo. */
printf("%d marker %d: finished with student %d (job %d)\n", timenow(), markerID, studentID, job + 1);
/* Wait for the demo to finish */
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to acquire "
"locker (mut), %s.\n", markerID, strerror(errno));
abort();
}
while (markers[markerID].is_grabbed == 1) {
err = pthread_cond_wait(&c_marker, &mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"wait conditional variable (c_student, mut), "
"%s.\n", studentID, strerror(errno));
abort();
}
}
job = job + 1;
if (job < parameters.N) {
err = release(markerID, job);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is "
"failed to release.\n", markerID);
abort();
}
err = pthread_cond_broadcast(&c_student);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"broadcast student (c_student), "
"%s.\n", markerID, strerror(errno));
abort();
}
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to release "
"locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
}
/*
* When the marker exits the lab, exactly one of the following two lines shall be
* printed, depending on whether the marker has finished all their jobs or there
* is no time to complete another demo.
*/
printf("%d marker %d: exits lab (finished %d jobs)\n", timenow(), markerID, parameters.N);
return NULL;
} | /*
* A marker thread. You need to modify this function.
* The parameter arg is the number of the current marker and the function
* doesn't need to return any values.
* Do not modify the printed output as it will be used as part of the testing.
*/ | A marker thread. You need to modify this function.
The parameter arg is the number of the current marker and the function
doesn't need to return any values.
Do not modify the printed output as it will be used as part of the testing. | [
"A",
"marker",
"thread",
".",
"You",
"need",
"to",
"modify",
"this",
"function",
".",
"The",
"parameter",
"arg",
"is",
"the",
"number",
"of",
"the",
"current",
"marker",
"and",
"the",
"function",
"doesn",
"'",
"t",
"need",
"to",
"return",
"any",
"values",
".",
"Do",
"not",
"modify",
"the",
"printed",
"output",
"as",
"it",
"will",
"be",
"used",
"as",
"part",
"of",
"the",
"testing",
"."
] | void *marker(void *arg) {
int markerID = *(int *)arg;
int studentID;
int job = 0;
int err;
printf("%d marker %d: enters lab\n", timenow(), markerID);
while (job < parameters.N) {
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to acquire "
"locker (mut), %s.\n", markerID, strerror(errno));
abort();
}
while ((markers[markerID].is_grabbed == 0) && (timeout == 0)) {
err = pthread_cond_wait(&c_marker, &mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"wait conditional variable (c_marker, mut), "
"%s.\n", studentID, strerror(errno));
abort();
}
}
if (timeout == 1) {
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
printf("%d marker %d: exits lab (timeout)\n", timenow(), markerID);
return NULL;
} else {
studentID = markers[markerID].studentID;
if (studentID < 0 || studentID >= parameters.S) {
fprintf(stderr, "**ERROR**: Marker %d grabbed by student %d is illegal.\n", markerID, studentID);
abort();
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"release locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
}
printf("%d marker %d: grabbed by student %d (job %d)\n", timenow(), markerID, studentID, job + 1);
demo();
printf("%d marker %d: finished with student %d (job %d)\n", timenow(), markerID, studentID, job + 1);
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to acquire "
"locker (mut), %s.\n", markerID, strerror(errno));
abort();
}
while (markers[markerID].is_grabbed == 1) {
err = pthread_cond_wait(&c_marker, &mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"wait conditional variable (c_student, mut), "
"%s.\n", studentID, strerror(errno));
abort();
}
}
job = job + 1;
if (job < parameters.N) {
err = release(markerID, job);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is "
"failed to release.\n", markerID);
abort();
}
err = pthread_cond_broadcast(&c_student);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to "
"broadcast student (c_student), "
"%s.\n", markerID, strerror(errno));
abort();
}
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Marker %d is failed to release "
"locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
}
printf("%d marker %d: exits lab (finished %d jobs)\n", timenow(), markerID, parameters.N);
return NULL;
} | [
"void",
"*",
"marker",
"(",
"void",
"*",
"arg",
")",
"{",
"int",
"markerID",
"=",
"*",
"(",
"int",
"*",
")",
"arg",
";",
"int",
"studentID",
";",
"int",
"job",
"=",
"0",
";",
"int",
"err",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"markerID",
")",
";",
"while",
"(",
"job",
"<",
"parameters",
".",
"N",
")",
"{",
"err",
"=",
"pthread_mutex_lock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"markerID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"while",
"(",
"(",
"markers",
"[",
"markerID",
"]",
".",
"is_grabbed",
"==",
"0",
")",
"&&",
"(",
"timeout",
"==",
"0",
")",
")",
"{",
"err",
"=",
"pthread_cond_wait",
"(",
"&",
"c_marker",
",",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"if",
"(",
"timeout",
"==",
"1",
")",
"{",
"err",
"=",
"pthread_mutex_unlock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"markerID",
")",
";",
"return",
"NULL",
";",
"}",
"else",
"{",
"studentID",
"=",
"markers",
"[",
"markerID",
"]",
".",
"studentID",
";",
"if",
"(",
"studentID",
"<",
"0",
"||",
"studentID",
">=",
"parameters",
".",
"S",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\\n",
"\"",
",",
"markerID",
",",
"studentID",
")",
";",
"abort",
"(",
")",
";",
"}",
"err",
"=",
"pthread_mutex_unlock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"markerID",
",",
"studentID",
",",
"job",
"+",
"1",
")",
";",
"demo",
"(",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"markerID",
",",
"studentID",
",",
"job",
"+",
"1",
")",
";",
"err",
"=",
"pthread_mutex_lock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"markerID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"while",
"(",
"markers",
"[",
"markerID",
"]",
".",
"is_grabbed",
"==",
"1",
")",
"{",
"err",
"=",
"pthread_cond_wait",
"(",
"&",
"c_marker",
",",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"job",
"=",
"job",
"+",
"1",
";",
"if",
"(",
"job",
"<",
"parameters",
".",
"N",
")",
"{",
"err",
"=",
"release",
"(",
"markerID",
",",
"job",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"markerID",
")",
";",
"abort",
"(",
")",
";",
"}",
"err",
"=",
"pthread_cond_broadcast",
"(",
"&",
"c_student",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"markerID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"err",
"=",
"pthread_mutex_unlock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"markerID",
",",
"parameters",
".",
"N",
")",
";",
"return",
"NULL",
";",
"}"
] | A marker thread. | [
"A",
"marker",
"thread",
"."
] | [
"/*\n\t * The following variable is used in the printf statements when a marker is\n\t * grabbed by a student. It shall be set by this function whenever the\n\t * marker is grabbed - and before the printf statements referencing it are\n\t * executed.\n\t */",
"/*\n\t * The following variable shall indicate which job the marker is currently\n\t * executing, the first being job 0. The variable ranges from 0 to\n\t * (parameters.N - 1) .\n\t */",
"/* Error code */",
"/* 1. Enter the lab. */",
"/* A marker marks up to N projects. */",
"/* 2. Repeat (N times). \n\t * (a) Wait to be grabbed by a student.\n\t * (b) Wait for the student's demo to begin\n\t * (you may not need to do anything here).\n\t * (c) Wait for the demo to finish.\n\t * Do not just wait a given time -\n\t * let the student signal when the demo is over.\n\t * (d) Exit the lab.\n\t */",
"/* Repeat N times */",
"/* Wait to be grabbed by a student or timeout */",
"/* \n\t\t\t * 3. If the end of the session approaches (i.e. there is no time\n\t\t\t *\t\tto start another demo) then the marker waits for the current\n\t\t\t *\t\tdemo to finish (if they are currently attending one) and then\n\t\t\t *\t\texits the lab.\n\t\t\t */",
"/* \n\t\t\t * Marker exit lab since timeout\n\t\t\t * Unlock the locker before exit lab\n\t\t\t */",
"/* Get the studentID which grabed the current marker */",
"/* The following line shall be printed when a marker is grabbed by a student. */",
"/* The following line shall be printed when a marker has finished attending a demo. */",
"/* Wait for the demo to finish */",
"/* \n\t * When the marker exits the lab, exactly one of the following two lines shall be\n\t * printed, depending on whether the marker has finished all their jobs or there\n\t * is no time to complete another demo.\n\t */"
] | [
{
"param": "arg",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
7d953c0b9e55aca4af9148ab60dbf289af9d17ae | JeraKrs/linear-algebra-notes | src/Server Software/Assignment01/src/version01.c | [
"Apache-2.0"
] | C | student | void | void *student(void *arg) {
/* The ID of the current student. */
int studentID = *(int *)arg;
/* The variable for storing error code */
int err;
/* Store the markerID which grabbed by the current student */
int* markerIDs;
markerIDs = (int *)malloc(parameters.K * sizeof(int));
if (markerIDs == NULL) {
fprintf(stderr, "**ERROR**: Student %d is failed to allocate "
"memory for the pointer of markerIDs.\n", studentID);
abort();
}
/* 1. Panic! */
printf("%d student %d: starts panicking\n", timenow(), studentID);
panic();
/* 2. Enter the lab. */
printf("%d student %d: enters lab\n", timenow(), studentID);
/* 3. Grab K markers. */
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to acquire "
"locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
/* Waiting for K idle markers or timeout */
while ((idle_marker < parameters.K) && (timeout == 0)) {
err = pthread_cond_wait(&c_student, &mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"wait conditional variable (c_student, mut), "
"%s.\n", studentID, strerror(errno));
abort();
}
}
if (timeout == 0) {
/* Student grabs K markers */
err = grab(studentID, markerIDs);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"grab %d markers.\n", studentID, parameters.K);
abort();
}
/* Student broadcast markers after grab */
err = pthread_cond_broadcast(&c_marker);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"broadcast markers (c_marker), %s.\n",
studentID, strerror(errno));
abort();
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
} else {
/*
* Student exit the lab since timeout
* Unlock the locker (mut) before exit the lab
*/
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
printf("%d student %d: exits lab (timeout)\n", timenow(), studentID);
return NULL;
}
/* 4. Demo! */
/*
* If the student succeeds in grabbing K markers and there is enough time left
* for a demo, the following three lines shall be executed in order.
* If the student has not started their demo and there is not sufficient time
* left to do a full demo, the following three lines shall not be executed
* and the student proceeds to step 5.
*/
printf("%d student %d: starts demo\n", timenow(), studentID);
demo();
printf("%d student %d: ends demo\n", timenow(), studentID);
/* Release the markers that grabbed the current student */
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to acquire "
"locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
for (int i = 0; i < parameters.K; i++) {
int markerID = markerIDs[i];
if (markerID < 0 || markerID >= parameters.M) {
fprintf(stderr, "**ERROR**: Student %d grabbed marker %d is"
" illegal.\n", studentID, markerID);
abort();
}
markers[markerID].is_grabbed = 0;
}
/* Student broadcast markers after demo */
err = pthread_cond_broadcast(&c_marker);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"broadcast markers (c_marker), %s.\n",
studentID, strerror(errno));
abort();
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
/* 5. Exit the lab. */
/*
* Exactly one of the following two lines shall be printed, depending on
* whether the student got to give their demo or not.
*/
printf("%d student %d: exits lab (finished)\n", timenow(), studentID);
free(markerIDs);
return NULL;
} | /*
* A student thread. You must modify this function.
*/ | A student thread. You must modify this function. | [
"A",
"student",
"thread",
".",
"You",
"must",
"modify",
"this",
"function",
"."
] | void *student(void *arg) {
int studentID = *(int *)arg;
int err;
int* markerIDs;
markerIDs = (int *)malloc(parameters.K * sizeof(int));
if (markerIDs == NULL) {
fprintf(stderr, "**ERROR**: Student %d is failed to allocate "
"memory for the pointer of markerIDs.\n", studentID);
abort();
}
printf("%d student %d: starts panicking\n", timenow(), studentID);
panic();
printf("%d student %d: enters lab\n", timenow(), studentID);
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to acquire "
"locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
while ((idle_marker < parameters.K) && (timeout == 0)) {
err = pthread_cond_wait(&c_student, &mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"wait conditional variable (c_student, mut), "
"%s.\n", studentID, strerror(errno));
abort();
}
}
if (timeout == 0) {
err = grab(studentID, markerIDs);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"grab %d markers.\n", studentID, parameters.K);
abort();
}
err = pthread_cond_broadcast(&c_marker);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"broadcast markers (c_marker), %s.\n",
studentID, strerror(errno));
abort();
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
} else {
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
printf("%d student %d: exits lab (timeout)\n", timenow(), studentID);
return NULL;
}
printf("%d student %d: starts demo\n", timenow(), studentID);
demo();
printf("%d student %d: ends demo\n", timenow(), studentID);
err = pthread_mutex_lock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to acquire "
"locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
for (int i = 0; i < parameters.K; i++) {
int markerID = markerIDs[i];
if (markerID < 0 || markerID >= parameters.M) {
fprintf(stderr, "**ERROR**: Student %d grabbed marker %d is"
" illegal.\n", studentID, markerID);
abort();
}
markers[markerID].is_grabbed = 0;
}
err = pthread_cond_broadcast(&c_marker);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to "
"broadcast markers (c_marker), %s.\n",
studentID, strerror(errno));
abort();
}
err = pthread_mutex_unlock(&mut);
if (err != 0) {
fprintf(stderr, "**ERROR**: Student %d is failed to release"
" locker (mut), %s.\n", studentID, strerror(errno));
abort();
}
printf("%d student %d: exits lab (finished)\n", timenow(), studentID);
free(markerIDs);
return NULL;
} | [
"void",
"*",
"student",
"(",
"void",
"*",
"arg",
")",
"{",
"int",
"studentID",
"=",
"*",
"(",
"int",
"*",
")",
"arg",
";",
"int",
"err",
";",
"int",
"*",
"markerIDs",
";",
"markerIDs",
"=",
"(",
"int",
"*",
")",
"malloc",
"(",
"parameters",
".",
"K",
"*",
"sizeof",
"(",
"int",
")",
")",
";",
"if",
"(",
"markerIDs",
"==",
"NULL",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
")",
";",
"abort",
"(",
")",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"studentID",
")",
";",
"panic",
"(",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"studentID",
")",
";",
"err",
"=",
"pthread_mutex_lock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"while",
"(",
"(",
"idle_marker",
"<",
"parameters",
".",
"K",
")",
"&&",
"(",
"timeout",
"==",
"0",
")",
")",
"{",
"err",
"=",
"pthread_cond_wait",
"(",
"&",
"c_student",
",",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"if",
"(",
"timeout",
"==",
"0",
")",
"{",
"err",
"=",
"grab",
"(",
"studentID",
",",
"markerIDs",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"parameters",
".",
"K",
")",
";",
"abort",
"(",
")",
";",
"}",
"err",
"=",
"pthread_cond_broadcast",
"(",
"&",
"c_marker",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"err",
"=",
"pthread_mutex_unlock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"}",
"else",
"{",
"err",
"=",
"pthread_mutex_unlock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"studentID",
")",
";",
"return",
"NULL",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"studentID",
")",
";",
"demo",
"(",
")",
";",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"studentID",
")",
";",
"err",
"=",
"pthread_mutex_lock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"for",
"(",
"int",
"i",
"=",
"0",
";",
"i",
"<",
"parameters",
".",
"K",
";",
"i",
"++",
")",
"{",
"int",
"markerID",
"=",
"markerIDs",
"[",
"i",
"]",
";",
"if",
"(",
"markerID",
"<",
"0",
"||",
"markerID",
">=",
"parameters",
".",
"M",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"markerID",
")",
";",
"abort",
"(",
")",
";",
"}",
"markers",
"[",
"markerID",
"]",
".",
"is_grabbed",
"=",
"0",
";",
"}",
"err",
"=",
"pthread_cond_broadcast",
"(",
"&",
"c_marker",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"err",
"=",
"pthread_mutex_unlock",
"(",
"&",
"mut",
")",
";",
"if",
"(",
"err",
"!=",
"0",
")",
"{",
"fprintf",
"(",
"stderr",
",",
"\"",
"\"",
"\"",
"\\n",
"\"",
",",
"studentID",
",",
"strerror",
"(",
"errno",
")",
")",
";",
"abort",
"(",
")",
";",
"}",
"printf",
"(",
"\"",
"\\n",
"\"",
",",
"timenow",
"(",
")",
",",
"studentID",
")",
";",
"free",
"(",
"markerIDs",
")",
";",
"return",
"NULL",
";",
"}"
] | A student thread. | [
"A",
"student",
"thread",
"."
] | [
"/* The ID of the current student. */",
"/* The variable for storing error code */",
"/* Store the markerID which grabbed by the current student */",
"/* 1. Panic! */",
"/* 2. Enter the lab. */",
"/* 3. Grab K markers. */",
"/* Waiting for K idle markers or timeout */",
"/* Student grabs K markers */",
"/* Student broadcast markers after grab */",
"/* \n\t\t * Student exit the lab since timeout\n\t\t * Unlock the locker (mut) before exit the lab\n\t\t */",
"/* 4. Demo! */",
"/*\n\t * If the student succeeds in grabbing K markers and there is enough time left\n\t * for a demo, the following three lines shall be executed in order.\n\t * If the student has not started their demo and there is not sufficient time\n\t * left to do a full demo, the following three lines shall not be executed\n\t * and the student proceeds to step 5.\n\t */",
"/* Release the markers that grabbed the current student */",
"/* Student broadcast markers after demo */",
"/* 5. Exit the lab. */",
"/* \n\t * Exactly one of the following two lines shall be printed, depending on\n\t * whether the student got to give their demo or not.\n\t */"
] | [
{
"param": "arg",
"type": "void"
}
] | {
"returns": [],
"raises": [],
"params": [
{
"identifier": "arg",
"type": "void",
"docstring": null,
"docstring_tokens": [],
"default": null,
"is_optional": null
}
],
"outlier_params": [],
"others": []
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.