Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
ba51045d
Commit
ba51045d
authored
Jan 29, 2013
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refcount: convert to C++
parent
fa34dd7b
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
31 additions
and
43 deletions
+31
-43
Makefile.am
Makefile.am
+1
-1
Bzip2ArchivePlugin.cxx
src/archive/Bzip2ArchivePlugin.cxx
+4
-5
Iso9660ArchivePlugin.cxx
src/archive/Iso9660ArchivePlugin.cxx
+4
-5
ZzipArchivePlugin.cxx
src/archive/ZzipArchivePlugin.cxx
+4
-5
CdioParanoiaInputPlugin.cxx
src/input/CdioParanoiaInputPlugin.cxx
+0
-1
RefCount.hxx
src/util/RefCount.hxx
+18
-26
No files found.
Makefile.am
View file @
ba51045d
...
...
@@ -99,7 +99,6 @@ mpd_headers = \
src/poison.h
\
src/riff.h
\
src/aiff.h
\
src/refcount.h
\
src/replay_gain_config.h
\
src/replay_gain_info.h
\
src/replay_gain_ape.h
\
...
...
@@ -310,6 +309,7 @@ endif
# Generic utility library
libutil_a_SOURCES
=
\
src/util/RefCount.hxx
\
src/util/fifo_buffer.c src/util/fifo_buffer.h
\
src/util/growing_fifo.c src/util/growing_fifo.h
\
src/util/LazyRandomEngine.cxx src/util/LazyRandomEngine.hxx
\
...
...
src/archive/Bzip2ArchivePlugin.cxx
View file @
ba51045d
...
...
@@ -29,7 +29,7 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
#include "
refcount.h
"
#include "
util/RefCount.hxx
"
#include <stdint.h>
#include <stddef.h>
...
...
@@ -45,18 +45,17 @@
struct
Bzip2ArchiveFile
{
struct
archive_file
base
;
struct
refc
ount
ref
;
RefC
ount
ref
;
char
*
name
;
struct
input_stream
*
istream
;
Bzip2ArchiveFile
()
{
archive_file_init
(
&
base
,
&
bz2_archive_plugin
);
refcount_init
(
&
ref
);
}
void
Unref
()
{
if
(
!
ref
count_dec
(
&
ref
))
if
(
!
ref
.
Decrement
(
))
return
;
g_free
(
name
);
...
...
@@ -174,7 +173,7 @@ Bzip2InputStream::Bzip2InputStream(Bzip2ArchiveFile &_context, const char *uri,
:
base
(
bz2_inputplugin
,
uri
,
mutex
,
cond
),
archive
(
&
_context
),
eof
(
false
)
{
refcount_inc
(
&
archive
->
ref
);
archive
->
ref
.
Increment
(
);
}
Bzip2InputStream
::~
Bzip2InputStream
()
...
...
src/archive/Iso9660ArchivePlugin.cxx
View file @
ba51045d
...
...
@@ -29,7 +29,7 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
#include "
refcount.h
"
#include "
util/RefCount.hxx
"
#include <cdio/cdio.h>
#include <cdio/iso9660.h>
...
...
@@ -44,14 +44,13 @@
struct
Iso9660ArchiveFile
{
struct
archive_file
base
;
struct
refc
ount
ref
;
RefC
ount
ref
;
iso9660_t
*
iso
;
Iso9660ArchiveFile
(
iso9660_t
*
_iso
)
:
iso
(
_iso
)
{
archive_file_init
(
&
base
,
&
iso9660_archive_plugin
);
refcount_init
(
&
ref
);
}
~
Iso9660ArchiveFile
()
{
...
...
@@ -59,7 +58,7 @@ struct Iso9660ArchiveFile {
}
void
Unref
()
{
if
(
ref
count_dec
(
&
ref
))
if
(
ref
.
Decrement
(
))
delete
this
;
}
...
...
@@ -161,7 +160,7 @@ struct Iso9660InputStream {
base
.
ready
=
true
;
base
.
size
=
statbuf
->
size
;
refcount_inc
(
&
archive
->
ref
);
archive
->
ref
.
Increment
(
);
}
~
Iso9660InputStream
()
{
...
...
src/archive/ZzipArchivePlugin.cxx
View file @
ba51045d
...
...
@@ -29,7 +29,7 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
#include "
refcount.h
"
#include "
util/RefCount.hxx
"
#include <zzip/zzip.h>
#include <glib.h>
...
...
@@ -38,17 +38,16 @@
struct
ZzipArchiveFile
{
struct
archive_file
base
;
struct
refc
ount
ref
;
RefC
ount
ref
;
ZZIP_DIR
*
dir
;
ZzipArchiveFile
()
{
archive_file_init
(
&
base
,
&
zzip_archive_plugin
);
refcount_init
(
&
ref
);
}
void
Unref
()
{
if
(
!
ref
count_dec
(
&
ref
))
if
(
!
ref
.
Decrement
(
))
return
;
//close archive
...
...
@@ -136,7 +135,7 @@ struct ZzipInputStream {
zzip_file_stat
(
file
,
&
z_stat
);
base
.
size
=
z_stat
.
st_size
;
refcount_inc
(
&
archive
->
ref
);
archive
->
ref
.
Increment
(
);
}
~
ZzipInputStream
()
{
...
...
src/input/CdioParanoiaInputPlugin.cxx
View file @
ba51045d
...
...
@@ -26,7 +26,6 @@
#include "InputInternal.hxx"
#include "InputStream.hxx"
#include "InputPlugin.hxx"
#include "refcount.h"
#include <stdio.h>
#include <stdint.h>
...
...
src/
refcount.h
→
src/
util/RefCount.hxx
View file @
ba51045d
/*
* Copyright (C) 2003-201
1
The Music Player Daemon Project
* Copyright (C) 2003-201
3
The Music Player Daemon Project
* http://www.musicpd.org
*
* Redistribution and use in source and binary forms, with or without
...
...
@@ -33,35 +33,27 @@
* A very simple reference counting library.
*/
#ifndef MPD_REFCOUNT_H
#define MPD_REFCOUNT_H
#ifndef MPD_REFCOUNT_H
XX
#define MPD_REFCOUNT_H
XX
#include <glib.h>
#include <stdbool.h>
#include <atomic>
struct
refcount
{
gint
n
;
};
class
RefCount
{
std
::
atomic_uint
n
;
static
inline
void
refcount_init
(
struct
refcount
*
r
)
{
r
->
n
=
1
;
}
public
:
constexpr
RefCount
()
:
n
(
1
)
{}
static
inline
void
refcount_inc
(
struct
refcount
*
r
)
{
g_atomic_int_inc
(
&
r
->
n
);
}
void
Increment
()
{
++
n
;
}
/**
* @return true if the number of references has been dropped to 0
*/
static
inline
bool
refcount_dec
(
struct
refcount
*
r
)
{
return
g_atomic_int_dec_and_test
(
&
r
->
n
);
}
/**
* @return true if the number of references has been dropped to 0
*/
bool
Decrement
()
{
return
--
n
==
0
;
}
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment