<commit_before>/**
 * @file Cosa/Types.h
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2012, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * @section Description
 * Common data types and syntax abstractions.
 *
 * This file is part of the Arduino Che Cosa project.
 */

#ifndef __COSA_TYPES_H__
#define __COSA_TYPES_H__

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

/**
 * Number of bits in a character.
 */
#define CHARBITS 8

/**
 * Macro for number of elements in a vector.
 * @param[in] x vector
 * @return number of elements
 */
#define membersof(x) (sizeof(x)/sizeof(x[0]))

/**
 * Macro for offset to member in structure.
 * @param[in] type data type name.
 * @param[in] member name.
 * @return offset.
 */
#define offsetof(type, member) __builtin_offsetof(type, member)

/**
 * Disable interrupts and return flags.
 * @return processor flags.
 */
inline uint8_t lock() 
{ 
  uint8_t key = SREG;
  cli();
  return (key);
}

/**
 * Restore processor flags and possible enable of interrupts.
 * @param[in] key processor flags.
 */
inline void unlock(uint8_t key)
{
  SREG = key;
}

/**
 * Syntactic sugar for synchronized block. Used in the form:
 * synchronized {
 *   ...
 * }
 * Interrupts are disabled in the block allowing secure update.
 */
#define synchronized for (uint8_t key = lock(), i = 1; i != 0; i--, unlock(key))

/**
 * Force compiler to store all values in memory at this point.
 * Alternative to volatile declaration.
 */
#define barrier() __asm__ __volatile__("nop" ::: "memory") 

#endif
<commit_msg>Adding io-vector type to allow writev type of device driver calls.<commit_after>/**
 * @file Cosa/Types.h
 * @version 1.0
 *
 * @section License
 * Copyright (C) 2012, <NAME>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General
 * Public License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
 * Boston, MA  02111-1307  USA
 *
 * @section Description
 * Common data types and syntax abstractions.
 *
 * This file is part of the Arduino Che Cosa project.
 */

#ifndef __COSA_TYPES_H__
#define __COSA_TYPES_H__

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/sfr_defs.h>

#include <stdint.h>
#include <stdlib.h>
#include <string.h>

/**
 * Number of bits in a character.
 */
#define CHARBITS 8

/**
 * Macro for number of elements in a vector.
 * @param[in] x vector
 * @return number of elements
 */
#define membersof(x) (sizeof(x)/sizeof(x[0]))

/**
 * Macro for offset to member in structure.
 * @param[in] type data type name.
 * @param[in] member name.
 * @return offset.
 */
#define offsetof(type, member) __builtin_offsetof(type, member)

/**
 * Disable interrupts and return flags.
 * @return processor flags.
 */
inline uint8_t lock() 
{ 
  uint8_t key = SREG;
  cli();
  return (key);
}

/**
 * Restore processor flags and possible enable of interrupts.
 * @param[in] key processor flags.
 */
inline void unlock(uint8_t key)
{
  SREG = key;
}

/**
 * Syntactic sugar for synchronized block. Used in the form:
 * synchronized {
 *   ...
 * }
 * Interrupts are disabled in the block allowing secure update.
 */
#define synchronized for (uint8_t key = lock(), i = 1; i != 0; i--, unlock(key))

/**
 * Force compiler to store all values in memory at this point.
 * Alternative to volatile declaration.
 */
#define barrier() __asm__ __volatile__("nop" ::: "memory") 

/**
 * Buffer structure for vector write operations.
 */
struct iovec {
  void* buf;
  size_t count;
};

#endif

{'fraction_non_alphanumeric': 0.10926609266092661, 'fraction_numerical': 0.012300123001230012, 'mean_word_length': 3.5941619585687383, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4838947', 'n_tokens_mistral': 1558, 'n_tokens_neox': 1502, 'n_words': 620}