Beispiel #1
0
EAPI void
eina_stringshare_del(Eina_Stringshare *str)
{
    int slen;

    if (!str)
        return;

    /* special cases */
    if (str[0] == '\0')
        slen = 0;
    else if (str[1] == '\0')
        slen = 1;
    else if (str[2] == '\0')
        slen = 2;
    else if (str[3] == '\0')
        slen = 3;
    else
        slen = 4;  /* handled later */

    if (slen < 2)
        return;
    else if (slen < 4)
    {
        eina_share_common_population_del(stringshare_share, slen);
        eina_lock_take(&_mutex_small);
        _eina_stringshare_small_del(str, slen);
        eina_lock_release(&_mutex_small);
        return;
    }

    if (!eina_share_common_del(stringshare_share, str))
        CRITICAL("EEEK trying to del non-shared stringshare \"%s\"", str);
}
Beispiel #2
0
/**
 * @brief Note that the given string has lost an instance.
 *
 * @param str string The given string.
 *
 * This function decreases the reference counter associated to @p str
 * if it exists. If that counter reaches 0, the memory associated to
 * @p str is freed. If @p str is NULL, the function returns
 * immediately.
 *
 * Note that if the given pointer is not shared or NULL, bad things
 * will happen, likely a segmentation fault.
 */
EAPI void
eina_stringshare_del(const char *str)
{
   int slen;
   DBG("str=%p (%s)", str, str ? str : "");
   if (!str)
      return;

   /* special cases */
   if      (str[0] == '\0')
      slen = 0;
   else if (str[1] == '\0')
      slen = 1;
   else if (str[2] == '\0')
      slen = 2;
   else if (str[3] == '\0')
      slen = 3;
   else
      slen = 4;  /* handled later */

   if (slen < 2)
      return;
   else if (slen < 4)
     {
        eina_share_common_population_del(stringshare_share, slen);
        STRINGSHARE_LOCK_SMALL();
        _eina_stringshare_small_del(str, slen);
        STRINGSHARE_UNLOCK_SMALL();
        return;
     }

   eina_share_common_del(stringshare_share, str);
}